{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "meter-quota-rule",
  "title": "Meter Quota Rule",
  "description": "A quota meter with no bar, no fill, no pill: the printed reading ('38.2 GB of 100 GB') sits above a 4px hairline whose used portion is solid and remainder is dashed, a fixed tick marks the warning threshold, and crossing it thickens the rule and bolds the digits instead of turning anything red.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/core/meter-quota-rule/component.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useId, useRef, useState } from \"react\";\n\n// ---------------------------------------------------------------------------\n// RationRule — a quota meter with no bar, no fill, no pill: just the printed\n// reading ('38.2 GB of 100 GB') sitting directly above a 4px-tall hairline.\n// The rule itself IS the meter — its used portion is a solid --foreground\n// stroke, its remainder a dashed --border stroke (2 3), and the boundary\n// between them eases with the value. A fixed tick marks the warning\n// threshold in --warning, never on the fill; crossing it doesn't turn\n// anything red, it thickens the solid stroke 1px -> 2px and steps the\n// numerals from weight 400 to 600 — the line asserts itself instead of\n// alarming. Meant to sit dozens-deep on a settings page (storage, seats,\n// API credits, budget) at text scale. Pure inline SVG + CSS, no canvas.\n// ---------------------------------------------------------------------------\n\nexport interface RationRuleProps {\n  /** what's being rationed, e.g. \"Storage\" — shown as a caption and used as the meter's accessible name */\n  label: string;\n  /** amount currently used */\n  value: number;\n  /** total allowance */\n  max: number;\n  /** short unit printed after both numbers, e.g. \"GB\" */\n  unit: string;\n  /** full unit word spoken by aria-valuetext, e.g. \"gigabytes\" — defaults to `unit` */\n  unitLabel?: string;\n  /** fraction of max (0-1) at which the rule crosses into warning weight */\n  warning?: number;\n  /** extra classes merged onto the rendered root element */\n  className?: string;\n}\n\nconst VIEW_W = 400;\nconst VIEW_H = 6;\nconst RULE_Y = VIEW_H / 2;\nconst MOVE_MS = 350;\n\nfunction easeOutExpo(t: number) {\n  return t >= 1 ? 1 : 1 - Math.pow(2, -10 * t);\n}\n\nfunction fmt(n: number) {\n  if (!Number.isFinite(n)) return \"0\";\n  const rounded = Math.round(n * 10) / 10;\n  return Number.isInteger(rounded) ? String(rounded) : rounded.toFixed(1);\n}\n\nfunction clamp01(n: number) {\n  if (Number.isNaN(n)) return 0;\n  return Math.min(1, Math.max(0, n));\n}\n\nfunction useReducedMotion() {\n  const [reduced, setReduced] = useState(false);\n  useEffect(() => {\n    const mq = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    setReduced(mq.matches);\n    const onChange = () => setReduced(mq.matches);\n    mq.addEventListener(\"change\", onChange);\n    return () => mq.removeEventListener(\"change\", onChange);\n  }, []);\n  return reduced;\n}\n\n// eases `target` toward its resting value over `duration`ms with\n// ease-out-expo, cleanly retargeting mid-flight from whatever the display\n// value currently is. Snaps instantly when `reduced`.\nfunction useEasedFraction(target: number, duration: number, reduced: boolean) {\n  const [display, setDisplay] = useState(target);\n  const displayRef = useRef(target);\n  const fromRef = useRef(target);\n  const toRef = useRef(target);\n  const startRef = useRef(0);\n  const rafRef = useRef<number | null>(null);\n\n  useEffect(() => {\n    if (reduced) {\n      if (rafRef.current !== null) cancelAnimationFrame(rafRef.current);\n      rafRef.current = null;\n      displayRef.current = target;\n      fromRef.current = target;\n      toRef.current = target;\n      setDisplay(target);\n      return;\n    }\n    if (target === toRef.current) return;\n    fromRef.current = displayRef.current;\n    toRef.current = target;\n    startRef.current = performance.now();\n    if (rafRef.current !== null) cancelAnimationFrame(rafRef.current);\n\n    const tick = (now: number) => {\n      const t = Math.min(1, (now - startRef.current) / duration);\n      const eased = easeOutExpo(t);\n      const next = fromRef.current + (toRef.current - fromRef.current) * eased;\n      displayRef.current = next;\n      setDisplay(next);\n      rafRef.current = t < 1 ? requestAnimationFrame(tick) : null;\n    };\n    rafRef.current = requestAnimationFrame(tick);\n    return () => {\n      if (rafRef.current !== null) cancelAnimationFrame(rafRef.current);\n    };\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [target, duration, reduced]);\n\n  return display;\n}\n\nexport function RationRule({\n  label,\n  value,\n  max,\n  unit,\n  unitLabel,\n  warning = 0.8,\n  className = \"\",\n}: RationRuleProps) {\n  const uid = useId();\n  const reduced = useReducedMotion();\n\n  const safeMax = max > 0 ? max : 1e-6;\n  const targetFraction = clamp01(value / safeMax);\n  const warningFraction = clamp01(warning);\n\n  const displayFraction = useEasedFraction(targetFraction, MOVE_MS, reduced);\n\n  // final rest-state crossing drives ARIA (never mid-animation dependent);\n  // the visual stroke width/weight track the live animated position, so the\n  // thickening visibly happens AT the tick as the boundary sweeps past it.\n  const crossedFinal = targetFraction >= warningFraction;\n  const crossedLive = displayFraction >= warningFraction;\n\n  const boundaryX = displayFraction * VIEW_W;\n  const tickX = warningFraction * VIEW_W;\n\n  const usedText = fmt(value);\n  const maxText = fmt(max);\n  const resolvedUnitLabel = unitLabel || unit;\n  const stateText = crossedFinal\n    ? \"at or above warning threshold\"\n    : \"below warning threshold\";\n  const valueText =\n    `${usedText} of ${maxText} ${resolvedUnitLabel}, ${stateText}`.replace(\n      /\\s+/g,\n      \" \"\n    );\n\n  const labelId = `${uid}-label`;\n\n  return (\n    <div className={className}>\n      <style>{`\n.ns-ration-solid{transition:stroke-width 200ms cubic-bezier(0.22,1,0.36,1)}\n.ns-ration-weight{transition:font-weight 200ms cubic-bezier(0.22,1,0.36,1)}\n@media (prefers-reduced-motion: reduce){\n  .ns-ration-solid{transition:none}\n  .ns-ration-weight{transition:none}\n}\n`}</style>\n\n      <span id={labelId} className=\"block font-mono text-[11px] tracking-wide text-ns-muted\">\n        {label.toUpperCase()}\n      </span>\n\n      <p\n        className={\n          \"ns-ration-weight mt-1 text-sm tabular-nums text-foreground \" +\n          (crossedLive ? \"font-semibold\" : \"font-normal\")\n        }\n      >\n        {usedText} {unit}{\" \"}\n        <span className=\"text-ns-muted\">\n          of {maxText} {unit}\n        </span>\n      </p>\n\n      <div\n        role=\"meter\"\n        aria-labelledby={labelId}\n        aria-valuemin={0}\n        aria-valuemax={max}\n        aria-valuenow={value}\n        aria-valuetext={valueText}\n        className=\"mt-1.5\"\n      >\n        <svg\n          viewBox={`0 0 ${VIEW_W} ${VIEW_H}`}\n          preserveAspectRatio=\"none\"\n          className=\"block h-1.5 w-full\"\n          aria-hidden\n          focusable=\"false\"\n        >\n          <line\n            x1={boundaryX}\n            y1={RULE_Y}\n            x2={VIEW_W}\n            y2={RULE_Y}\n            vectorEffect=\"non-scaling-stroke\"\n            strokeWidth={1}\n            strokeDasharray=\"2 3\"\n            strokeLinecap=\"butt\"\n            className=\"stroke-current text-border\"\n          />\n          <line\n            x1={0}\n            y1={RULE_Y}\n            x2={boundaryX}\n            y2={RULE_Y}\n            vectorEffect=\"non-scaling-stroke\"\n            strokeWidth={crossedLive ? 2 : 1}\n            strokeLinecap=\"butt\"\n            className=\"ns-ration-solid stroke-current text-foreground\"\n          />\n          <line\n            x1={tickX}\n            y1={0}\n            x2={tickX}\n            y2={VIEW_H}\n            vectorEffect=\"non-scaling-stroke\"\n            strokeWidth={1}\n            style={{ stroke: \"var(--warning, #f5a623)\" }}\n          />\n        </svg>\n      </div>\n\n      <p role=\"status\" aria-live=\"polite\" className=\"sr-only\">\n        {valueText}\n      </p>\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "components/ui/meter-quota-rule.tsx"
    }
  ],
  "cssVars": {
    "theme": {
      "color-ns-muted": "var(--ns-muted)"
    },
    "light": {
      "ns-muted": "#4d4d4d",
      "warning": "#7a5200"
    },
    "dark": {
      "ns-muted": "#8f8f8f",
      "warning": "#f5a623"
    }
  },
  "meta": {
    "collection": "core",
    "tags": [
      "meter",
      "quota",
      "usage",
      "typography",
      "svg",
      "status",
      "accessibility",
      "settings"
    ],
    "instruction": "Renders one quota — a live `value` against a `max`, both in `unit` — as nothing but its own printed reading sitting above a ruled hairline, with no bar, fill, or pill anywhere. Above the rule: a small mono `label` caption (e.g. 'STORAGE') and, directly under it, the composed readout '38.2 GB of 100 GB' in tabular-nums text, the used number and unit in full ink and the 'of X unit' remainder in --ns-muted. Below that: a single inline SVG line 4px tall (viewBox 0 0 400 6, preserveAspectRatio=none, every stroke `vector-effect=non-scaling-stroke` so widths stay literal px regardless of the container's rendered width) drawn as three overlaid `<line>` elements sharing one horizontal axis: a dashed line from the used/remaining boundary to the far end, --border ink, `stroke-dasharray=\"2 3\"`, representing the unused allowance; a solid line from 0 to that same boundary, --foreground ink, representing the used allowance, painted on top of the dashed line's origin so the seam never gapes; and a fixed vertical tick at the warning fraction (default 0.8 of max, overridable via `warning`), stroked in `var(--warning, #f5a623)` and nothing else in the whole component ever touches that token — the fill is always --foreground/--border, never colored by state, matching the rule that --warning marks a threshold, it doesn't recolor a value. On every `value`/`max` change the used/unused boundary — the shared x-coordinate the solid line ends at and the dashed line begins at — eases to its new position with a hand-rolled requestAnimationFrame tween (no dependency), ease-out-expo shaped (`1 - 2^(-10t)`), 350ms, cleanly retargetable mid-flight if a new value lands before the previous animation settles. Crossing the tick is the entire state change and it is never carried by color: as the animated boundary sweeps past the tick's x-position, the solid stroke's `stroke-width` steps 1px -> 2px (itself CSS-transitioned over 200ms) and the printed numerals' `font-weight` steps 400 -> 600 in the same beat — the rule visibly thickens and the digits visibly firm up exactly as the boundary crosses the mark, then holds that state at rest; nothing turns red, nothing recolors, the line just asserts itself harder ('clears its throat'). The rest-state crossing test (used for ARIA and for which side of the 400/600 step the component settles on) is computed from the true `value`/`max` props directly, decoupled from the animation's current frame, so assistive tech never races a mid-flight visual. Structurally the meter is `role=meter` on the wrapper around the SVG, `aria-labelledby` pointing at the visible label span, `aria-valuemin=0`, `aria-valuemax` = max, `aria-valuenow` = value, and `aria-valuetext` spelling the same reading in full words with the crossing state named explicitly — e.g. '38.2 of 100 gigabytes, below warning threshold' or '19 of 20 seats, at or above warning threshold' — built from an optional `unitLabel` prop (falls back to the short `unit` if omitted) so the short glyph used in the printed row ('GB') and the spoken word used by ARIA ('gigabytes') can differ. The SVG itself is `aria-hidden` — decorative once the meter node and the always-visible printed text carry the real reading — and a visually-hidden `role=status`/`aria-live=polite` paragraph mirrors the same `aria-valuetext` so a value change announces without needing focus, matching the printed text as the primary reading for sighted and screen-reader users alike. The component is non-interactive by design: no button, no input, no keyboard surface, nothing for Tab to reach, and it is correctly exempt from the registry's tab-reachability check as a display-only meter. Under `prefers-reduced-motion` (checked via `matchMedia` with a change listener) the boundary tween is skipped entirely — value changes apply their new resting position in a single frame — and the stroke-width/font-weight CSS transitions are stripped via a matching media-query block, so the crossing state is still fully legible, just instant rather than swept. Every ink comes from `stroke-current`/`text-*` token classes (--foreground, --border, --ns-muted) except the tick, which is the one and only place `var(--warning, #f5a623)` appears, exactly per the semantic-color rule that warning marks a threshold marker, never a fill. Differs from sparkline-automaton, which threads a whole SERIES of points into a typographic rule as a KPI sparkline with history and a Wolfram-rule cellular-automaton texture; meter-quota-rule carries no history and no trend at all — it is a single static fraction-of-allowance, legible instantly because the numbers are always printed, meant to appear dozens of times on one settings page (storage, seats, API credits, budget) at plain text scale rather than as a hero chart.",
    "rank": 279
  },
  "type": "registry:ui"
}