{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "leaderboard",
  "title": "Leaderboard",
  "description": "Primitives for composing ranked lists and leaderboards.",
  "dependencies": [
    "class-variance-authority"
  ],
  "registryDependencies": [
    "https://www.dashboardblocks.com/r/radix/change-amount.json",
    "https://www.dashboardblocks.com/r/radix/use-reveal.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/leaderboard.tsx",
      "content": "'use client'\n\nimport { ChangeAmount } from '@/registry/components/dashboardblocks/change-amount'\nimport { useReveal } from '@/registry/hooks/use-reveal'\nimport { type VariantProps, cva } from 'class-variance-authority'\nimport type { ReactNode } from 'react'\n\nimport { cn } from '@/lib/utils'\n\nconst itemVariants = cva('relative isolate flex items-center rounded-md text-sm', {\n  variants: {\n    size: {\n      default: 'gap-3 px-2 py-1.5',\n      lg: 'gap-3 px-2 py-2',\n      sm: 'gap-2 px-1.5 py-1',\n    },\n  },\n  defaultVariants: {\n    size: 'default',\n  },\n})\n\nconst rankVariants = cva(\n  'inline-flex shrink-0 items-center justify-center text-xs font-medium tabular-nums',\n  {\n    variants: {\n      variant: {\n        badge: 'size-6 rounded-full bg-muted text-foreground',\n        plain: 'w-5 text-muted-foreground',\n      },\n    },\n    defaultVariants: {\n      variant: 'plain',\n    },\n  },\n)\n\nconst medalStyles: Record<number, string> = {\n  1: 'bg-[color-mix(in_oklab,var(--color-chart-2)_35%,transparent)] text-foreground',\n  2: 'bg-[color-mix(in_oklab,var(--color-chart-2)_20%,transparent)] text-foreground',\n  3: 'bg-[color-mix(in_oklab,var(--color-chart-2)_10%,transparent)] text-foreground',\n}\n\ntype LeaderboardProps = {\n  children: ReactNode\n  className?: string\n}\n\ntype LeaderboardItemProps = {\n  children: ReactNode\n  className?: string\n  size?: VariantProps<typeof itemVariants>['size']\n}\n\ninterface LeaderboardRankProps extends VariantProps<typeof rankVariants> {\n  className?: string\n  medal?: boolean\n  rank: number\n}\n\ntype LeaderboardBarProps = {\n  animated?: boolean\n  className?: string\n  delay?: number\n  value: number\n}\n\ntype LeaderboardRankChangeProps = {\n  change: number | 'new'\n  className?: string\n}\n\nfunction Leaderboard({ children, className }: LeaderboardProps) {\n  return <ol className={cn('flex flex-col gap-1', className)}>{children}</ol>\n}\n\nfunction LeaderboardItem({\n  children,\n  className,\n  size = 'default',\n}: LeaderboardItemProps) {\n  return <li className={cn(itemVariants({ size }), className)}>{children}</li>\n}\n\nfunction LeaderboardRank({\n  className,\n  medal = false,\n  rank,\n  variant = 'plain',\n}: LeaderboardRankProps) {\n  return (\n    <span\n      className={cn(\n        rankVariants({ variant }),\n        medal && variant === 'badge' && medalStyles[rank],\n        className,\n      )}\n    >\n      <span className='sr-only'>Rank </span>\n      {rank}\n    </span>\n  )\n}\n\nfunction LeaderboardBar({\n  animated = true,\n  className,\n  delay = 0,\n  value,\n}: LeaderboardBarProps) {\n  const { ref, revealed } = useReveal(animated)\n\n  const safeValue = Number.isFinite(value) ? value : 0\n  const normalized = Math.min(100, Math.max(0, safeValue))\n\n  return (\n    <div\n      ref={ref}\n      aria-hidden='true'\n      className='pointer-events-none absolute inset-0 -z-10 overflow-hidden rounded-[inherit]'\n    >\n      <div\n        className={cn(\n          'h-full rounded-[inherit] bg-[color-mix(in_oklab,var(--color-chart-2)_18%,transparent)] transition-[width] duration-1000 ease-[cubic-bezier(0.33,1,0.68,1)] motion-reduce:transition-none',\n          className,\n        )}\n        style={{\n          transitionDelay: animated ? `${delay}ms` : undefined,\n          width: `${!animated || revealed ? normalized : 0}%`,\n        }}\n      />\n    </div>\n  )\n}\n\nfunction LeaderboardLabel({ children, className }: LeaderboardProps) {\n  return <div className={cn('min-w-0 flex-1', className)}>{children}</div>\n}\n\nfunction LeaderboardValue({ children, className }: LeaderboardProps) {\n  return (\n    <div className={cn('shrink-0 text-end font-medium tabular-nums', className)}>\n      {children}\n    </div>\n  )\n}\n\nfunction LeaderboardRankChange({ change, className }: LeaderboardRankChangeProps) {\n  if (change === 'new') {\n    return (\n      <span\n        className={cn('text-sm font-medium text-sky-700 dark:text-sky-400', className)}\n      >\n        New\n      </span>\n    )\n  }\n\n  if (change === 0) {\n    return (\n      <span\n        className={cn(\n          'text-sm font-medium whitespace-nowrap text-muted-foreground',\n          className,\n        )}\n      >\n        No change\n      </span>\n    )\n  }\n\n  const isUp = change > 0\n\n  return (\n    <ChangeAmount\n      change={change}\n      className={cn(\n        'text-sm font-medium whitespace-nowrap tabular-nums',\n        isUp\n          ? 'text-emerald-700 dark:text-emerald-400'\n          : 'text-red-700 dark:text-red-400',\n        className,\n      )}\n    >\n      {Math.abs(change)}\n      <span className='sr-only'> {Math.abs(change) === 1 ? 'place' : 'places'}</span>\n    </ChangeAmount>\n  )\n}\n\nexport {\n  Leaderboard,\n  LeaderboardBar,\n  LeaderboardItem,\n  LeaderboardLabel,\n  LeaderboardRank,\n  LeaderboardRankChange,\n  LeaderboardValue,\n  rankVariants,\n}\nexport type {\n  LeaderboardBarProps,\n  LeaderboardItemProps,\n  LeaderboardRankChangeProps,\n  LeaderboardRankProps,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/leaderboard.tsx"
    }
  ],
  "type": "registry:component"
}
