{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "stocks-dashboard-shadcnui",
  "type": "registry:block",
  "title": "Stocks Dashboard",
  "description": "Interactive stock portfolio dashboard with status cards, data table, and detailed stock information modal",
  "registryDependencies": [
    "badge",
    "button",
    "card",
    "dialog"
  ],
  "dependencies": [
    "framer-motion",
    "react"
  ],
  "files": [
    {
      "path": "@uitripled/react-shadcn/src/components/components/stocks-dashboard/stocks-dashboard.tsx",
      "content": "\"use client\";\n\nimport { Badge } from \"@/components/ui/badge\";\nimport { Card, CardContent, CardHeader, CardTitle } from \"@/components/ui/card\";\nimport {\n  Dialog,\n  DialogContent,\n  DialogDescription,\n  DialogHeader,\n  DialogTitle,\n} from \"@/components/ui/dialog\";\nimport { Button } from \"@/components/ui/button\";\nimport { motion, useReducedMotion } from \"framer-motion\";\nimport {\n  Activity,\n  BarChart3,\n  Building2,\n  ChevronRight,\n  DollarSign,\n  TrendingDown,\n  TrendingUp,\n} from \"lucide-react\";\nimport { useState } from \"react\";\n\ninterface Stock {\n  id: string;\n  symbol: string;\n  name: string;\n  price: number;\n  change: number;\n  changePercent: number;\n  volume: number;\n  marketCap: string;\n  sector: string;\n  peRatio: number;\n}\n\nconst mockStocks: Stock[] = [\n  {\n    id: \"1\",\n    symbol: \"AAPL\",\n    name: \"Apple Inc.\",\n    price: 178.23,\n    change: 2.45,\n    changePercent: 1.39,\n    volume: 45234567,\n    marketCap: \"2.8T\",\n    sector: \"Technology\",\n    peRatio: 31.2,\n  },\n  {\n    id: \"2\",\n    symbol: \"GOOGL\",\n    name: \"Alphabet Inc.\",\n    price: 142.56,\n    change: -1.23,\n    changePercent: -0.85,\n    volume: 28345123,\n    marketCap: \"1.8T\",\n    sector: \"Technology\",\n    peRatio: 24.8,\n  },\n  {\n    id: \"3\",\n    symbol: \"MSFT\",\n    name: \"Microsoft Corporation\",\n    price: 378.91,\n    change: 5.67,\n    changePercent: 1.52,\n    volume: 19234567,\n    marketCap: \"2.9T\",\n    sector: \"Technology\",\n    peRatio: 35.4,\n  },\n  {\n    id: \"4\",\n    symbol: \"TSLA\",\n    name: \"Tesla, Inc.\",\n    price: 248.42,\n    change: -3.21,\n    changePercent: -1.28,\n    volume: 78234567,\n    marketCap: \"790B\",\n    sector: \"Automotive\",\n    peRatio: 62.5,\n  },\n  {\n    id: \"5\",\n    symbol: \"AMZN\",\n    name: \"Amazon.com Inc.\",\n    price: 148.76,\n    change: 1.89,\n    changePercent: 1.29,\n    volume: 45234567,\n    marketCap: \"1.5T\",\n    sector: \"E-commerce\",\n    peRatio: 48.3,\n  },\n];\n\nfunction formatNumber(num: number): string {\n  if (num >= 1000000) {\n    return (num / 1000000).toFixed(1) + \"M\";\n  }\n  if (num >= 1000) {\n    return (num / 1000).toFixed(1) + \"K\";\n  }\n  return num.toString();\n}\n\n/**\n * Gain/loss needs a pair that clears 4.5:1 on the card surface in both themes.\n * `text-green-500` measured 2.22:1 and `text-red-500` 3.81:1 on white, which is\n * below AA for the most important numbers in the component.\n */\nconst trendText = (v: number) =>\n  v >= 0\n    ? \"text-emerald-700 dark:text-emerald-400\"\n    : \"text-red-700 dark:text-red-400\";\n\nconst signed = (v: number, digits = 2) =>\n  `${v >= 0 ? \"+\" : \"-\"}$${Math.abs(v).toFixed(digits)}`;\n\nfunction StatusSection({ reduce }: { reduce: boolean | null }) {\n  const totalValue = mockStocks.reduce(\n    (sum, stock) => sum + stock.price * 100,\n    0\n  );\n  const totalChange = mockStocks.reduce(\n    (sum, stock) => sum + stock.change * 100,\n    0\n  );\n  const totalChangePercent = (totalChange / (totalValue - totalChange)) * 100;\n\n  const cards = [\n    {\n      label: \"Total portfolio value\",\n      icon: DollarSign,\n      value: `$${totalValue.toLocaleString(\"en-US\", {\n        minimumFractionDigits: 2,\n        maximumFractionDigits: 2,\n      })}`,\n      note: \"Based on current prices\",\n      tone: \"\",\n    },\n    {\n      label: \"Today's change\",\n      icon: totalChange >= 0 ? TrendingUp : TrendingDown,\n      value: `${signed(totalChange)}`,\n      note: `${totalChangePercent >= 0 ? \"+\" : \"\"}${totalChangePercent.toFixed(2)}%`,\n      tone: trendText(totalChange),\n    },\n    {\n      label: \"Active positions\",\n      icon: BarChart3,\n      value: String(mockStocks.length),\n      note: \"Stocks in portfolio\",\n      tone: \"\",\n    },\n  ];\n\n  return (\n    <div className=\"mb-6 grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3\">\n      {cards.map((card, index) => {\n        const Icon = card.icon;\n        return (\n          <motion.div\n            key={card.label}\n            initial={reduce ? { opacity: 1, y: 0 } : { opacity: 0, y: 20 }}\n            animate={{ opacity: 1, y: 0 }}\n            transition={reduce ? { duration: 0 } : { duration: 0.4, delay: index * 0.1 }}\n          >\n            <Card className=\"h-full\">\n              <CardHeader className=\"flex flex-row items-center justify-between pb-2\">\n                <CardTitle className=\"text-xs font-medium text-muted-foreground sm:text-sm\">\n                  {card.label}\n                </CardTitle>\n                <Icon className={`size-4 ${card.tone || \"text-muted-foreground\"}`} aria-hidden />\n              </CardHeader>\n              <CardContent>\n                <div className={`text-xl font-bold tabular-nums sm:text-2xl ${card.tone}`}>\n                  {card.value}\n                </div>\n                <p className={`mt-1 text-xs tabular-nums ${card.tone || \"text-muted-foreground\"}`}>\n                  {card.note}\n                </p>\n              </CardContent>\n            </Card>\n          </motion.div>\n        );\n      })}\n    </div>\n  );\n}\n\n/**\n * Six bordered cards for six key/value pairs buried the numbers in chrome.\n * A definition list groups them with space instead, so the price and change\n * lead and the rest read as supporting detail.\n */\nfunction StockDetails({\n  stock,\n  isOpen,\n  onClose,\n}: {\n  stock: Stock | null;\n  isOpen: boolean;\n  onClose: () => void;\n}) {\n  return (\n    <Dialog open={isOpen} onOpenChange={(open) => !open && onClose()}>\n      <DialogContent className=\"max-w-lg\">\n        {stock && (\n          <>\n            <DialogHeader>\n              <div className=\"flex items-center gap-3\">\n                <div className=\"flex size-11 shrink-0 items-center justify-center rounded-lg bg-muted text-foreground\">\n                  <Building2 className=\"size-5\" strokeWidth={1.5} aria-hidden />\n                </div>\n                <div className=\"min-w-0 text-left\">\n                  <DialogTitle className=\"text-xl\">{stock.symbol}</DialogTitle>\n                  <DialogDescription className=\"truncate\">\n                    {stock.name}\n                  </DialogDescription>\n                </div>\n              </div>\n            </DialogHeader>\n\n            {/* Headline figures */}\n            <div className=\"mt-2 flex items-baseline gap-3\">\n              <span className=\"text-3xl font-bold tabular-nums\">\n                ${stock.price.toFixed(2)}\n              </span>\n              <span\n                className={`flex items-center gap-1 text-sm font-medium tabular-nums ${trendText(stock.change)}`}\n              >\n                {stock.change >= 0 ? (\n                  <TrendingUp className=\"size-4\" aria-hidden />\n                ) : (\n                  <TrendingDown className=\"size-4\" aria-hidden />\n                )}\n                {signed(stock.change)} ({stock.change >= 0 ? \"+\" : \"\"}\n                {stock.changePercent.toFixed(2)}%)\n              </span>\n            </div>\n\n            <dl className=\"mt-6 grid grid-cols-2 gap-x-6 gap-y-4 border-t border-border pt-6\">\n              <div>\n                <dt className=\"text-xs text-muted-foreground\">Market cap</dt>\n                <dd className=\"mt-0.5 text-base font-semibold tabular-nums\">\n                  ${stock.marketCap}\n                </dd>\n              </div>\n              <div>\n                <dt className=\"text-xs text-muted-foreground\">Volume</dt>\n                <dd className=\"mt-0.5 text-base font-semibold tabular-nums\">\n                  {formatNumber(stock.volume)}\n                </dd>\n              </div>\n              <div>\n                <dt className=\"text-xs text-muted-foreground\">P/E ratio</dt>\n                <dd className=\"mt-0.5 text-base font-semibold tabular-nums\">\n                  {stock.peRatio}\n                </dd>\n              </div>\n              <div>\n                <dt className=\"text-xs text-muted-foreground\">Sector</dt>\n                <dd className=\"mt-0.5\">\n                  <Badge variant=\"outline\">{stock.sector}</Badge>\n                </dd>\n              </div>\n            </dl>\n          </>\n        )}\n      </DialogContent>\n    </Dialog>\n  );\n}\n\nfunction DataTable({\n  onRowClick,\n  reduce,\n}: {\n  onRowClick: (stock: Stock) => void;\n  reduce: boolean | null;\n}) {\n  const th =\n    \"py-3 px-3 sm:px-4 text-xs sm:text-sm font-medium text-muted-foreground whitespace-nowrap\";\n\n  return (\n    <Card>\n      <CardHeader>\n        <CardTitle className=\"flex items-center gap-2 text-lg sm:text-xl\">\n          <Activity className=\"size-5\" aria-hidden />\n          Stock holdings\n        </CardTitle>\n      </CardHeader>\n      <CardContent className=\"p-0 sm:p-6\">\n        {/* Focusable so the horizontal scroll is reachable without a pointer */}\n        <div\n          role=\"region\"\n          aria-label=\"Stock holdings table\"\n          tabIndex={0}\n          className=\"overflow-x-auto focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset\"\n        >\n          <table className=\"w-full min-w-[720px] border-collapse\">\n            <caption className=\"sr-only\">\n              Your holdings, with price, daily change and key figures. Each row\n              has a button that opens full details.\n            </caption>\n            <thead>\n              <tr className=\"border-b border-border\">\n                <th scope=\"col\" className={`${th} text-left`}>Symbol</th>\n                <th scope=\"col\" className={`${th} text-left`}>Name</th>\n                <th scope=\"col\" className={`${th} text-right`}>Price</th>\n                <th scope=\"col\" className={`${th} text-right`}>Change</th>\n                <th scope=\"col\" className={`${th} hidden text-right md:table-cell`}>Volume</th>\n                <th scope=\"col\" className={`${th} hidden text-right lg:table-cell`}>Market cap</th>\n                <th scope=\"col\" className={`${th} hidden text-right lg:table-cell`}>Sector</th>\n                <th scope=\"col\" className={`${th} text-right`}>\n                  <span className=\"sr-only\">Details</span>\n                </th>\n              </tr>\n            </thead>\n            <tbody>\n              {mockStocks.map((stock, index) => (\n                <motion.tr\n                  key={stock.id}\n                  initial={reduce ? { opacity: 1, x: 0 } : { opacity: 0, x: -20 }}\n                  animate={{ opacity: 1, x: 0 }}\n                  transition={reduce ? { duration: 0 } : { duration: 0.3, delay: index * 0.05 }}\n                  className=\"border-b border-border transition-colors last:border-b-0 hover:bg-muted/50 motion-reduce:transition-none\"\n                >\n                  <th scope=\"row\" className=\"px-3 py-3 text-left sm:px-4\">\n                    <span className=\"text-sm font-semibold sm:text-base\">\n                      {stock.symbol}\n                    </span>\n                  </th>\n                  <td className=\"px-3 py-3 sm:px-4\">\n                    <div className=\"max-w-[140px] truncate text-xs text-muted-foreground sm:max-w-none sm:text-sm\">\n                      {stock.name}\n                    </div>\n                  </td>\n                  <td className=\"px-3 py-3 text-right text-sm font-semibold tabular-nums sm:px-4 sm:text-base\">\n                    ${stock.price.toFixed(2)}\n                  </td>\n                  <td className=\"px-3 py-3 text-right sm:px-4\">\n                    <div\n                      className={`flex items-center justify-end gap-1 text-sm font-semibold tabular-nums sm:text-base ${trendText(stock.change)}`}\n                    >\n                      {stock.change >= 0 ? (\n                        <TrendingUp className=\"size-3 shrink-0\" aria-hidden />\n                      ) : (\n                        <TrendingDown className=\"size-3 shrink-0\" aria-hidden />\n                      )}\n                      <span className=\"whitespace-nowrap\">\n                        {signed(stock.change)}\n                      </span>\n                    </div>\n                    <div className={`text-xs tabular-nums ${trendText(stock.change)}`}>\n                      {stock.changePercent >= 0 ? \"+\" : \"\"}\n                      {stock.changePercent.toFixed(2)}%\n                    </div>\n                  </td>\n                  <td className=\"hidden px-3 py-3 text-right text-xs tabular-nums sm:px-4 sm:text-sm md:table-cell\">\n                    {formatNumber(stock.volume)}\n                  </td>\n                  <td className=\"hidden px-3 py-3 text-right text-xs tabular-nums sm:px-4 sm:text-sm lg:table-cell\">\n                    ${stock.marketCap}\n                  </td>\n                  <td className=\"hidden px-3 py-3 text-right sm:px-4 lg:table-cell\">\n                    <Badge variant=\"outline\" className=\"text-xs\">\n                      {stock.sector}\n                    </Badge>\n                  </td>\n                  <td className=\"px-3 py-3 text-right sm:px-4\">\n                    {/*\n                      The row used to carry the only onClick, with no tabindex\n                      and no key handler, so the detail dialog could not be\n                      opened without a pointer. A real button restores that path\n                      and keeps the table semantics intact.\n                    */}\n                    <Button\n                      variant=\"ghost\"\n                      size=\"icon\"\n                      className=\"size-8\"\n                      onClick={() => onRowClick(stock)}\n                      aria-label={`View details for ${stock.name}`}\n                    >\n                      <ChevronRight className=\"size-4\" aria-hidden />\n                    </Button>\n                  </td>\n                </motion.tr>\n              ))}\n            </tbody>\n          </table>\n        </div>\n      </CardContent>\n    </Card>\n  );\n}\n\nexport function StocksDashboard() {\n  const [selectedStock, setSelectedStock] = useState<Stock | null>(null);\n  const [isDetailsOpen, setIsDetailsOpen] = useState(false);\n  const shouldReduceMotion = useReducedMotion();\n\n  const handleRowClick = (stock: Stock) => {\n    setSelectedStock(stock);\n    setIsDetailsOpen(true);\n  };\n\n  return (\n    <div className=\"w-full px-3 py-4 sm:px-4 sm:py-8\">\n      <div className=\"mx-auto max-w-7xl\">\n        <motion.div\n          initial={shouldReduceMotion ? { opacity: 1, y: 0 } : { opacity: 0, y: 20 }}\n          animate={{ opacity: 1, y: 0 }}\n          transition={shouldReduceMotion ? { duration: 0 } : undefined}\n          className=\"mb-6 sm:mb-8\"\n        >\n          <h2 className=\"mb-2 text-2xl font-bold tracking-tight sm:text-3xl\">\n            Stock portfolio dashboard\n          </h2>\n          <p className=\"text-sm text-muted-foreground sm:text-base\">\n            Track your investments and monitor market performance.\n          </p>\n        </motion.div>\n\n        <StatusSection reduce={shouldReduceMotion} />\n        <DataTable onRowClick={handleRowClick} reduce={shouldReduceMotion} />\n        <StockDetails\n          stock={selectedStock}\n          isOpen={isDetailsOpen}\n          onClose={() => setIsDetailsOpen(false)}\n        />\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:block",
      "target": "components/uitripled/stocks-dashboard-shadcnui.tsx"
    }
  ]
}