{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "leaderboard-01",
  "description": "Ranked rows with a background bar sized relative to the leader.",
  "registryDependencies": [
    "card",
    "button",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/leaderboard.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/leaderboard/leaderboard-01.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  Leaderboard,\n  LeaderboardBar,\n  LeaderboardItem,\n  LeaderboardLabel,\n  LeaderboardValue,\n} from '@/registry/components/dashboardblocks/leaderboard'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { formatNumber, formatPercent } from '@/registry/lib/dashboardblocks/format'\n\nimport { Button } from '@/components/ui/button'\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface PageStat {\n  path: string\n  visitors: number\n}\n\ninterface Leaderboard1Props extends BlockStateProps {\n  /** Defaults to a sentence about the visitors and the top page's share. */\n  description?: string\n  /** Heads the column of names. @default 'Page' */\n  labelHeader?: string\n  onViewAll?: () => void\n  /** Leave out, or pass none, to show the empty state. */\n  pages?: PageStat[]\n  title: string\n  /** Heads the column of counts. @default 'Visitors' */\n  valueHeader?: string\n  /** Names the button that opens the full list; `null` leaves it out. @default 'View all' */\n  viewAllLabel?: string | null\n}\n\nconst exampleProps: Leaderboard1Props = {\n  pages: [\n    { path: '/', visitors: 18_420 },\n    { path: '/pricing', visitors: 9_312 },\n    { path: '/docs/getting-started', visitors: 7_845 },\n    { path: '/blog/launch-week', visitors: 5_127 },\n    { path: '/changelog', visitors: 3_406 },\n    { path: '/careers', visitors: 1_982 },\n  ],\n  title: 'Top pages',\n}\n\nconst summarize = (pages: PageStat[]) => {\n  const total = pages.reduce((sum, page) => sum + page.visitors, 0)\n  const [top] = pages\n  if (!top || total === 0) return 'No visitors yet.'\n  const visitors = `${formatNumber(total)} visitors across ${pages.length} ${pages.length === 1 ? 'page' : 'pages'}`\n  return `${visitors}, ${formatPercent(top.visitors / total, { maximumFractionDigits: 0 })} of them to ${top.path}.`\n}\n\nconst Leaderboard1 = (props: Leaderboard1Props) => {\n  const {\n    labelHeader = 'Page',\n    onViewAll,\n    pages = [],\n    errorMessage,\n    status,\n    title,\n    valueHeader = 'Visitors',\n    viewAllLabel = 'View all',\n  } = props\n  const { description = summarize(pages) } = props\n  const state = getBlockState(status, pages)\n  const max = Math.max(...pages.map((page) => page.visitors), 1)\n\n  return (\n    <Card>\n      <CardContent>\n        <BlockStateProvider errorMessage={errorMessage} state={state}>\n          <section className='@container flex flex-col gap-4'>\n            <header className='flex items-start justify-between gap-3'>\n              <div className='flex min-w-0 flex-col gap-0.5'>\n                <h2 className='font-semibold tracking-tight'>{title}</h2>\n                <BlockReady className='text-sm'>\n                  <p className='text-muted-foreground text-sm'>{description}</p>\n                </BlockReady>\n              </div>\n              {viewAllLabel !== null && (\n                <Button variant='outline' size='sm' onClick={onViewAll}>\n                  {viewAllLabel}\n                  <IconPlaceholder\n                    lucide='ArrowRightIcon'\n                    tabler='IconArrowRight'\n                    hugeicons='ArrowRight01Icon'\n                    phosphor='ArrowRightIcon'\n                    remixicon='RiArrowRightLine'\n                    data-icon='inline-end'\n                  />\n                </Button>\n              )}\n            </header>\n            <div className='flex flex-col gap-1.5 border-t pt-4'>\n              <div className='text-muted-foreground flex justify-between px-2 text-xs'>\n                <span>{labelHeader}</span>\n                <span>{valueHeader}</span>\n              </div>\n              <BlockStateRows rows={6} />\n              {!state && (\n                <Leaderboard>\n                  {pages.map((page, index) => (\n                    <LeaderboardItem key={page.path}>\n                      <LeaderboardBar\n                        className={\n                          index === 0\n                            ? 'bg-[color-mix(in_oklab,var(--color-chart-2)_32%,transparent)]'\n                            : undefined\n                        }\n                        delay={index * 100}\n                        value={(page.visitors / max) * 100}\n                      />\n                      <LeaderboardLabel className='truncate'>\n                        {page.path}\n                      </LeaderboardLabel>\n                      <LeaderboardValue>{formatNumber(page.visitors)}</LeaderboardValue>\n                    </LeaderboardItem>\n                  ))}\n                </Leaderboard>\n              )}\n            </div>\n          </section>\n        </BlockStateProvider>\n      </CardContent>\n    </Card>\n  )\n}\n\nexport {\n  Leaderboard1,\n  exampleProps as leaderboard1ExampleProps,\n  type Leaderboard1Props,\n  type PageStat,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/leaderboard/leaderboard-01.tsx"
    }
  ],
  "meta": {
    "shows": "Ranked rows with a background bar sized relative to the leader.",
    "size": "half",
    "usedWith": [
      "breakdown-01",
      "geo-02",
      "chart-panel-02"
    ],
    "component": "Leaderboard1",
    "props": "{ description?: string; labelHeader?: string; onViewAll?: () => void; pages?: { path: string; visitors: number }[]; title: string; valueHeader?: string; viewAllLabel?: null | string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
