{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bar-list",
  "type": "registry:component",
  "title": "Ranked bars",
  "description": "Compare the busiest destinations or highest-volume workstreams without a full chart.",
  "categories": [
    "charts"
  ],
  "dependencies": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/registry/overtrue/bar-list.tsx",
      "type": "registry:component",
      "target": "components/overtrue/bar-list.tsx",
      "content": "/** Adapted from dashboardcn (MIT), copyright 2026 dashboardcn contributors.\n * Source: https://github.com/NoahGdev/dashboardcn/tree/b1ffacbca0f7a0be60135c8665b9e8c267205c48\n *\n * MIT License\n *\n * Copyright (c) 2026 dashboardcn contributors\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n * ---\n *\n * Portions of this project are derived from shadcn/ui and shadcn/registry-template\n * (https://github.com/shadcn-ui/ui), Copyright (c) 2023 shadcn, licensed under the\n * MIT License. The notice above applies to those portions as well.\n */\nimport * as React from \"react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { formatNumber } from \"./metric-format\";\n\nexport interface BarListItem {\n  name: string;\n  value: number;\n  /** Renders the label as a link. */\n  href?: string;\n  icon?: React.ReactNode;\n  /** Stable key when names can repeat. */\n  key?: string;\n}\n\nexport interface BarListProps extends React.ComponentProps<\"div\"> {\n  data: BarListItem[];\n  valueFormatter?: (value: number) => string;\n  sortOrder?: \"descending\" | \"ascending\" | \"none\";\n  /** Any CSS color. Defaults to chart-1. */\n  color?: string;\n  /** Show each row's share of the total next to its value. */\n  showPercentage?: boolean;\n  onItemClick?: (item: BarListItem) => void;\n}\n\nconst keyframes =\n  \"@keyframes bar-list-grow{from{transform:scaleX(0)}to{transform:scaleX(1)}}\";\n\nfunction BarList({\n  data,\n  valueFormatter = (value) => formatNumber(value, { format: \"compact\" }),\n  sortOrder = \"descending\",\n  color = \"var(--color-chart-1)\",\n  showPercentage = false,\n  onItemClick,\n  className,\n  style,\n  ...props\n}: BarListProps) {\n  const items = React.useMemo(() => {\n    if (sortOrder === \"none\") return data;\n    const sorted = [...data].sort((a, b) => a.value - b.value);\n    return sortOrder === \"descending\" ? sorted.reverse() : sorted;\n  }, [data, sortOrder]);\n  const max = Math.max(...items.map((item) => item.value), 0);\n  const total = items.reduce((sum, item) => sum + item.value, 0);\n\n  return (\n    <div\n      data-slot=\"bar-list\"\n      className={cn(\"flex flex-col gap-1\", className)}\n      style={{ \"--bar-list-color\": color, ...style } as React.CSSProperties}\n      {...props}\n    >\n      <style href=\"overtrue-bar-list\" precedence=\"default\">\n        {keyframes}\n      </style>\n      {items.map((item, index) => {\n        const width = max > 0 ? (item.value / max) * 100 : 0;\n        const share = total > 0 ? item.value / total : 0;\n        const interactive = Boolean(item.href || onItemClick);\n        const Label = item.href ? \"a\" : onItemClick ? \"button\" : \"div\";\n\n        return (\n          <div\n            key={item.key ?? item.name}\n            data-slot=\"bar-list-row\"\n            className=\"group/row flex items-center gap-3 text-sm\"\n          >\n            <div className=\"relative flex h-8 min-w-0 flex-1 items-center rounded-md transition-colors duration-150 group-hover/row:bg-foreground/[0.035] motion-reduce:transition-none\">\n              <div\n                aria-hidden=\"true\"\n                data-slot=\"bar-list-bar\"\n                className=\"absolute inset-y-0 left-0 origin-left rounded-md transition-[width] duration-500 ease-[cubic-bezier(0.22,1,0.36,1)] [--bar-from:8%] [--bar-to:24%] group-hover/row:[--bar-from:13%] group-hover/row:[--bar-to:34%] motion-safe:animate-[bar-list-grow_700ms_cubic-bezier(0.22,1,0.36,1)_both] motion-reduce:transition-none dark:[--bar-from:12%] dark:[--bar-to:34%] dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.06)] dark:group-hover/row:[--bar-from:18%] dark:group-hover/row:[--bar-to:46%]\"\n                style={{\n                  width: `${width}%`,\n                  minWidth: width > 0 ? 4 : 0,\n                  animationDelay: `${Math.min(index, 12) * 40}ms`,\n                  backgroundImage:\n                    \"linear-gradient(90deg, color-mix(in oklab, var(--bar-list-color) var(--bar-from), transparent), color-mix(in oklab, var(--bar-list-color) var(--bar-to), transparent))\",\n                }}\n              />\n              <Label\n                {...(item.href ? { href: item.href } : {})}\n                {...(onItemClick && !item.href\n                  ? {\n                      type: \"button\" as const,\n                      onClick: () => onItemClick(item),\n                    }\n                  : {})}\n                className={cn(\n                  \"relative flex min-w-0 items-center gap-2 rounded-md px-2.5 text-left text-foreground/90\",\n                  interactive &&\n                    \"underline-offset-4 outline-none hover:underline hover:decoration-muted-foreground/50 focus-visible:ring-2 focus-visible:ring-primary/30\",\n                )}\n              >\n                {item.icon ? (\n                  <span className=\"text-muted-foreground shrink-0 [&>svg]:size-4\">\n                    {item.icon}\n                  </span>\n                ) : null}\n                <span className=\"truncate\">{item.name}</span>\n              </Label>\n            </div>\n            <div className=\"flex shrink-0 items-center gap-3 tabular-nums\">\n              <span\n                data-slot=\"bar-list-value\"\n                className=\"min-w-12 text-right font-medium\"\n              >\n                {valueFormatter(item.value)}\n              </span>\n              {showPercentage ? (\n                <span\n                  data-slot=\"bar-list-share\"\n                  className=\"text-muted-foreground w-11 text-right text-xs\"\n                >\n                  {formatNumber(share, { format: \"percent\" })}\n                </span>\n              ) : null}\n            </div>\n          </div>\n        );\n      })}\n    </div>\n  );\n}\n\nexport { BarList };\n"
    },
    {
      "path": "src/registry/overtrue/metric-format.tsx",
      "type": "registry:component",
      "target": "components/overtrue/metric-format.tsx",
      "content": "/** Adapted from dashboardcn (MIT), copyright 2026 dashboardcn contributors.\n * Source: https://github.com/NoahGdev/dashboardcn/tree/b1ffacbca0f7a0be60135c8665b9e8c267205c48\n *\n * MIT License\n *\n * Copyright (c) 2026 dashboardcn contributors\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n * ---\n *\n * Portions of this project are derived from shadcn/ui and shadcn/registry-template\n * (https://github.com/shadcn-ui/ui), Copyright (c) 2023 shadcn, licensed under the\n * MIT License. The notice above applies to those portions as well.\n */\nexport type NumberFormat = \"number\" | \"compact\" | \"currency\" | \"percent\";\n\nexport interface FormatNumberOptions {\n  format?: NumberFormat;\n  /** ISO 4217 code, used when format is \"currency\". Defaults to USD. */\n  currency?: string;\n  locale?: string;\n  maximumFractionDigits?: number;\n  /** Abbreviate large values, e.g. \"$158K\" instead of \"$158,143\". */\n  compact?: boolean;\n}\n\nconst formatterCache = new Map<string, Intl.NumberFormat>();\n\nfunction getFormatter(locale: string, options: Intl.NumberFormatOptions) {\n  const key = locale + JSON.stringify(options);\n  let formatter = formatterCache.get(key);\n  if (!formatter) {\n    formatter = new Intl.NumberFormat(locale, options);\n    formatterCache.set(key, formatter);\n  }\n  return formatter;\n}\n\n/**\n * Format a metric value for display.\n *\n * formatNumber(1234567)                          -> \"1,234,567\"\n * formatNumber(1234567, { format: \"compact\" })   -> \"1.2M\"\n * formatNumber(48.2, { format: \"currency\" })     -> \"$48.20\"\n * formatNumber(158143, { format: \"currency\", compact: true }) -> \"$158K\"\n * formatNumber(0.124, { format: \"percent\" })     -> \"12.4%\"\n */\nexport function formatNumber(\n  value: number,\n  {\n    format = \"number\",\n    currency = \"USD\",\n    locale = \"en-US\",\n    maximumFractionDigits,\n    compact = false,\n  }: FormatNumberOptions = {},\n): string {\n  if (!Number.isFinite(value)) return \"—\";\n\n  // Compact values keep three significant digits: $158K, $1.23M, 41.2K.\n  const compactOptions: Intl.NumberFormatOptions = compact\n    ? maximumFractionDigits === undefined\n      ? { notation: \"compact\", maximumSignificantDigits: 3 }\n      : { notation: \"compact\", maximumFractionDigits }\n    : {};\n  switch (format) {\n    case \"compact\":\n      return getFormatter(locale, {\n        notation: \"compact\",\n        maximumFractionDigits: maximumFractionDigits ?? 1,\n      }).format(value);\n    case \"currency\":\n      return getFormatter(locale, {\n        style: \"currency\",\n        currency,\n        maximumFractionDigits: maximumFractionDigits ?? 2,\n        ...compactOptions,\n      }).format(value);\n    case \"percent\":\n      return getFormatter(locale, {\n        style: \"percent\",\n        maximumFractionDigits: maximumFractionDigits ?? 1,\n      }).format(value);\n    default:\n      return getFormatter(locale, {\n        maximumFractionDigits: maximumFractionDigits ?? 0,\n        ...compactOptions,\n      }).format(value);\n  }\n}\n\n/**\n * Format a fractional change as a signed percentage.\n *\n * formatDelta(0.124)  -> \"+12.4%\"\n * formatDelta(-0.03)  -> \"-3.0%\"\n * formatDelta(0)      -> \"0.0%\"\n */\nexport function formatDelta(delta: number, locale = \"en-US\"): string {\n  if (!Number.isFinite(delta)) return \"—\";\n  return getFormatter(locale, {\n    style: \"percent\",\n    signDisplay: \"exceptZero\",\n    maximumFractionDigits: 1,\n    minimumFractionDigits: 1,\n  }).format(delta);\n}\n\n/**\n * Fractional change between two values. Returns 0 when there is no baseline.\n */\nexport function computeDelta(current: number, previous: number): number {\n  if (!previous) return 0;\n  return (current - previous) / Math.abs(previous);\n}\n"
    }
  ],
  "docs": "Documentation: https://ui.overtrue.xyz/components/bar-list. Requires an initialized shadcn/ui project with Tailwind CSS v4."
}
