{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dual-range-slider",
  "title": "Dual Range Slider",
  "description": "A two-handle range filter with a histogram behind it: bars inside the range light up, the result count rolls as you drag, the filled part drags both ends together, and Min / Max fields stay in sync for exact numbers.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/dual-range-slider/dual-range-slider.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface DualRangeSliderProps {\n  min?: number;\n  max?: number;\n  step?: number;\n  /** Smallest allowed distance between the two handles. */\n  minGap?: number;\n  value?: [number, number];\n  defaultValue?: [number, number];\n  onValueChange?: (value: [number, number]) => void;\n  /** Called once a drag or edit ends. */\n  onValueCommit?: (value: [number, number]) => void;\n  /** Counts per bucket, drawn as bars behind the track; the bars inside the range light up. */\n  histogram?: number[];\n  label?: string;\n  /** Text before the numbers, e.g. \"$\". */\n  prefix?: string;\n  suffix?: string;\n  /** Shows \"n results\" from the histogram. */\n  showCount?: boolean;\n  /** Show the Min / Max number fields. */\n  inputs?: boolean;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: {\n    text: \"#F5F4F1\",\n    muted: \"rgba(245,244,241,0.5)\",\n    faint: \"rgba(245,244,241,0.3)\",\n    panel: \"#0E0E0E\",\n    border: \"rgba(255,255,255,0.1)\",\n    track: \"rgba(255,255,255,0.1)\",\n    fill: \"#F5F4F1\",\n    bar: \"rgba(255,255,255,0.1)\",\n    barOn: \"rgba(245,244,241,0.55)\",\n    thumb: \"#F5F4F1\",\n    thumbEdge: \"#0E0E0E\",\n    input: \"rgba(255,255,255,0.04)\",\n    inputBorder: \"rgba(255,255,255,0.12)\",\n    focus: \"rgba(245,244,241,0.85)\",\n    tip: \"#F5F4F1\",\n    onTip: \"#0A0A0A\",\n  },\n  light: {\n    text: \"#0A0A0A\",\n    muted: \"rgba(10,10,10,0.5)\",\n    faint: \"rgba(10,10,10,0.3)\",\n    panel: \"#FFFFFF\",\n    border: \"rgba(10,10,10,0.1)\",\n    track: \"rgba(10,10,10,0.1)\",\n    fill: \"#0A0A0A\",\n    bar: \"rgba(10,10,10,0.08)\",\n    barOn: \"rgba(10,10,10,0.5)\",\n    thumb: \"#FFFFFF\",\n    thumbEdge: \"#0A0A0A\",\n    input: \"#FFFFFF\",\n    inputBorder: \"rgba(10,10,10,0.14)\",\n    focus: \"rgba(10,10,10,0.85)\",\n    tip: \"#0A0A0A\",\n    onTip: \"#FFFFFF\",\n  },\n};\n\n// A believable price distribution: most listings in the low-middle, a long tail.\nconst DEFAULT_HISTOGRAM = [\n  3, 6, 11, 18, 26, 34, 41, 45, 47, 44, 40, 37, 33, 31, 28, 27, 24, 20, 18, 17,\n  15, 13, 12, 10, 9, 9, 8, 7, 6, 6, 5, 4, 4, 3, 3, 2, 2, 2, 1, 1,\n];\n\nexport function DualRangeSlider({\n  min = 0,\n  max = 1000,\n  step = 10,\n  minGap = 50,\n  value,\n  defaultValue = [180, 620],\n  onValueChange,\n  onValueCommit,\n  histogram = DEFAULT_HISTOGRAM,\n  label = \"Price range\",\n  prefix = \"$\",\n  suffix = \"\",\n  showCount = true,\n  inputs = true,\n  theme = \"dark\",\n  className,\n}: DualRangeSliderProps) {\n  const p = PALETTES[theme];\n  const uid = React.useId();\n  const reduce = Boolean(useReducedMotion());\n  const [internal, setInternal] =\n    React.useState<[number, number]>(defaultValue);\n  const [lo, hi] = value ?? internal;\n  const trackRef = React.useRef<HTMLDivElement>(null);\n  const drag = React.useRef<{\n    mode: 0 | 1 | \"both\";\n    x: number;\n    start: [number, number];\n  } | null>(null);\n  const [dragging, setDragging] = React.useState<0 | 1 | \"both\" | null>(null);\n  const [focused, setFocused] = React.useState<0 | 1 | null>(null);\n  const [draft, setDraft] = React.useState<{ i: 0 | 1; text: string } | null>(\n    null,\n  );\n\n  const span = max - min;\n  const pct = (v: number) => ((v - min) / span) * 100;\n  const snap = (v: number) => Math.round((v - min) / step) * step + min;\n  const fmt = (v: number) => `${prefix}${v.toLocaleString(\"en-US\")}${suffix}`;\n\n  const set = (next: [number, number]) => {\n    if (value === undefined) setInternal(next);\n    onValueChange?.(next);\n  };\n  // Move one handle, keeping it inside the bounds and at least minGap from the other.\n  const move = (i: 0 | 1, v: number, from: [number, number] = [lo, hi]) => {\n    const n = snap(v);\n    const next: [number, number] =\n      i === 0\n        ? [Math.max(min, Math.min(n, from[1] - minGap)), from[1]]\n        : [from[0], Math.min(max, Math.max(n, from[0] + minGap))];\n    if (next[0] !== lo || next[1] !== hi) set(next);\n    return next;\n  };\n\n  const toValue = (clientX: number) => {\n    const r = trackRef.current!.getBoundingClientRect();\n    return min + Math.min(1, Math.max(0, (clientX - r.left) / r.width)) * span;\n  };\n\n  const onPointerDown = (e: React.PointerEvent) => {\n    if (e.button !== 0) return;\n    e.preventDefault();\n    const v = toValue(e.clientX);\n    const target = (e.target as HTMLElement)\n      .closest(\"[data-part]\")\n      ?.getAttribute(\"data-part\");\n    // Grabbing the filled part moves the whole range; elsewhere, the nearer handle jumps there.\n    const mode: 0 | 1 | \"both\" =\n      target === \"lo\"\n        ? 0\n        : target === \"hi\"\n          ? 1\n          : target === \"fill\"\n            ? \"both\"\n            : Math.abs(v - lo) <= Math.abs(v - hi)\n              ? 0\n              : 1;\n    trackRef.current!.setPointerCapture(e.pointerId);\n    drag.current = { mode, x: e.clientX, start: [lo, hi] };\n    setDragging(mode);\n    if (mode !== \"both\" && target !== \"lo\" && target !== \"hi\") move(mode, v);\n    (\n      trackRef.current!.querySelector(\n        `[data-part=\"${mode === 1 ? \"hi\" : \"lo\"}\"]`,\n      ) as HTMLElement | null\n    )?.focus({ preventScroll: true });\n  };\n  const onPointerMove = (e: React.PointerEvent) => {\n    const d = drag.current;\n    if (!d) return;\n    if (d.mode === \"both\") {\n      const r = trackRef.current!.getBoundingClientRect();\n      const width = d.start[1] - d.start[0];\n      const shift =\n        snap(d.start[0] + ((e.clientX - d.x) / r.width) * span) - d.start[0];\n      const a = Math.max(min, Math.min(max - width, d.start[0] + shift));\n      if (a !== lo) set([a, a + width]);\n    } else move(d.mode, toValue(e.clientX));\n  };\n  const endDrag = () => {\n    if (!drag.current) return;\n    drag.current = null;\n    setDragging(null);\n    onValueCommit?.([lo, hi]);\n  };\n\n  const onKey = (i: 0 | 1) => (e: React.KeyboardEvent) => {\n    const big = Math.max(step, span / 10);\n    const cur = i === 0 ? lo : hi;\n    const map: Record<string, number> = {\n      ArrowLeft: cur - step,\n      ArrowDown: cur - step,\n      ArrowRight: cur + step,\n      ArrowUp: cur + step,\n      PageDown: cur - big,\n      PageUp: cur + big,\n      Home: min,\n      End: max,\n    };\n    if (!(e.key in map)) return;\n    e.preventDefault();\n    const next = move(i, map[e.key]);\n    onValueCommit?.(next);\n  };\n\n  const commitDraft = () => {\n    if (!draft) return;\n    const n = Number(draft.text.replace(/[^\\d.-]/g, \"\"));\n    setDraft(null);\n    // Move first: `onValueCommit?.(move(...))` would skip the move when there's no callback.\n    if (draft.text.trim() !== \"\" && Number.isFinite(n)) {\n      const next = move(draft.i, n);\n      onValueCommit?.(next);\n    }\n  };\n\n  const bins = histogram.length;\n  const barMax = Math.max(1, ...histogram);\n  const count = histogram.reduce((sum, c, b) => {\n    const center = min + ((b + 0.5) / bins) * span;\n    return center >= lo && center <= hi ? sum + c : sum;\n  }, 0);\n\n  return (\n    <div\n      className={cn(\"flex w-full flex-col\", className)}\n      style={{\n        gap: 14,\n        padding: 18,\n        borderRadius: 18,\n        background: p.panel,\n        border: `1px solid ${p.border}`,\n        fontFamily: \"Inter, sans-serif\",\n        color: p.text,\n      }}\n    >\n      <div className=\"flex items-baseline justify-between\" style={{ gap: 12 }}>\n        <span id={`${uid}-label`} className=\"text-[14px] font-semibold\">\n          {label}\n        </span>\n        {showCount && (\n          <span\n            className=\"flex items-baseline text-[12.5px] tabular-nums\"\n            style={{ color: p.muted, gap: 4 }}\n            aria-live=\"polite\"\n          >\n            <span\n              className=\"relative inline-grid overflow-hidden\"\n              style={{ color: p.text }}\n            >\n              <AnimatePresence initial={false} mode=\"popLayout\">\n                <motion.span\n                  key={count}\n                  className=\"col-start-1 row-start-1 font-medium\"\n                  initial={reduce ? false : { y: 8, opacity: 0 }}\n                  animate={{ y: 0, opacity: 1 }}\n                  exit={reduce ? undefined : { y: -8, opacity: 0 }}\n                  transition={{ duration: 0.18 }}\n                >\n                  {count}\n                </motion.span>\n              </AnimatePresence>\n            </span>\n            results\n          </span>\n        )}\n      </div>\n\n      <div style={{ padding: \"0 9px\" }}>\n        {bins > 0 && (\n          <div\n            className=\"flex items-end\"\n            aria-hidden=\"true\"\n            style={{ height: 64, gap: 2 }}\n          >\n            {histogram.map((c, b) => {\n              const center = min + ((b + 0.5) / bins) * span;\n              const on = center >= lo && center <= hi;\n              return (\n                <span\n                  key={b}\n                  className=\"flex-1\"\n                  style={{\n                    height: `${Math.max(4, (c / barMax) * 100)}%`,\n                    borderRadius: \"3px 3px 1px 1px\",\n                    background: on ? p.barOn : p.bar,\n                    transition: \"background 0.2s ease\",\n                  }}\n                />\n              );\n            })}\n          </div>\n        )}\n        <div\n          ref={trackRef}\n          className=\"relative cursor-pointer touch-none select-none\"\n          style={{ height: 28 }}\n          onPointerDown={onPointerDown}\n          onPointerMove={onPointerMove}\n          onPointerUp={endDrag}\n          onPointerCancel={endDrag}\n        >\n          <span\n            className=\"absolute inset-x-0 top-1/2 -translate-y-1/2 rounded-full\"\n            style={{ height: 4, background: p.track }}\n          />\n          {/* The whole height between the handles is grabbable, not just the thin line. */}\n          <span\n            data-part=\"fill\"\n            className=\"absolute inset-y-0 flex items-center\"\n            style={{\n              left: `${pct(lo)}%`,\n              width: `${pct(hi) - pct(lo)}%`,\n              cursor: dragging === \"both\" ? \"grabbing\" : \"grab\",\n            }}\n          >\n            <span\n              className=\"w-full rounded-full\"\n              style={{\n                height: dragging === \"both\" ? 6 : 4,\n                background: p.fill,\n                transition: \"height 0.15s ease\",\n              }}\n            />\n          </span>\n          {([0, 1] as const).map((i) => {\n            const v = i === 0 ? lo : hi;\n            const active =\n              dragging === i || dragging === \"both\" || focused === i;\n            return (\n              <span\n                key={i}\n                data-part={i === 0 ? \"lo\" : \"hi\"}\n                role=\"slider\"\n                tabIndex={0}\n                aria-labelledby={`${uid}-label`}\n                aria-label={i === 0 ? \"Minimum\" : \"Maximum\"}\n                aria-valuemin={i === 0 ? min : lo + minGap}\n                aria-valuemax={i === 0 ? hi - minGap : max}\n                aria-valuenow={v}\n                aria-valuetext={fmt(v)}\n                onKeyDown={onKey(i)}\n                onFocus={(e) =>\n                  e.currentTarget.matches(\":focus-visible\") && setFocused(i)\n                }\n                onBlur={() => setFocused(null)}\n                className=\"absolute top-1/2 rounded-full outline-none\"\n                style={{\n                  left: `${pct(v)}%`,\n                  width: 20,\n                  height: 20,\n                  marginLeft: -10,\n                  marginTop: -10,\n                  zIndex: dragging === i ? 3 : 2,\n                  cursor: dragging === i ? \"grabbing\" : \"grab\",\n                }}\n              >\n                <motion.span\n                  className=\"absolute inset-0 rounded-full\"\n                  style={{\n                    background: p.thumb,\n                    border: `2px solid ${p.thumbEdge}`,\n                    boxShadow: `0 0 0 1px ${p.fill}, 0 2px 8px rgba(0,0,0,0.3)`,\n                  }}\n                  animate={{ scale: active && !reduce ? 1.18 : 1 }}\n                  transition={{ type: \"spring\", stiffness: 600, damping: 30 }}\n                />\n                <AnimatePresence>\n                  {active && (\n                    <motion.span\n                      className=\"pointer-events-none absolute bottom-full left-1/2 flex justify-center\"\n                      style={{ width: 0, marginBottom: 10 }}\n                      initial={{ opacity: 0, y: 4 }}\n                      animate={{ opacity: 1, y: 0 }}\n                      exit={{ opacity: 0, y: 4 }}\n                      transition={{ duration: reduce ? 0 : 0.14 }}\n                    >\n                      <span\n                        className=\"text-[11.5px] font-semibold whitespace-nowrap tabular-nums\"\n                        style={{\n                          padding: \"3px 7px\",\n                          borderRadius: 6,\n                          background: p.tip,\n                          color: p.onTip,\n                        }}\n                      >\n                        {fmt(v)}\n                      </span>\n                    </motion.span>\n                  )}\n                </AnimatePresence>\n              </span>\n            );\n          })}\n        </div>\n        <div\n          className=\"flex justify-between text-[11.5px] tabular-nums\"\n          style={{ color: p.faint, marginTop: 2 }}\n        >\n          <span>{fmt(min)}</span>\n          <span>{fmt(max)}+</span>\n        </div>\n      </div>\n\n      {inputs && (\n        <div className=\"flex items-center\" style={{ gap: 10 }}>\n          {([0, 1] as const).map((i) => (\n            <React.Fragment key={i}>\n              {i === 1 && (\n                <span\n                  aria-hidden=\"true\"\n                  style={{ width: 10, height: 1, background: p.faint }}\n                />\n              )}\n              <label\n                className=\"flex flex-1 flex-col rounded-xl focus-within:ring-2\"\n                style={{\n                  padding: \"7px 12px\",\n                  background: p.input,\n                  border: `1px solid ${p.inputBorder}`,\n                  gap: 1,\n                  [\"--tw-ring-color\" as string]: p.focus,\n                }}\n              >\n                <span\n                  className=\"text-[11px] font-medium\"\n                  style={{ color: p.muted }}\n                >\n                  {i === 0 ? \"Min\" : \"Max\"}\n                </span>\n                <span\n                  className=\"flex items-baseline text-[14px] font-medium tabular-nums\"\n                  style={{ gap: 1 }}\n                >\n                  {prefix && <span style={{ color: p.muted }}>{prefix}</span>}\n                  <input\n                    inputMode=\"numeric\"\n                    value={\n                      draft?.i === i ? draft.text : String(i === 0 ? lo : hi)\n                    }\n                    onFocus={(e) => e.target.select()}\n                    onChange={(e) => setDraft({ i, text: e.target.value })}\n                    onBlur={commitDraft}\n                    onKeyDown={(e) => {\n                      if (e.key === \"Enter\") e.currentTarget.blur();\n                      if (e.key === \"Escape\") {\n                        setDraft(null);\n                        requestAnimationFrame(() =>\n                          (e.target as HTMLInputElement).blur(),\n                        );\n                      }\n                    }}\n                    className=\"w-full min-w-0 border-none bg-transparent outline-none\"\n                    style={{ color: p.text }}\n                    aria-label={i === 0 ? \"Minimum price\" : \"Maximum price\"}\n                  />\n                  {suffix && <span style={{ color: p.muted }}>{suffix}</span>}\n                </span>\n              </label>\n            </React.Fragment>\n          ))}\n        </div>\n      )}\n    </div>\n  );\n}\n\nexport default DualRangeSlider;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}