{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "segmented-meter",
  "type": "registry:component",
  "title": "Capacity zones",
  "description": "Place a live value against named operating ranges and highlight its current zone.",
  "categories": [
    "metrics"
  ],
  "dependencies": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/registry/overtrue/segmented-meter.tsx",
      "type": "registry:component",
      "target": "components/overtrue/segmented-meter.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 MeterZone {\n  label?: string;\n  from: number;\n  to: number;\n  /** Any CSS color. Defaults to chart-1. */\n  color?: string;\n}\n\nexport interface SegmentedMeterProps extends React.ComponentProps<\"div\"> {\n  value: number;\n  zones: MeterZone[];\n  /** Only color the zone that contains the value; others stay muted. */\n  highlightActive?: boolean;\n  /** Show zone boundary values under the bar. */\n  showTicks?: boolean;\n  /** Show zone labels under the bar. */\n  showLabels?: boolean;\n  /** Show a marker at the current value. */\n  showMarker?: boolean;\n  tickFormatter?: (value: number) => string;\n}\n\nfunction SegmentedMeter({\n  value,\n  zones,\n  highlightActive = true,\n  showTicks = true,\n  showLabels = false,\n  showMarker = true,\n  tickFormatter = (v) => formatNumber(v),\n  className,\n  style,\n  ...props\n}: SegmentedMeterProps) {\n  const ticksRef = React.useRef<HTMLDivElement>(null);\n  React.useLayoutEffect(() => {\n    const container = ticksRef.current;\n    if (!container || !showTicks) return;\n    const labels = Array.from(container.children) as HTMLElement[];\n    const measure = () => {\n      const last = labels.at(-1)?.getBoundingClientRect();\n      let right = -Infinity;\n      labels.forEach((label, index) => {\n        const rect = label.getBoundingClientRect();\n        const endpoint = index === 0 || index === labels.length - 1;\n        const fits =\n          rect.left >= right + 8 && (!last || rect.right + 8 <= last.left);\n        label.style.visibility = endpoint || fits ? \"visible\" : \"hidden\";\n        if (endpoint || fits) right = rect.right;\n      });\n    };\n    measure();\n    const observer = new ResizeObserver(measure);\n    observer.observe(container);\n    labels.forEach((label) => observer.observe(label));\n    return () => observer.disconnect();\n  }, [showTicks, zones, tickFormatter]);\n  const validZones = zones.filter(\n    (zone) =>\n      Number.isFinite(zone.from) &&\n      Number.isFinite(zone.to) &&\n      zone.to > zone.from,\n  );\n  if (!validZones.length) {\n    return (\n      <div\n        data-slot=\"segmented-meter\"\n        className={cn(\"flex flex-col gap-1.5\", className)}\n        style={style}\n        {...props}\n      >\n        <p className=\"text-sm text-muted-foreground\">No ranges available.</p>\n      </div>\n    );\n  }\n  const min = Math.min(...validZones.map((z) => z.from));\n  const max = Math.max(...validZones.map((z) => z.to));\n  const span = max - min || 1;\n  const current = Math.min(\n    max,\n    Math.max(min, Number.isFinite(value) ? value : min),\n  );\n  const position = (current - min) / span;\n  const activeIndex = validZones.findIndex(\n    (z, i) =>\n      current >= z.from &&\n      (current < z.to || (i === validZones.length - 1 && current <= z.to)),\n  );\n\n  const activeColor =\n    activeIndex >= 0\n      ? (validZones[activeIndex].color ?? \"var(--color-chart-1)\")\n      : \"var(--color-foreground)\";\n  const ease = \"ease-[cubic-bezier(0.22,1,0.36,1)]\";\n\n  return (\n    <div\n      data-slot=\"segmented-meter\"\n      role=\"meter\"\n      aria-valuemin={min}\n      aria-valuemax={max}\n      aria-valuenow={current}\n      aria-valuetext={\n        activeIndex >= 0 && validZones[activeIndex].label\n          ? `${tickFormatter(current)}, ${validZones[activeIndex].label}`\n          : undefined\n      }\n      className={cn(\"flex flex-col gap-2\", className)}\n      style={\n        {\n          ...style,\n          \"--meter-active\": activeColor,\n        } as React.CSSProperties\n      }\n      {...props}\n    >\n      <div className=\"relative\">\n        <div\n          data-slot=\"segmented-meter-track\"\n          className=\"flex h-2 w-full gap-[3px]\"\n        >\n          {validZones.map((zone, index) => {\n            const active = index === activeIndex;\n            const color = zone.color ?? \"var(--color-chart-1)\";\n            const lit = !highlightActive || active;\n            return (\n              <div\n                key={index}\n                data-slot=\"segmented-meter-zone\"\n                data-active={active}\n                className={cn(\n                  \"h-full min-w-0 origin-left rounded-full transition-[background,box-shadow,scale] duration-500 starting:scale-x-0 motion-reduce:transition-none\",\n                  ease,\n                  lit &&\n                    \"dark:shadow-[0_0_12px_-2px_color-mix(in_oklab,var(--zone-color)_70%,transparent)]\",\n                )}\n                style={\n                  {\n                    \"--zone-color\": color,\n                    width: `${((zone.to - zone.from) / span) * 100}%`,\n                    background: lit\n                      ? \"linear-gradient(90deg, color-mix(in oklab, var(--zone-color) 72%, transparent), var(--zone-color))\"\n                      : \"color-mix(in oklab, var(--zone-color) 16%, color-mix(in oklab, var(--color-foreground) 6%, transparent))\",\n                    transitionDelay: `${index * 50}ms`,\n                  } as React.CSSProperties\n                }\n              />\n            );\n          })}\n        </div>\n        {showMarker ? (\n          <div\n            aria-hidden=\"true\"\n            data-slot=\"segmented-meter-marker\"\n            className={cn(\n              \"absolute top-1/2 size-3.5 -translate-x-1/2 -translate-y-1/2 rounded-full border-[2.5px] border-(--meter-active) bg-card shadow-[0_0_0_3px_color-mix(in_oklab,var(--meter-active)_20%,transparent),0_1px_3px_rgb(0_0_0/0.18)] [transition:left_500ms_cubic-bezier(0.22,1,0.36,1),border-color_300ms,box-shadow_300ms,opacity_300ms_ease-out_250ms,scale_500ms_cubic-bezier(0.22,1,0.36,1)_250ms] starting:scale-50 starting:opacity-0 motion-reduce:transition-none dark:shadow-[0_0_0_3px_color-mix(in_oklab,var(--meter-active)_26%,transparent),0_0_12px_color-mix(in_oklab,var(--meter-active)_60%,transparent)]\",\n            )}\n            style={{ left: `${position * 100}%` }}\n          />\n        ) : null}\n      </div>\n      {showTicks || showLabels ? (\n        <div\n          ref={ticksRef}\n          data-slot=\"segmented-meter-scale\"\n          className=\"relative h-4 text-[11px] leading-4 text-muted-foreground tabular-nums\"\n        >\n          {showTicks\n            ? [min, ...validZones.map((z) => z.to)].map((tick, index, all) => (\n                <span\n                  key={index}\n                  className={cn(\n                    \"absolute top-0 whitespace-nowrap\",\n                    index === 0 && \"left-0\",\n                    index === all.length - 1 && \"right-0\",\n                    index > 0 && index < all.length - 1 && \"-translate-x-1/2\",\n                  )}\n                  style={\n                    index > 0 && index < all.length - 1\n                      ? { left: `${((tick - min) / span) * 100}%` }\n                      : undefined\n                  }\n                >\n                  {tickFormatter(tick)}\n                </span>\n              ))\n            : validZones.map((zone, index) => (\n                <span\n                  key={index}\n                  data-active={index === activeIndex}\n                  className=\"absolute top-0 max-w-[40%] -translate-x-1/2 truncate transition-colors duration-300 data-[active=true]:font-medium data-[active=true]:text-foreground\"\n                  style={{\n                    left: `${(((zone.from + zone.to) / 2 - min) / span) * 100}%`,\n                  }}\n                >\n                  {zone.label}\n                </span>\n              ))}\n        </div>\n      ) : null}\n    </div>\n  );\n}\n\nexport { SegmentedMeter };\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/segmented-meter. Requires an initialized shadcn/ui project with Tailwind CSS v4."
}
