{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "leaderboard-03",
  "description": "The top three on a podium sized by their totals, with the rest of the field listed below.",
  "registryDependencies": [
    "card",
    "avatar",
    "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",
    "https://www.dashboardblocks.com/r/radix/use-reveal.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/leaderboard/leaderboard-03.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  LeaderboardItem,\n  LeaderboardLabel,\n  LeaderboardRank,\n  LeaderboardValue,\n} from '@/registry/components/dashboardblocks/leaderboard'\nimport { useReveal } from '@/registry/hooks/use-reveal'\nimport { formatNumber, formatPercent } from '@/registry/lib/dashboardblocks/format'\n\nimport { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'\nimport { Card, CardContent } from '@/components/ui/card'\n\nimport { cn } from '@/lib/utils'\n\ninterface Contributor {\n  avatar: string\n  id: number\n  name: string\n  value: number\n}\n\ninterface Leaderboard3Props extends BlockStateProps {\n  /** Leave out, or pass none, to show the empty state. */\n  contributors?: Contributor[]\n  /** Defaults to a sentence about the winner's lead. */\n  description?: string\n  title: string\n  unit: string\n}\n\nconst exampleProps: Leaderboard3Props = {\n  contributors: [\n    { id: 1, name: 'Sarah Chen', avatar: '/images/avatar-11.webp', value: 312 },\n    { id: 2, name: 'Marcus Reid', avatar: '/images/avatar-04.webp', value: 268 },\n    { id: 3, name: 'Priya Patel', avatar: '/images/avatar-02.webp', value: 241 },\n    { id: 4, name: 'Diego Alvarez', avatar: '/images/avatar-13.webp', value: 187 },\n    { id: 5, name: 'Emma Larsen', avatar: '/images/avatar-03.webp', value: 154 },\n    { id: 6, name: 'Tom Becker', avatar: '/images/avatar-17.webp', value: 129 },\n  ],\n  title: 'Top contributors',\n  unit: 'commits',\n}\n\nconst PODIUM_HEIGHT = 112\n\nconst podium = [\n  {\n    avatar: 'size-12',\n    order: 'order-2',\n    step: 'bg-[color-mix(in_oklab,var(--color-chart-2)_45%,transparent)]',\n  },\n  {\n    avatar: 'size-10',\n    order: 'order-1',\n    step: 'bg-[color-mix(in_oklab,var(--color-chart-2)_22%,transparent)]',\n  },\n  {\n    avatar: 'size-10',\n    order: 'order-3',\n    step: 'bg-[color-mix(in_oklab,var(--color-chart-2)_22%,transparent)]',\n  },\n]\n\nfunction getInitials(name: string) {\n  return name\n    .split(/\\s+/)\n    .filter(Boolean)\n    .slice(0, 2)\n    .map((part) => part[0]?.toUpperCase())\n    .join('')\n}\n\nfunction summarize(contributors: Contributor[], unit: string) {\n  const [first, second] = contributors\n  if (!first) return `No ${unit} yet.`\n  const total = contributors.reduce((sum, contributor) => sum + contributor.value, 0)\n  const share = formatPercent(first.value / (total || 1), { maximumFractionDigits: 0 })\n  return second\n    ? `${first.name} leads with ${formatNumber(first.value)} ${unit}, ${formatNumber(first.value - second.value)} more than ${second.name} and ${share} of the team's ${formatNumber(total)}.`\n    : `${first.name} leads with ${formatNumber(first.value)} ${unit}.`\n}\n\ninterface PodiumProps {\n  top: Contributor[]\n  unit: string\n}\n\nfunction Podium({ top, unit }: PodiumProps) {\n  const { ref, revealed } = useReveal<HTMLOListElement>(true)\n  const max = Math.max(top[0]?.value ?? 0, 1)\n\n  return (\n    <ol ref={ref} className='grid grid-cols-3 items-end gap-2 border-y pt-4'>\n      {top.map((contributor, index) => {\n        const step = podium[index]\n        const delay = `${index * 100}ms`\n        return (\n          <li\n            key={contributor.id}\n            className={cn('flex min-w-0 flex-col items-center', step.order)}\n          >\n            <div\n              className={cn(\n                'flex w-full flex-col items-center gap-2 pb-3 text-center transition-[opacity,translate,filter] duration-400 ease-out motion-reduce:transition-none',\n                revealed\n                  ? 'translate-y-0 opacity-100 blur-[0px]'\n                  : 'translate-y-3 opacity-0 blur-[4px]',\n              )}\n              style={{ transitionDelay: delay }}\n            >\n              <Avatar\n                // Not the primitive's colour: the style sets no outline, so this one is the block's own\n                className={cn(\n                  'outline outline-1 -outline-offset-1 outline-black/10 dark:outline-white/10',\n                  step.avatar,\n                )}\n              >\n                <AvatarImage src={contributor.avatar} alt='' />\n                <AvatarFallback className='text-xs'>\n                  {getInitials(contributor.name)}\n                </AvatarFallback>\n              </Avatar>\n              <div className='flex w-full min-w-0 flex-col'>\n                <p className='truncate text-sm font-medium'>{contributor.name}</p>\n                <p className='flex flex-wrap items-baseline justify-center gap-x-1'>\n                  <span\n                    className={cn(\n                      'font-light tracking-tight tabular-nums',\n                      index === 0 ? 'text-3xl' : 'text-2xl',\n                    )}\n                  >\n                    {formatNumber(contributor.value)}\n                  </span>\n                  <span className='text-muted-foreground text-base font-normal tracking-normal'>\n                    {unit}\n                  </span>\n                </p>\n              </div>\n            </div>\n            <div className='w-full overflow-hidden rounded-t-lg'>\n              <div\n                className={cn(\n                  'text-foreground flex items-start justify-center pt-2 text-sm font-medium tabular-nums transition-transform duration-700 ease-[cubic-bezier(0.33,1,0.68,1)] motion-reduce:transition-none',\n                  step.step,\n                  revealed ? 'translate-y-0' : 'translate-y-full',\n                )}\n                style={{\n                  height: Math.max(32, (contributor.value / max) * PODIUM_HEIGHT),\n                  transitionDelay: delay,\n                }}\n              >\n                <span className='sr-only'>Rank </span>\n                {index + 1}\n              </div>\n            </div>\n          </li>\n        )\n      })}\n    </ol>\n  )\n}\n\nconst Leaderboard3 = (props: Leaderboard3Props) => {\n  const { contributors = [], errorMessage, status, title, unit } = props\n  const state = getBlockState(status, contributors)\n  const { description = summarize(contributors, unit) } = props\n  const top = contributors.slice(0, 3)\n  const rest = contributors.slice(3)\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 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            </header>\n            <BlockStateRows className='border-t' rows={6} />\n            {!state && <Podium top={top} unit={unit} />}\n            {!state && rest.length > 0 && (\n              <Leaderboard className='gap-0'>\n                {rest.map((contributor, index) => (\n                  <LeaderboardItem\n                    key={contributor.id}\n                    className='border-b px-0 py-2.5 last:border-b-0'\n                  >\n                    <LeaderboardRank rank={index + 4} />\n                    <Avatar\n                      // Not the primitive's colour: the style sets no outline, so this one is the block's own\n                      className='size-7 outline outline-1 -outline-offset-1 outline-black/10 dark:outline-white/10'\n                    >\n                      <AvatarImage src={contributor.avatar} alt='' />\n                      <AvatarFallback className='text-xs'>\n                        {getInitials(contributor.name)}\n                      </AvatarFallback>\n                    </Avatar>\n                    <LeaderboardLabel className='truncate'>\n                      {contributor.name}\n                    </LeaderboardLabel>\n                    <LeaderboardValue>\n                      {formatNumber(contributor.value)}\n                      <span className='text-muted-foreground text-xs font-normal'>\n                        {' '}\n                        {unit}\n                      </span>\n                    </LeaderboardValue>\n                  </LeaderboardItem>\n                ))}\n              </Leaderboard>\n            )}\n          </section>\n        </BlockStateProvider>\n      </CardContent>\n    </Card>\n  )\n}\n\nexport {\n  Leaderboard3,\n  exampleProps as leaderboard3ExampleProps,\n  type Contributor,\n  type Leaderboard3Props,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/leaderboard/leaderboard-03.tsx"
    }
  ],
  "meta": {
    "shows": "The top three on a podium sized by their totals, with the rest of the field listed below.",
    "size": "half",
    "usedWith": [
      "leaderboard-02",
      "team-02",
      "chart-panel-01"
    ],
    "component": "Leaderboard3",
    "props": "{ contributors?: { avatar: string; id: number; name: string; value: number }[]; description?: string; title: string; unit: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
