{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "distribution-bar",
  "type": "registry:component",
  "title": "Distribution bar",
  "description": "Show how a total is divided among categories in a single horizontal strip.",
  "categories": [
    "charts"
  ],
  "dependencies": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/registry/overtrue/distribution-bar.tsx",
      "type": "registry:component",
      "target": "components/overtrue/distribution-bar.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 */\n\"use client\";\n\nimport * as React from \"react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { formatNumber } from \"./metric-format\";\n\nexport interface DistributionSegment {\n  name: string;\n  value: number;\n  /** Any CSS color. Defaults to chart-1 through chart-5 in order. */\n  color?: string;\n}\n\nexport interface DistributionBarProps extends React.ComponentProps<\"div\"> {\n  segments: DistributionSegment[];\n  valueFormatter?: (value: number) => string;\n  showLegend?: boolean;\n  /** Show absolute values in the legend in addition to the share. */\n  showValues?: boolean;\n}\n\nconst defaultColors = [\n  \"var(--color-chart-1)\",\n  \"var(--color-chart-2)\",\n  \"var(--color-chart-3)\",\n  \"var(--color-chart-4)\",\n  \"var(--color-chart-5)\",\n];\n\nconst keyframes =\n  \"@keyframes distribution-bar-reveal{from{clip-path:inset(0 100% 0 0 round 999px)}to{clip-path:inset(0 0 0 0 round 999px)}}\";\n\nfunction DistributionBar({\n  segments,\n  valueFormatter = (value) => formatNumber(value, { format: \"compact\" }),\n  showLegend = true,\n  showValues = false,\n  className,\n  ...props\n}: DistributionBarProps) {\n  const [active, setActive] = React.useState<string | null>(null);\n  const total = segments.reduce((sum, segment) => sum + segment.value, 0);\n  const resolved = segments.map((segment, index) => ({\n    ...segment,\n    color: segment.color ?? defaultColors[index % defaultColors.length]!,\n    share: total > 0 ? segment.value / total : 0,\n  }));\n  const visible = resolved.filter((segment) => segment.share > 0);\n\n  return (\n    <div\n      data-slot=\"distribution-bar\"\n      className={cn(\"flex flex-col gap-3.5\", className)}\n      {...props}\n    >\n      <style href=\"overtrue-distribution-bar\" precedence=\"default\">\n        {keyframes}\n      </style>\n      <div\n        role=\"img\"\n        aria-label={resolved\n          .map(\n            (segment) =>\n              `${segment.name} ${formatNumber(segment.share, { format: \"percent\" })}`,\n          )\n          .join(\", \")}\n        data-slot=\"distribution-bar-strip\"\n        className=\"flex h-3 w-full gap-[3px] motion-safe:animate-[distribution-bar-reveal_800ms_cubic-bezier(0.22,1,0.36,1)_both]\"\n        onMouseLeave={() => setActive(null)}\n      >\n        {visible.map((segment, index) => (\n          <div\n            key={segment.name}\n            data-slot=\"distribution-bar-segment\"\n            data-active={active === segment.name || undefined}\n            onMouseEnter={() => setActive(segment.name)}\n            className={cn(\n              \"h-full min-w-[3px] rounded-[3px] transition-[flex-grow,opacity] duration-500 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.12)]\",\n              index === 0 && \"rounded-l-full\",\n              index === visible.length - 1 && \"rounded-r-full\",\n            )}\n            style={{\n              flex: `${segment.share} 1 0%`,\n              backgroundImage: `linear-gradient(180deg, ${segment.color}, color-mix(in oklab, ${segment.color} 78%, transparent))`,\n              opacity: active && active !== segment.name ? 0.4 : 1,\n              transitionDuration: active !== null ? \"150ms\" : undefined,\n            }}\n          />\n        ))}\n      </div>\n      {showLegend ? (\n        <ul\n          data-slot=\"distribution-bar-legend\"\n          className=\"flex flex-wrap gap-x-5 gap-y-2 text-sm\"\n          onMouseLeave={() => setActive(null)}\n        >\n          {resolved.map((segment) => (\n            <li\n              key={segment.name}\n              data-active={active === segment.name || undefined}\n              onMouseEnter={() => setActive(segment.name)}\n              className={cn(\n                \"flex items-center gap-2 transition-opacity duration-150 motion-reduce:transition-none\",\n                active && active !== segment.name && \"opacity-50\",\n              )}\n            >\n              <span\n                aria-hidden=\"true\"\n                className=\"size-2 shrink-0 rounded-full\"\n                style={{\n                  backgroundColor: segment.color,\n                  boxShadow: `0 0 0 2px color-mix(in oklab, ${segment.color} 16%, transparent)`,\n                }}\n              />\n              <span className=\"text-muted-foreground\">{segment.name}</span>\n              <span className=\"font-medium tabular-nums\">\n                {formatNumber(segment.share, { format: \"percent\" })}\n              </span>\n              {showValues ? (\n                <span className=\"text-muted-foreground text-xs tabular-nums\">\n                  ({valueFormatter(segment.value)})\n                </span>\n              ) : null}\n            </li>\n          ))}\n        </ul>\n      ) : null}\n    </div>\n  );\n}\n\nexport { DistributionBar };\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/distribution-bar. Requires an initialized shadcn/ui project with Tailwind CSS v4."
}
