{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ranked-list",
  "type": "registry:component",
  "title": "Ranked list",
  "description": "Compare sources, products, or regions with sorted bars, values, and share of total.",
  "categories": [
    "tables-&-lists"
  ],
  "dependencies": [
    "@tabler/icons-react"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/registry/overtrue/ranked-list.tsx",
      "type": "registry:component",
      "target": "components/overtrue/ranked-list.tsx",
      "content": "import type { CSSProperties, ReactNode } from \"react\";\nimport { IconArrowUpRight } from \"@tabler/icons-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface RankedListItem {\n  id: string;\n  label: string;\n  value: number;\n  icon?: ReactNode;\n  href?: string;\n}\nexport interface RankedListProps {\n  items: RankedListItem[];\n  label: string;\n  formatValue?: (value: number) => string;\n  emptyMessage?: string;\n  className?: string;\n  /** Any CSS color for the bars. Defaults to the primary color. */\n  color?: string;\n  /** Show each row's rank before its label. */\n  showRank?: boolean;\n}\n\n/**\n * A sorted list of labelled values with a proportional bar behind each row, the value,\n * and its share of the total. Hovering a row brings its bar forward and quiets the rest.\n */\nexport function RankedList({\n  items,\n  label,\n  formatValue = (value) => value.toLocaleString(\"en-US\"),\n  emptyMessage = \"No results for this period.\",\n  className,\n  color = \"var(--color-primary)\",\n  showRank = false,\n}: RankedListProps) {\n  const rows = items\n    .map((item) => ({\n      ...item,\n      value: Number.isFinite(item.value) ? Math.max(0, item.value) : 0,\n    }))\n    .sort((a, b) => b.value - a.value);\n  const max = rows[0]?.value ?? 0;\n  const total = rows.reduce((sum, item) => sum + item.value, 0);\n  return (\n    <ol\n      data-slot=\"ranked-list\"\n      aria-label={label}\n      className={cn(\n        \"@container/ranking m-0 list-none space-y-2 p-0\",\n        // While one row is hovered, the other bars step back.\n        \"[&:has(>li:hover)>li:not(:hover)_[data-slot=ranked-list-bar]]:opacity-45\",\n        className,\n      )}\n      style={{ \"--ranked-list-color\": color } as CSSProperties}\n    >\n      <style href=\"overtrue-ranked-list\" precedence=\"default\">\n        {`@keyframes ranked-list-grow{from{transform:scaleX(0)}}`}\n      </style>\n      {!rows.length && (\n        <li className=\"py-8 text-center text-sm text-muted-foreground\">\n          {emptyMessage}\n        </li>\n      )}\n      {rows.map((item, index) => {\n        const width = max ? (item.value / max) * 100 : 0;\n        const content = (\n          <>\n            <span\n              aria-hidden=\"true\"\n              data-slot=\"ranked-list-bar\"\n              className={cn(\n                \"pointer-events-none absolute inset-y-0 left-0 origin-left rounded-lg\",\n                // The fill deepens toward its end, so its length reads without a hard rule through the label.\n                \"bg-[linear-gradient(to_right,color-mix(in_oklab,var(--ranked-list-color)_8%,transparent),color-mix(in_oklab,var(--ranked-list-color)_22%,transparent))]\",\n                \"shadow-[inset_0_0_0_1px_color-mix(in_oklab,var(--ranked-list-color)_7%,transparent)]\",\n                \"dark:bg-[linear-gradient(to_right,color-mix(in_oklab,var(--ranked-list-color)_8%,transparent),color-mix(in_oklab,var(--ranked-list-color)_28%,transparent))]\",\n                \"dark:shadow-[inset_0_0_0_1px_color-mix(in_oklab,var(--ranked-list-color)_10%,transparent),inset_0_1px_0_rgb(255_255_255/0.05)]\",\n                \"transition-[width,opacity,filter] duration-500 ease-[cubic-bezier(0.22,1,0.36,1)] group-hover/row:brightness-[1.06] group-hover/row:saturate-150 motion-reduce:transition-none\",\n                \"motion-safe:animate-[ranked-list-grow_700ms_cubic-bezier(0.22,1,0.36,1)_backwards]\",\n              )}\n              style={{\n                width: `${width}%`,\n                animationDelay: `${index * 40}ms`,\n              }}\n            />\n            <span className=\"relative flex min-w-0 items-center gap-2\">\n              {showRank && (\n                <span\n                  aria-hidden=\"true\"\n                  className=\"w-5 shrink-0 text-xs text-muted-foreground tabular-nums\"\n                >\n                  {index + 1}\n                </span>\n              )}\n              {item.icon && (\n                <span\n                  aria-hidden=\"true\"\n                  className=\"shrink-0 text-muted-foreground transition-colors duration-150 group-hover/row:text-foreground motion-reduce:transition-none [&>svg]:size-4\"\n                >\n                  {item.icon}\n                </span>\n              )}\n              <span className=\"min-w-0 wrap-anywhere\">{item.label}</span>\n              {item.href && (\n                <IconArrowUpRight\n                  aria-hidden=\"true\"\n                  className=\"size-3.5 shrink-0 text-muted-foreground transition-[translate,color] duration-150 group-hover/row:translate-x-px group-hover/row:-translate-y-px group-hover/row:text-foreground motion-reduce:transition-none\"\n                />\n              )}\n            </span>\n            <span className=\"relative flex flex-wrap items-baseline justify-between gap-x-3 gap-y-0.5 text-right tabular-nums @min-[18rem]/ranking:justify-end\">\n              <span className=\"font-medium\">{formatValue(item.value)}</span>\n              <span className=\"w-12 text-right text-xs text-muted-foreground\">\n                {total ? `${((item.value / total) * 100).toFixed(1)}%` : \"—\"}\n                <span className=\"sr-only\"> of total</span>\n              </span>\n            </span>\n          </>\n        );\n        const rowClass =\n          \"group/row relative grid grid-cols-1 items-center gap-1.5 rounded-lg px-3 py-3 text-sm text-foreground transition-colors duration-150 hover:bg-muted/50 motion-reduce:transition-none @min-[18rem]/ranking:grid-cols-[minmax(0,1fr)_auto] @min-[18rem]/ranking:gap-3\";\n        return (\n          <li key={item.id}>\n            {item.href ? (\n              <a\n                href={item.href}\n                className={cn(\n                  rowClass,\n                  \"outline-none focus-visible:ring-2 focus-visible:ring-primary/30\",\n                )}\n              >\n                {content}\n              </a>\n            ) : (\n              <div className={rowClass}>{content}</div>\n            )}\n          </li>\n        );\n      })}\n    </ol>\n  );\n}\n"
    }
  ],
  "docs": "Documentation: https://ui.overtrue.xyz/components/ranked-list. Requires an initialized shadcn/ui project with Tailwind CSS v4."
}
