{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "meter",
  "title": "Usage meter",
  "description": "Labeled usage meter like \"SMS credits 7,420 / 10,000\" whose fill springs to the new value and shifts to amber and rose near the limit, with optional per-seat segments.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json",
    "https://goodui.dev/r/locale.json",
    "https://goodui.dev/r/number-flow.json"
  ],
  "files": [
    {
      "path": "registry/components/numbers/meter.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { motion, useReducedMotion } from \"motion/react\"\nimport { cn } from \"@/lib/utils\"\nimport { useGooduiLocale, useLabels } from \"@/lib/goodui-locale\"\nimport { NumberFlow } from \"@/components/goodui/number-flow\"\nimport { spring as springs } from \"@/lib/goodui-motion\"\n\nexport type MeterTone = \"normal\" | \"warning\" | \"danger\"\n\nexport type MeterProps = Omit<React.ComponentProps<\"div\">, \"children\"> & {\n  /** Name shown above the bar and used as the meter's accessible name, e.g. \"SMS credits\". */\n  label: React.ReactNode\n  /** Amount used. It rolls with NumberFlow and the fill springs to it; it is clamped between 0 and max for the bar. */\n  value: number\n  /** Limit the value is measured against, e.g. 10000 credits. */\n  max: number\n  /** Formats value and max, e.g. { maximumFractionDigits: 1 }. */\n  format?: Intl.NumberFormatOptions\n  /** Locale passed to Intl.NumberFormat for value and max. Defaults to the GooduiLocaleProvider language, else en-US. */\n  locale?: string\n  /** Text after the numbers, e.g. \" GB\". */\n  unit?: string\n  /** Share of max (0 to 1) where the bar turns amber. */\n  warnAt?: number\n  /** Share of max (0 to 1) where the bar turns rose. */\n  dangerAt?: number\n  /** Split the bar into this many segments, e.g. one per seat. */\n  segments?: number\n  /** Small line under the bar. Receives the current tone and percentage. */\n  hint?: React.ReactNode | ((state: { tone: MeterTone; percent: number }) => React.ReactNode)\n  /** Bar height: sm 6px, md 8px, lg 12px. */\n  size?: \"sm\" | \"md\" | \"lg\"\n  /** Text for built-in controls and screen readers; pass translations here. */\n  labels?: Partial<MeterLabels>\n}\n\n/** aria-valuetext of the meter. value and max arrive formatted (max with the unit). */\nexport type MeterLabels = { valueText: (value: string, max: string, percent: number) => string }\nconst DEFAULT_LABELS: MeterLabels = { valueText: (value, max, percent) => `${value} of ${max}, ${percent}%` }\n\nconst FILL: Record<MeterTone, string> = {\n  normal: \"bg-primary\",\n  warning: \"bg-amber-500 dark:bg-amber-400\",\n  danger: \"bg-rose-500 dark:bg-rose-400\",\n}\nconst TEXT: Record<MeterTone, string> = {\n  normal: \"text-muted-foreground\",\n  warning: \"text-amber-700 dark:text-amber-400\",\n  danger: \"text-rose-700 dark:text-rose-400\",\n}\nconst HEIGHT = { sm: \"h-1.5\", md: \"h-2\", lg: \"h-3\" }\n\n/** Usage meter: the fill springs to the new value and shifts to amber and rose as it nears the limit. */\nexport function Meter({\n  label,\n  value,\n  max,\n  format,\n  locale: localeProp,\n  unit = \"\",\n  warnAt = 0.75,\n  dangerAt = 0.9,\n  segments,\n  hint,\n  size = \"md\",\n  labels,\n  className,\n  ...props\n}: MeterProps) {\n  const l = useLabels(\"meter\", DEFAULT_LABELS, labels)\n  const { lang } = useGooduiLocale()\n  const locale = localeProp ?? lang\n  const reduce = useReducedMotion() ?? false\n  const ratio = max > 0 ? Math.min(Math.max(value / max, 0), 1) : 0\n  const tone: MeterTone = ratio >= dangerAt ? \"danger\" : ratio >= warnAt ? \"warning\" : \"normal\"\n  const percent = Math.round(ratio * 100)\n  const spring = reduce ? { duration: 0 } : springs.morph\n  const formatter = React.useMemo(() => new Intl.NumberFormat(locale, format), [locale, format])\n  const id = React.useId()\n\n  const count = segments && segments > 1 ? Math.round(segments) : 1\n  const filled = ratio * count\n\n  return (\n    <div className={cn(\"w-full\", className)} {...props}>\n      <div className=\"mb-2 flex items-baseline justify-between gap-3 text-sm\">\n        <span id={id} className=\"truncate font-medium\">\n          {label}\n        </span>\n        <span className=\"flex shrink-0 items-end tabular-nums text-muted-foreground\">\n          <NumberFlow value={value} format={format} locale={locale} className=\"font-medium text-foreground\" />\n          <span aria-hidden=\"true\" className=\"leading-[1.15em] whitespace-pre\">\n            {\" / \"}\n            {formatter.format(max)}\n            {unit}\n          </span>\n        </span>\n      </div>\n      <div\n        role=\"meter\"\n        aria-labelledby={id}\n        aria-valuemin={0}\n        aria-valuemax={max}\n        aria-valuenow={Math.min(value, max)}\n        aria-valuetext={l.valueText(formatter.format(value), `${formatter.format(max)}${unit}`, percent)}\n        className={cn(\"flex w-full gap-1\", HEIGHT[size])}\n      >\n        {Array.from({ length: count }, (_, i) => {\n          const part = Math.min(Math.max(filled - i, 0), 1)\n          return (\n            // Mirrored under RTL so each segment fills from the inline start.\n            <div key={i} className=\"relative h-full flex-1 overflow-hidden rounded-full bg-muted rtl:-scale-x-100\">\n              <motion.div\n                className={cn(\"absolute inset-0 rounded-full transition-colors duration-500\", FILL[tone])}\n                initial={{ x: \"-100%\" }}\n                // Fading out at 0 hides the 1px sliver that sub-pixel rounding can leave at the track edge.\n                animate={{ x: `${(part - 1) * 100}%`, opacity: part > 0 ? 1 : 0 }}\n                transition={\n                  reduce\n                    ? spring\n                    : { ...spring, delay: count > 1 ? i * 0.025 : 0, opacity: { duration: 0.15, delay: part > 0 ? 0 : 0.3 } }\n                }\n              />\n            </div>\n          )\n        })}\n      </div>\n      {hint !== undefined && (\n        <div className={cn(\"mt-1.5 text-xs transition-colors duration-500\", TEXT[tone])}>\n          {typeof hint === \"function\" ? hint({ tone, percent }) : hint}\n        </div>\n      )}\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/meter.tsx"
    }
  ],
  "categories": [
    "components",
    "numbers"
  ],
  "type": "registry:component"
}
