{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "range-select",
  "type": "registry:component",
  "title": "Year range",
  "description": "Pick a range from a few set values, such as model years.",
  "author": "Eugen Eşanu <https://eugenesanu.com>",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "registryDependencies": [
    "https://filtersui.com/r/select.json"
  ],
  "files": [
    {
      "path": "registry/filters/range-select.tsx",
      "type": "registry:component",
      "target": "@components/filters-ui/filters/range-select.tsx",
      "content": "\"use client\";\n\nimport type { HTMLAttributes } from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { formatsFor } from \"../lib/format\";\nimport { RangeChart, type RangeValue } from \"../ui/range-chart\";\nimport { Select } from \"../ui/select\";\nimport { StatusFrame, type StateProps } from \"../ui/status-frame\";\n\nexport type RangeSelectProps<V extends number> = Omit<HTMLAttributes<HTMLDivElement>, \"onChange\" | \"defaultValue\"> &\n  Omit<StateProps, \"emptyText\"> & {\n  /** The values to pick from, in ascending order, e.g. model years. One bar each. */\n  options: readonly V[];\n  /** [from, to], both inclusive. null is an open end. */\n  value: [V | null, V | null];\n  onChange: (value: [V | null, V | null]) => void;\n  /** Item count per option, in the order of `options`. */\n  buckets?: readonly number[];\n  /** Picker, tooltip and screen-reader text for a value. Default: the number with no group marks, in the locale's digits. */\n  format?: (value: V) => string;\n  /** Picker order. Default \"ascending\"; \"descending\" puts the newest year first. */\n  pickerOrder?: \"ascending\" | \"descending\";\n  /** The open-end choice in both pickers. Default \"Any\". */\n  anyLabel?: string;\n  /** Visible picker prefixes. Default \"From\" and \"To\". */\n  prefixes?: { low?: string; high?: string };\n  /** Accessible names of the handles and pickers. Default: the prefixes. Keep the prefix word in them. */\n  labels?: { low?: string; high?: string };\n  /** Screen-reader words for a count in the pickers, e.g. \"6 cars\". Default \"6 results\". */\n  countLabel?: (n: number) => string;\n  /** Bar width as a share of its slot, so a chart with few bars can keep the rhythm of a denser one. Default 1. */\n  barScale?: number;\n  /** Formats values and counts by default, e.g. \"ar-EG\". Default \"en-US\". */\n  locale?: string;\n};\n\nconst ANY = \"\";\n\n/**\n * A range over a few discrete values: a bar chart with two handles and From and To pickers under it, kept in step\n * both ways. With buckets, each picker choice shows how many items picking it would give. Handles sit between bars, so the two may hold a single value. Picking From past To moves To along\n * to the same value, and picking To before From moves From back: the pick always wins.\n */\nexport function RangeSelect<V extends number>({\n  options,\n  value,\n  onChange,\n  buckets,\n  format: formatProp,\n  pickerOrder = \"ascending\",\n  anyLabel = \"Any\",\n  prefixes,\n  labels,\n  countLabel,\n  barScale,\n  locale,\n  status = \"ready\",\n  onRetry,\n  errorText = \"Couldn't load the counts.\",\n  disabled = false,\n  className,\n  ...props\n}: RangeSelectProps<V>) {\n  const format = formatProp ?? formatsFor(locale).plain;\n  const n = options.length;\n  const lowPrefix = prefixes?.low ?? \"From\";\n  const highPrefix = prefixes?.high ?? \"To\";\n  const lowLabel = labels?.low ?? lowPrefix;\n  const highLabel = labels?.high ?? highPrefix;\n\n  // The chart runs over bar edges 0..n: From at edge i is options[i]; To at edge j is options[j - 1].\n  const indexOf = (v: V) => {\n    const at = options.findIndex((option) => option >= v);\n    return at < 0 ? n - 1 : at;\n  };\n  const edges: RangeValue = [value[0] === null ? null : indexOf(value[0]), value[1] === null ? null : indexOf(value[1]) + 1];\n\n  // The oldest From and the newest To exclude nothing, so they are the open ends.\n  const emit = ([low, high]: [V | null, V | null]) => {\n    const next: [V | null, V | null] = [low === options[0] ? null : low, high === options[n - 1] ? null : high];\n    if (next[0] !== value[0] || next[1] !== value[1]) onChange(next);\n  };\n\n  const fromEdges = ([low, high]: RangeValue) =>\n    emit([low === null ? null : options[low], high === null ? null : options[high - 1]]);\n\n  // With buckets, each choice counts what picking it would give, the other end included; a choice past the other end\n  // moves it along, as the pick does.\n  const within = (low: V | null, high: V | null) =>\n    buckets ? options.reduce((sum, option, i) => ((low === null || option >= low) && (high === null || option <= high) ? sum + (buckets[i] ?? 0) : sum), 0) : undefined;\n  const choicesFor = (end: \"low\" | \"high\") => [\n    { value: ANY, label: anyLabel, count: end === \"low\" ? within(null, value[1]) : within(value[0], null) },\n    ...(pickerOrder === \"descending\" ? [...options].reverse() : options).map((option) => ({\n      value: String(option),\n      label: format(option),\n      count:\n        end === \"low\"\n          ? within(option, value[1] !== null && value[1] < option ? option : value[1])\n          : within(value[0] !== null && value[0] > option ? option : value[0], option),\n    })),\n  ];\n  const read = (text: string) => (text === ANY ? null : (options.find((option) => String(option) === text) ?? null));\n\n  // The frame dims and blocks everything while disabled, so the chart and pickers are not dimmed a second time.\n  return (\n    <div className={cn(\"pt-1\", className)} {...props}>\n      <StatusFrame status={status} onRetry={onRetry} errorText={errorText} disabled={disabled}>\n        <RangeChart\n          min={0}\n          max={n}\n          step={1}\n          value={edges}\n          onChange={fromEdges}\n          buckets={buckets}\n          format={(edge, handle) => format(options[Math.max(0, Math.min(n - 1, handle === \"low\" ? edge : edge - 1))])}\n          openLabel={format(options[n - 1])}\n          labels={{ low: lowLabel, high: highLabel }}\n          barScale={barScale}\n          locale={locale}\n        />\n        <div className=\"mt-3 grid grid-cols-[repeat(auto-fit,minmax(min(100%,7rem),1fr))] gap-2\">\n          <Select\n            label={lowLabel}\n            prefix={lowPrefix}\n            options={choicesFor(\"low\")}\n            countLabel={countLabel}\n            locale={locale}\n            value={value[0] === null ? ANY : String(value[0])}\n            onChange={(text) => {\n              const low = read(text);\n              emit([low, low !== null && value[1] !== null && value[1] < low ? low : value[1]]);\n            }}\n          />\n          <Select\n            label={highLabel}\n            prefix={highPrefix}\n            options={choicesFor(\"high\")}\n            countLabel={countLabel}\n            locale={locale}\n            value={value[1] === null ? ANY : String(value[1])}\n            onChange={(text) => {\n              const high = read(text);\n              emit([high !== null && value[0] !== null && value[0] > high ? high : value[0], high]);\n            }}\n          />\n        </div>\n      </StatusFrame>\n    </div>\n  );\n}\n"
    },
    {
      "path": "registry/ui/range-chart.tsx",
      "type": "registry:ui",
      "target": "@components/filters-ui/ui/range-chart.tsx",
      "content": "\"use client\";\n\nimport { useLayoutEffect, useRef, useState, type CSSProperties, type HTMLAttributes, type PointerEvent, type ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { isRtl, readingKey } from \"../lib/direction\";\nimport { formatsFor } from \"../lib/format\";\nimport { EmptyNote } from \"./empty-note\";\nimport { SKELETON_FILL, useLoading } from \"./skeleton\";\n\n/** [low, high]. null is an open end: no lower or no upper limit. */\nexport type RangeValue = [number | null, number | null];\n\ntype Handle = \"low\" | \"high\";\n\nexport type RangeChartProps = Omit<HTMLAttributes<HTMLDivElement>, \"onChange\" | \"defaultValue\"> & {\n  min: number;\n  max: number;\n  step: number;\n  value: RangeValue;\n  onChange: (value: RangeValue) => void;\n  /** Item count per bar, spread evenly from min to max. Leave out for a plain slider. */\n  buckets?: readonly number[];\n  /** Tooltip and screen-reader text for a value. Gets the handle too, for scales where the high handle reads one step back. */\n  format?: (value: number, handle: \"low\" | \"high\") => string;\n  /** Tooltip text while the high end is open. Default: the top value and a plus (\"$100,000+\"). */\n  openLabel?: string;\n  /** One handle, for an upper limit only. The low end of `value` is ignored; the handle stops one step above min. */\n  single?: boolean;\n  /** Accessible names of the handles. */\n  labels?: { low?: string; high?: string };\n  /** Bar width as a share of its slot, so a chart with few bars can keep the rhythm of a denser one. Default 1. */\n  barScale?: number;\n  /**\n   * A handle that something outside the chart is dragging, a field of its own say, with the value under its pointer.\n   * The chart draws that handle there and raises the bars it passes, as in a drag of its own, without the tooltip.\n   */\n  held?: { handle: \"low\" | \"high\"; value: number } | null;\n  /** Formats values when no format is given, e.g. \"de-DE\". */\n  locale?: string;\n  disabled?: boolean;\n  /**\n   * Draws pulsing columns in a calm hill and a pulsing rail, with no handles, in the space the chart takes.\n   * Default: the nearest StatusFrame's loading state.\n   */\n  loading?: boolean;\n  /** Shown, quiet, in the bars' place when buckets is an empty list. Default \"No items to show\" */\n  emptyText?: ReactNode;\n};\n\nconst HANDLE = 20;\n/** Columns a loading chart draws when it has no buckets yet. */\nconst PLACEHOLDER_BARS = 20;\n\n/** A loading column's height in percent: a soft hill, highest a third of the way along, as many prices are. */\nexport const hillAt = (i: number, n: number) => {\n  const x = (i + 0.5) / n;\n  return Math.round(18 + 64 * Math.exp(-(((x - 0.38) / 0.24) ** 2)));\n};\n// A press on a handle becomes a drag only after it travels this far, so a click does not show the tooltip.\nconst DRAG_FROM = 3;\n\nconst clamp = (value: number, low: number, high: number) => Math.min(high, Math.max(low, value));\n\n// A handle stops at the end of the track, so the bars, the fill and the tooltip share the handle's travel.\nconst along = (fraction: number) => `calc(${HANDLE / 2}px + (100% - ${HANDLE}px) * ${fraction})`;\n\ntype Drag = { handle: Handle; fraction: number; moving: boolean };\n\n/**\n * A bar chart of how many items sit along a range, with one or two handles on a track under it.\n * Each handle is backed by a visually hidden native range input for keyboards and screen readers. Right to left, the\n * scale runs from the right: the minimum sits at the right end and the Left arrow raises a value.\n */\nexport function RangeChart({\n  min,\n  max,\n  step,\n  value,\n  onChange,\n  buckets,\n  format: formatProp,\n  openLabel,\n  single = false,\n  labels,\n  barScale = 1,\n  held,\n  locale,\n  disabled = false,\n  loading: loadingProp,\n  emptyText = \"No items to show\",\n  className,\n  ...props\n}: RangeChartProps) {\n  const status = useLoading();\n  const loading = loadingProp ?? status.loading;\n  const format: (value: number, handle: Handle) => string = formatProp ?? formatsFor(locale).number;\n  const root = useRef<HTMLDivElement>(null);\n  const tip = useRef<HTMLSpanElement>(null);\n  const grip = useRef<{ x: number; shift: number; handle: Handle; stacked: boolean; box: DOMRect } | null>(null);\n  const pressed = useRef(false);\n  const [drag, setDrag] = useState<Drag | null>(null);\n  const [lastHeld, setLastHeld] = useState<Handle>(\"high\");\n  const [tipHalf, setTipHalf] = useState(0);\n\n  const span = max - min || 1;\n  const snap = (v: number) => clamp(min + Math.round((v - min) / step) * step, min, max);\n  const low = single ? min : clamp(value[0] ?? min, min, max);\n  const high = clamp(value[1] ?? max, Math.min(low + step, max), max);\n  const values = { low, high };\n  const fractionOf = (v: number) => (v - min) / span;\n  const stepFraction = step / span;\n\n  const emit = (nextLow: number, nextHigh: number) => {\n    const next: RangeValue = [single || nextLow <= min ? null : nextLow, nextHigh >= max ? null : nextHigh];\n    if (next[0] !== value[0] || next[1] !== value[1]) onChange(next);\n  };\n\n  // Handles never cross: each stops one step short of the other. Returns where the handle landed.\n  const moveTo = (handle: Handle, v: number) => {\n    if (handle === \"low\") {\n      const next = Math.min(snap(v), high - step);\n      emit(next, high);\n      return next;\n    }\n    const next = Math.max(snap(v), low + step);\n    emit(low, next);\n    return next;\n  };\n\n  // A drag passes the box it measured at press, so moves do not force a layout read each event.\n  const fractionAt = (clientX: number, box = root.current?.getBoundingClientRect()) => {\n    if (!box) return 0;\n    const fromStart = isRtl(root.current) ? box.right - clientX : clientX - box.left;\n    return clamp((fromStart - HANDLE / 2) / (box.width - HANDLE), 0, 1);\n  };\n\n  // Where each handle is drawn: a dragged one sits under the pointer, the other at its value. A handle held from\n  // outside is drawn the same way.\n  const pulled = !drag && held ? { handle: held.handle, fraction: clamp(fractionOf(held.value), 0, 1) } : null;\n  const shown = { low: fractionOf(low), high: fractionOf(high) };\n  if (drag) shown[drag.handle] = drag.fraction;\n  else if (pulled) shown[pulled.handle] = pulled.fraction;\n\n  const nearest = (v: number): Handle => {\n    if (single || v > high) return \"high\";\n    if (v < low) return \"low\";\n    return v - low < high - v ? \"low\" : \"high\";\n  };\n\n  // A press on a bar gives the nearest handle that bar's outer edge, so the bar stays in the range.\n  // A press on the rail moves the nearest handle to the step under the pointer.\n  const land = (clientX: number, onBar: boolean) => {\n    const at = min + fractionAt(clientX) * span;\n    if (onBar && buckets?.length) {\n      const size = span / buckets.length;\n      const bar = clamp(Math.floor((at - min) / size), 0, buckets.length - 1);\n      const handle = nearest(min + (bar + 0.5) * size);\n      return { handle, value: moveTo(handle, min + (handle === \"low\" ? bar : bar + 1) * size) };\n    }\n    const handle = nearest(at);\n    return { handle, value: moveTo(handle, at) };\n  };\n\n  const press = (event: PointerEvent<HTMLDivElement>) => {\n    pressed.current = false;\n    if (disabled || event.button !== 0) return;\n    const target = event.target as HTMLElement;\n    const handle = target.closest<HTMLElement>(\"[data-handle]\")?.dataset.handle as Handle | undefined;\n    // A finger landing off a handle may be starting a scroll, so a tap waits for its click.\n    if (!handle && event.pointerType === \"touch\") return;\n    event.preventDefault();\n    pressed.current = true;\n    try {\n      event.currentTarget.setPointerCapture(event.pointerId);\n    } catch {}\n    const box = event.currentTarget.getBoundingClientRect();\n    const landed = handle ? null : land(event.clientX, !!target.closest(\"[data-bars]\"));\n    const held = handle ?? landed!.handle;\n    const startFraction = fractionOf(handle ? values[handle] : landed!.value);\n    // Handles one step apart overlap, so the first move picks which one is pulled out of the stack.\n    const stacked = !!handle && !single && high - low <= step;\n    grip.current = { x: event.clientX, shift: startFraction - fractionAt(event.clientX, box), handle: held, stacked, box };\n    setLastHeld(held);\n    setDrag({ handle: held, fraction: startFraction, moving: false });\n    (root.current?.querySelector(`input[data-for=\"${held}\"]`) as HTMLInputElement | null)?.focus({ preventScroll: true });\n  };\n\n  const follow = (event: PointerEvent<HTMLDivElement>) => {\n    const g = grip.current;\n    if (!g || !drag) return;\n    if (!drag.moving && Math.abs(event.clientX - g.x) < DRAG_FROM) return;\n    if (g.stacked) {\n      const pulled: Handle = event.clientX < g.x !== isRtl(root.current) ? \"low\" : \"high\";\n      g.stacked = false;\n      if (pulled !== g.handle) {\n        g.shift += fractionOf(values[pulled]) - fractionOf(values[g.handle]);\n        g.handle = pulled;\n        setLastHeld(pulled);\n        (root.current?.querySelector(`input[data-for=\"${pulled}\"]`) as HTMLInputElement | null)?.focus({ preventScroll: true });\n      }\n    }\n    const [floor, ceiling] =\n      g.handle === \"low\" ? [0, fractionOf(high) - stepFraction] : [fractionOf(low) + stepFraction, 1];\n    const fraction = clamp(fractionAt(event.clientX, g.box) + g.shift, floor, ceiling);\n    setDrag({ handle: g.handle, fraction, moving: true });\n    moveTo(g.handle, min + fraction * span);\n  };\n\n  const release = () => {\n    grip.current = null;\n    setDrag(null);\n  };\n\n  const dragging = !!drag?.moving;\n  const tipHandle = drag?.handle ?? lastHeld;\n  // An open end is no limit, so it does not read as the end value.\n  const textOf = (handle: Handle) =>\n    handle === \"high\" && value[1] === null ? (openLabel ?? `${format(max, \"high\")}+`) : format(values[handle], handle);\n  const tipText = textOf(tipHandle);\n\n  useLayoutEffect(() => {\n    if (tip.current) setTipHalf(tip.current.offsetWidth / 2);\n  }, [tipText]);\n\n  const tallest = Math.max(1, ...(buckets ?? []));\n  // While a handle is dragged, the bars it passes rise a little, in a soft wave centred on the handle.\n  const wave = dragging && drag ? drag.fraction : pulled ? pulled.fraction : null;\n  const bumpAt = wave !== null && buckets?.length ? wave * buckets.length - 0.5 : null;\n  const bumpOf = (i: number) => {\n    if (bumpAt === null) return 0;\n    const near = Math.max(0, 1 - Math.abs(i - bumpAt) / 2.4);\n    return near * near;\n  };\n  // The rise is a few fixed pixels plus a small share of the bar, so a short bar shows it as clearly as a tall one.\n  // It grows the height rather than scaling the bar, and stops at the top of the bar area: a card around the chart\n  // clips anything above it, which would cut the rounded top flat.\n  const heightOf = (share: number, bump: number) =>\n    bump ? `min(100%, calc(${share}% + ${bump} * var(--lift, 1) * (5px + ${0.13 * share}%)))` : `${share}%`;\n  const lowShown = single ? 0 : shown.low;\n  const handles: Handle[] = single ? [\"high\"] : [\"low\", \"high\"];\n  const columns = buckets?.length || PLACEHOLDER_BARS;\n\n  return (\n    <div\n      ref={root}\n      data-dragging={dragging || !!pulled || undefined}\n      data-disabled={disabled || undefined}\n      className={cn(\n        \"group/range relative cursor-pointer touch-pan-y select-none [-webkit-tap-highlight-color:transparent]\",\n        \"data-[dragging]:cursor-grabbing data-[disabled]:pointer-events-none data-[disabled]:opacity-50\",\n        className,\n      )}\n      onPointerDown={press}\n      onPointerMove={follow}\n      onPointerUp={release}\n      onPointerCancel={release}\n      onLostPointerCapture={release}\n      onClick={(event) => {\n        if (!pressed.current && !disabled) land(event.clientX, !!(event.target as HTMLElement).closest(\"[data-bars]\"));\n        pressed.current = false;\n      }}\n      {...props}\n    >\n      {buckets && buckets.length === 0 && !loading && (\n        <EmptyNote className=\"mx-[10px] h-14 justify-center\">{emptyText}</EmptyNote>\n      )}\n      {buckets && (buckets.length > 0 || loading) && (\n        <div\n          data-bars\n          aria-hidden\n          className=\"mx-[10px] flex h-14 items-end gap-[2px] motion-reduce:[--lift:0]\"\n          // Many bars close their gaps up, a 2px gap at most and a quarter of a bar's slot at least, so bars never vanish.\n          style={columns > 40 ? { gap: `min(2px, calc(100% / ${columns * 4}))` } : undefined}\n        >\n          {loading\n            ? Array.from({ length: columns }, (_, i) => (\n                <span\n                  key={i}\n                  className={cn(\n                    \"min-w-0 flex-1 rounded-t-[3px]\",\n                    SKELETON_FILL,\n                    \"transition-[height,background-color] duration-[420ms,200ms] ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none\",\n                  )}\n                  style={{ height: `${hillAt(i, columns)}%` }}\n                />\n              ))\n            : buckets.map((count, i) => {\n                const start = i / buckets.length;\n                const end = (i + 1) / buckets.length;\n                const cover = clamp((Math.min(end, shown.high) - Math.max(start, lowShown)) / (end - start), 0, 1);\n                const lit = cover > 0 ? Math.round((0.35 + 0.65 * cover) * 100) : 0;\n                const narrow = barScale !== 1;\n                const bar = (\n                  <span\n                    key={i}\n                    className={cn(\n                      \"min-w-0 rounded-t-[3px]\",\n                      narrow ? \"flex-none\" : \"flex-1\",\n                      \"transition-[height,background-color] duration-[420ms,200ms] ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none\",\n                      // While dragging, the wave follows the handle exactly; it eases back when the handle is let go.\n                      \"group-data-[dragging]/range:transition-none\",\n                      // Forced colours would drop the inline fill, and the chart with it.\n                      \"forced-colors:[forced-color-adjust:none]\",\n                    )}\n                    style={{\n                      height: heightOf(Math.max(count ? 8 : 3, (count / tallest) * 100), bumpOf(i)),\n                      backgroundColor: `color-mix(in srgb, var(--fu-accent-soft,#8FAAFF) ${lit}%, var(--fu-bar-out,#4A4A4A))`,\n                      // The bar a denser chart would draw: its slot plus one 2px gap, scaled, less the gap.\n                      width: narrow ? `calc((100% + 2px) * ${barScale} - 2px)` : undefined,\n                    } as CSSProperties}\n                  />\n                );\n                return narrow ? (\n                  <span key={i} className=\"flex h-full min-w-0 flex-1 items-end justify-center\">\n                    {bar}\n                  </span>\n                ) : (\n                  bar\n                );\n              })}\n        </div>\n      )}\n\n      <div className=\"relative h-6\">\n        <span\n          aria-hidden\n          className={cn(\n            \"absolute inset-x-0 top-[10px] h-1 rounded-[2px] transition-[background-color] duration-200 motion-reduce:transition-none\",\n            loading ? SKELETON_FILL : \"bg-[var(--fu-rail,#4A4A4A)] forced-colors:bg-[GrayText] forced-colors:[forced-color-adjust:none]\",\n          )}\n        />\n        <span\n          aria-hidden\n          className={cn(\n            \"absolute top-[10px] h-1 rounded-[2px] bg-[var(--fu-accent-soft,#8FAAFF)] forced-colors:bg-[Highlight] forced-colors:[forced-color-adjust:none]\",\n            // While loading the fill and handles are hidden; they fade in with the data.\n            loading && \"opacity-0\",\n            \"transition-[left,right,opacity] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none\",\n            \"group-data-[dragging]/range:transition-none\",\n          )}\n          style={{ insetInlineStart: single ? 0 : along(lowShown), insetInlineEnd: along(1 - shown.high) }}\n        />\n        {handles.map((handle) => {\n          const grabbed = (drag ?? pulled)?.handle === handle;\n          const label = labels?.[handle] ?? (handle === \"low\" ? \"Minimum\" : \"Maximum\");\n          return (\n            <span key={handle} className=\"contents\">\n              <input\n                type=\"range\"\n                data-for={handle}\n                aria-label={label}\n                aria-valuetext={\n                  handle === \"high\" && value[1] === null ? \"No maximum\" : handle === \"low\" && value[0] === null ? \"No minimum\" : format(values[handle], handle)\n                }\n                min={single ? min + step : min}\n                max={max}\n                step={step}\n                value={values[handle]}\n                disabled={disabled}\n                onChange={(event) => moveTo(handle, Number(event.target.value))}\n                // Left and Right follow the screen in RTL too, the same in every browser.\n                onKeyDown={(event) => {\n                  const key = readingKey(event.key, event.currentTarget);\n                  if (key === event.key) return;\n                  event.preventDefault();\n                  moveTo(handle, values[handle] + (key === \"ArrowRight\" ? step : -step));\n                }}\n                className=\"peer pointer-events-none absolute inset-0 m-0 h-full w-full opacity-0\"\n              />\n              <span\n                data-handle={handle}\n                data-grabbed={grabbed || undefined}\n                className={cn(\n                  loading && \"opacity-0\",\n                  \"absolute top-[2px] -ms-[10px] size-5 cursor-grab touch-none rounded-full bg-[var(--fu-handle,#F8F5F1)]\",\n                  \"shadow-[0_0_0_0_color-mix(in_srgb,var(--fu-accent-soft,#8FAAFF)_28%,transparent),0_0_0_1px_var(--fu-handle-edge,rgb(0_0_0/0.25)),0_2px_6px_var(--fu-shadow,rgb(0_0_0/0.5))]\",\n                  \"transition-[left,scale,box-shadow,opacity] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none\",\n                  \"before:absolute before:-inset-[10px] before:rounded-full before:content-['']\",\n                  \"hover:scale-[1.15]\",\n                  \"peer-focus-visible:z-[1] data-[grabbed]:z-[1] data-[grabbed]:scale-[1.15] data-[grabbed]:cursor-grabbing\",\n                  \"data-[grabbed]:shadow-[0_0_0_6px_color-mix(in_srgb,var(--fu-accent-soft,#8FAAFF)_28%,transparent),0_0_0_1px_var(--fu-handle-edge,rgb(0_0_0/0.25)),0_2px_6px_var(--fu-shadow,rgb(0_0_0/0.5))]\",\n                  \"group-data-[dragging]/range:data-[grabbed]:transition-[scale,box-shadow]\",\n                  \"peer-focus-visible:outline-2 peer-focus-visible:outline-offset-2 peer-focus-visible:outline-solid peer-focus-visible:outline-[var(--fu-accent-soft,#8FAAFF)]\",\n                  \"forced-colors:bg-[CanvasText] forced-colors:[forced-color-adjust:none] forced-colors:peer-focus-visible:outline-[Highlight]\",\n                )}\n                style={{ insetInlineStart: along(shown[handle]) }}\n              />\n            </span>\n          );\n        })}\n      </div>\n\n      <span\n        ref={tip}\n        aria-hidden\n        data-state={dragging ? \"open\" : \"closed\"}\n        className={cn(\n          \"pointer-events-none absolute bottom-10 z-[2] -translate-x-1/2 rtl:translate-x-1/2 rounded-[8px] px-2 py-1 whitespace-nowrap\",\n          \"bg-[var(--fu-text,#F8F5F1)] text-[13px] leading-[18px] font-medium text-[var(--fu-surface-1,#171717)] tabular-nums\",\n          \"transition-[opacity,translate] duration-150 ease-in-out motion-reduce:transition-none\",\n          \"data-[state=closed]:translate-y-1 data-[state=closed]:opacity-0\",\n        )}\n        style={\n          {\n            insetInlineStart: `clamp(${tipHalf}px, ${along(shown[tipHandle])}, calc(100% - ${tipHalf}px))`,\n          } as CSSProperties\n        }\n      >\n        {tipText}\n      </span>\n    </div>\n  );\n}\n"
    },
    {
      "path": "registry/ui/filter-card.tsx",
      "type": "registry:ui",
      "target": "@components/filters-ui/ui/filter-card.tsx",
      "content": "\"use client\";\n\nimport { useId, useRef, useState, type HTMLAttributes, type ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { ChevronDownIcon } from \"./icons\";\n\nexport type FilterCardProps = Omit<HTMLAttributes<HTMLElement>, \"title\" | \"children\"> & {\n  title: string;\n  /** The value in words (\"Under $45k\"). Shown on the closed card; null or empty means the filter is unset. */\n  summary?: string | null;\n  /** Clears this one filter. When given, a Clear button takes the summary's place while open or hovered. */\n  onClear?: () => void;\n  /** Controlled open state. Leave undefined to let the card manage it. */\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  /** Looks like a closed card but cannot be opened or focused, e.g. a filter whose body is not ready. */\n  disabled?: boolean;\n  /** Accessible name of the Clear button. Default \"Clear {title}\". */\n  clearLabel?: string;\n  /** Heading level wrapping the head button. Default 3. */\n  headingLevel?: 2 | 3 | 4 | 5 | 6;\n  bodyClassName?: string;\n  children?: ReactNode;\n};\n\nconst SMOOTH = \"ease-[cubic-bezier(0.22,1,0.36,1)]\";\n\n// The summary and Clear share one slot and trade places over 150ms through a 2px blur and 4px shift.\nconst SUMMARY_HIDDEN = \"opacity-0 blur-[2px] -translate-y-1\";\nconst SUMMARY_HIDES_WHEN = [\n  \"group-data-[state=open]/card:opacity-0 group-data-[state=open]/card:blur-[2px] group-data-[state=open]/card:-translate-y-1\",\n  \"group-hover/slot:opacity-0 group-hover/slot:blur-[2px] group-hover/slot:-translate-y-1\",\n  \"group-focus-within/slot:opacity-0 group-focus-within/slot:blur-[2px] group-focus-within/slot:-translate-y-1\",\n].join(\" \");\n// Hovering anywhere on a closed card offers Clear in the summary's place.\nconst SUMMARY_HIDES_ON_CARD_HOVER = \"group-hover/card:opacity-0 group-hover/card:blur-[2px] group-hover/card:-translate-y-1\";\nconst CLEAR_SHOWS_ON_CARD_HOVER = \"group-hover/card:opacity-100 group-hover/card:blur-none group-hover/card:translate-y-0\";\n// A hidden Clear takes no taps: only a pointer that can hover reveals it before a click.\nconst CLEAR_HIDDEN = \"pointer-events-none opacity-0 blur-[2px] translate-y-1 [@media(hover:hover)]:pointer-events-auto\";\nconst CLEAR_SHOWS_WHEN = [\n  \"group-data-[state=open]/card:pointer-events-auto group-data-[state=open]/card:opacity-100 group-data-[state=open]/card:blur-none group-data-[state=open]/card:translate-y-0\",\n  \"group-hover/slot:opacity-100 group-hover/slot:blur-none group-hover/slot:translate-y-0\",\n  \"group-focus-within/slot:opacity-100 group-focus-within/slot:blur-none group-focus-within/slot:translate-y-0\",\n].join(\" \");\n\nconst FOCUS_RING =\n  \"outline-none focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-[var(--fu-accent-soft,#8FAAFF)]\";\n\n/**\n * One filter in a rounded card: a 52px head (title, value summary or Clear, chevron) that opens a body.\n * Opening animates the height over 480ms and reveals the content from a 6px blur, 6px lower.\n */\nexport function FilterCard({\n  title,\n  summary,\n  onClear,\n  open: openProp,\n  defaultOpen = false,\n  onOpenChange,\n  disabled = false,\n  clearLabel,\n  headingLevel = 3,\n  className,\n  bodyClassName,\n  children,\n  ...props\n}: FilterCardProps) {\n  const id = useId();\n  const headId = `${id}-head`;\n  const bodyId = `${id}-body`;\n  const head = useRef<HTMLButtonElement>(null);\n  const [innerOpen, setInnerOpen] = useState(defaultOpen);\n  const open = !disabled && (openProp ?? innerOpen);\n  const set = Boolean(summary);\n\n  // The last summary stays in place while it fades out after a clear.\n  const [lastSummary, setLastSummary] = useState(summary ?? \"\");\n  if (summary && summary !== lastSummary) setLastSummary(summary);\n\n  const setOpen = (next: boolean) => {\n    if (openProp === undefined) setInnerOpen(next);\n    onOpenChange?.(next);\n  };\n\n  const Heading = `h${headingLevel}` as const;\n  const swap = cn(\n    \"transition-[opacity,filter,translate] duration-150 ease-in-out motion-reduce:transition-none\",\n    \"group-data-[state=open]/card:duration-[480ms] group-data-[state=open]/card:ease-[cubic-bezier(0.22,1,0.36,1)]\",\n  );\n\n  return (\n    <section\n      data-state={open ? \"open\" : \"closed\"}\n      data-set={set ? \"true\" : \"false\"}\n      className={cn(\n        \"not-prose group/card relative overflow-hidden rounded-[24px] border border-[var(--fu-card-border,#2A2A2A)] bg-[var(--fu-card,#1F1F1F)] text-[var(--fu-text,#F8F5F1)]\",\n        \"transition-[background-color,border-color,opacity] duration-200 motion-reduce:transition-none\",\n        \"[@media(hover:hover)]:data-[state=closed]:has-[[data-filter-card-head]:enabled:hover,[data-filter-card-slot]:hover]:border-[var(--fu-line,#404040)] [@media(hover:hover)]:data-[state=closed]:has-[[data-filter-card-head]:enabled:hover,[data-filter-card-slot]:hover]:bg-[var(--fu-card-hover,#262626)]\",\n        // The head button sits flush in a clipped card, so its focus ring is drawn around the card.\n        \"has-[[data-filter-card-head]:focus-visible]:outline-2 has-[[data-filter-card-head]:focus-visible]:outline-offset-2 has-[[data-filter-card-head]:focus-visible]:outline-solid has-[[data-filter-card-head]:focus-visible]:outline-[var(--fu-accent-soft,#8FAAFF)]\",\n        className,\n      )}\n      {...props}\n    >\n      <Heading className=\"m-0 -mb-0.5 text-[15px] font-semibold leading-5 text-[var(--fu-text,#F8F5F1)]\">\n        <button\n          ref={head}\n          type=\"button\"\n          id={headId}\n          data-filter-card-head=\"\"\n          aria-expanded={open}\n          aria-controls={bodyId}\n          disabled={disabled}\n          onClick={() => setOpen(!open)}\n          className={cn(\n            \"flex h-[52px] w-full cursor-pointer items-center gap-3 rounded-[23px] px-4 text-start font-[inherit] text-inherit disabled:cursor-default\",\n            \"outline-none\",\n          )}\n        >\n          <span className=\"min-w-0 truncate\">{title}</span>\n          {set && <span className=\"sr-only\">, {summary}</span>}\n          {set && (\n            <span aria-hidden=\"true\" className=\"invisible min-w-0 max-w-[calc((100%+32px)*0.55)] shrink-0 truncate text-[14px] font-normal\">\n              {summary}\n            </span>\n          )}\n          <ChevronDownIcon\n            size={20}\n            className={cn(\n              \"ms-auto shrink-0 text-[var(--fu-mute,#BDBDBD)] group-has-[[data-filter-card-head]:disabled]/card:opacity-40 transition-[rotate] duration-[480ms] motion-reduce:transition-none\",\n              SMOOTH,\n              \"group-data-[state=open]/card:rotate-180\",\n            )}\n          />\n        </button>\n      </Heading>\n\n      {onClear && (\n        <div\n          inert={!set}\n          data-filter-card-slot=\"\"\n          className=\"group/slot pointer-events-none absolute inset-e-[46px] top-4 grid h-5 max-w-[55%] justify-items-end text-[14px] leading-5 text-[var(--fu-accent-soft,#8FAAFF)]\"\n        >\n          <span aria-hidden=\"true\" className={cn(\"pointer-events-none max-w-full truncate font-normal [grid-area:1/1]\", swap, set ? SUMMARY_HIDES_WHEN : SUMMARY_HIDDEN, set && !disabled && SUMMARY_HIDES_ON_CARD_HOVER)}>\n            {summary || lastSummary}\n          </span>\n          <button\n            type=\"button\"\n            tabIndex={set ? 0 : -1}\n            aria-label={clearLabel ?? `Clear ${title.toLowerCase()}`}\n            onClick={() => {\n              onClear();\n              head.current?.focus();\n            }}\n            className={cn(\n              \"relative -my-0.5 cursor-pointer rounded-[6px] py-0.5 font-medium [grid-area:1/1] before:absolute before:inset-x-0 before:-inset-y-2 before:content-['']\",\n              FOCUS_RING,\n              \"focus-visible:outline-offset-2\",\n              swap,\n              CLEAR_HIDDEN,\n              set && CLEAR_SHOWS_WHEN,\n              set && !disabled && CLEAR_SHOWS_ON_CARD_HOVER,\n            )}\n          >\n            Clear\n          </button>\n        </div>\n      )}\n      {!onClear && set && (\n        <span\n          aria-hidden=\"true\"\n          className={cn(\n            \"pointer-events-none absolute inset-e-[46px] top-4 max-w-[55%] truncate text-[14px] leading-5 text-[var(--fu-accent-soft,#8FAAFF)]\",\n            swap,\n            \"group-data-[state=open]/card:opacity-0\",\n          )}\n        >\n          {summary}\n        </span>\n      )}\n\n      <div\n        id={bodyId}\n        role=\"region\"\n        aria-labelledby={headId}\n        inert={!open}\n        className={cn(\n          \"grid grid-rows-[0fr] transition-[grid-template-rows] duration-[480ms] motion-reduce:transition-none\",\n          SMOOTH,\n          \"group-data-[state=open]/card:grid-rows-[1fr]\",\n        )}\n      >\n        <div className=\"min-h-0 overflow-hidden\">\n          <div\n            className={cn(\n              // pt-0.5 makes up the head's -2px margin, so content starts right under the 52px head.\n              \"px-4 pt-0.5 pb-4\",\n              \"translate-y-1.5 opacity-0 blur-[6px] transition-[opacity,filter,translate] duration-[480ms] motion-reduce:transition-none\",\n              SMOOTH,\n              \"group-data-[state=open]/card:translate-y-0 group-data-[state=open]/card:opacity-100 group-data-[state=open]/card:blur-none\",\n              \"group-data-[state=open]/card:delay-[120ms] group-data-[state=open]/card:duration-[460ms] group-data-[state=open]/card:ease-[cubic-bezier(0.16,1,0.3,1)]\",\n              bodyClassName,\n            )}\n          >\n            {children}\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n"
    }
  ],
  "meta": {
    "addedIn": "1.0.0",
    "updatedIn": "1.3.1"
  }
}
