{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "slider",
  "title": "Slider",
  "description": "An accessible single or range slider with a draggable thumb, a value tooltip, optional step marks, keyboard control and a focus ring.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/slider/slider.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence } 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 SliderProps {\n  min?: number;\n  max?: number;\n  step?: number;\n  value?: number | [number, number];\n  defaultValue?: number | [number, number];\n  onValueChange?: (value: number | [number, number]) => void;\n  range?: boolean;\n  label?: string;\n  unit?: string;\n  unitPosition?: \"prefix\" | \"suffix\";\n  showValue?: boolean;\n  showTooltip?: boolean;\n  showMarks?: boolean;\n  theme?: \"dark\" | \"light\";\n  disabled?: boolean;\n  width?: number;\n  trackHeight?: number;\n  thumbSize?: number;\n  accentColor?: string;\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: {\n    track: \"rgba(255,255,255,0.1)\",\n    text: \"#F5F4F1\",\n    muted: \"rgba(245,244,241,0.5)\",\n    thumb: \"#F5F4F1\",\n    tooltipBg: \"#F5F4F1\",\n    tooltipText: \"#0A0A0A\",\n    mark: \"rgba(255,255,255,0.22)\",\n  },\n  light: {\n    track: \"rgba(10,10,10,0.1)\",\n    text: \"#0A0A0A\",\n    muted: \"rgba(10,10,10,0.5)\",\n    thumb: \"#FFFFFF\",\n    tooltipBg: \"#0A0A0A\",\n    tooltipText: \"#F5F4F1\",\n    mark: \"rgba(10,10,10,0.2)\",\n  },\n};\n\nexport function Slider({\n  min = 0,\n  max = 100,\n  step = 1,\n  value,\n  defaultValue,\n  onValueChange,\n  range = false,\n  label,\n  unit = \"\",\n  unitPosition = \"suffix\",\n  showValue = true,\n  showTooltip = true,\n  showMarks = false,\n  theme = \"dark\",\n  disabled = false,\n  width = 320,\n  trackHeight = 6,\n  thumbSize = 20,\n  accentColor = \"#F2A841\",\n  className,\n}: SliderProps) {\n  const p = PALETTES[theme];\n  const uid = React.useId();\n  const trackRef = React.useRef<HTMLDivElement>(null);\n  const [internal, setInternal] = React.useState<number[]>(() => {\n    if (defaultValue !== undefined) return Array.isArray(defaultValue) ? [...defaultValue] : [defaultValue];\n    return range ? [min + (max - min) * 0.2, min + (max - min) * 0.7] : [min + (max - min) * 0.4];\n  });\n  const [dragIdx, setDragIdx] = React.useState<number | null>(null);\n  const [hoverIdx, setHoverIdx] = React.useState<number | null>(null);\n  const [focusIdx, setFocusIdx] = React.useState<number | null>(null);\n  const isControlled = value !== undefined;\n  const raw = isControlled ? (Array.isArray(value) ? value : [value]) : internal;\n  const vals = range ? [raw[0] ?? min, raw[1] ?? max] : [raw[0] ?? min];\n  const span = max - min || 1;\n  const decimals = (String(step).split(\".\")[1] || \"\").length;\n  const pct = (v: number) => ((v - min) / span) * 100;\n\n  const snap = (v: number) => {\n    const stepped = Math.round((v - min) / step) * step + min;\n    return Number(Math.min(max, Math.max(min, stepped)).toFixed(decimals));\n  };\n\n  const update = (idx: number, next: number) => {\n    const out = [...vals];\n    let nv = snap(next);\n    if (range) nv = idx === 0 ? Math.min(nv, out[1]) : Math.max(nv, out[0]);\n    if (nv === out[idx]) return;\n    out[idx] = nv;\n    if (!isControlled) setInternal(out);\n    onValueChange?.(range ? [out[0], out[1]] : out[0]);\n  };\n\n  const valueFromPointer = (clientX: number) => {\n    const rect = trackRef.current?.getBoundingClientRect();\n    if (!rect) return min;\n    return min + Math.min(1, Math.max(0, (clientX - rect.left) / rect.width)) * span;\n  };\n\n  const onPointerDown = (e: React.PointerEvent<HTMLDivElement>) => {\n    if (disabled) return;\n    const v = valueFromPointer(e.clientX);\n    let idx = 0;\n    if (range) {\n      const d0 = Math.abs(v - vals[0]);\n      const d1 = Math.abs(v - vals[1]);\n      idx = d0 < d1 ? 0 : d0 > d1 ? 1 : v > vals[1] ? 1 : 0;\n    }\n    e.currentTarget.setPointerCapture(e.pointerId);\n    setDragIdx(idx);\n    update(idx, v);\n    (e.currentTarget.querySelector(`[data-thumb=\"${idx}\"]`) as HTMLElement | null)?.focus({ preventScroll: true });\n  };\n\n  const onPointerMove = (e: React.PointerEvent<HTMLDivElement>) => {\n    if (dragIdx === null) return;\n    update(dragIdx, valueFromPointer(e.clientX));\n  };\n\n  const endDrag = () => setDragIdx(null);\n\n  const onKeyDown = (idx: number) => (e: React.KeyboardEvent<HTMLDivElement>) => {\n    if (disabled) return;\n    const cur = vals[idx];\n    let next: number | null = null;\n    if (e.key === \"ArrowRight\" || e.key === \"ArrowUp\") next = cur + step;\n    else if (e.key === \"ArrowLeft\" || e.key === \"ArrowDown\") next = cur - step;\n    else if (e.key === \"PageUp\") next = cur + step * 10;\n    else if (e.key === \"PageDown\") next = cur - step * 10;\n    else if (e.key === \"Home\") next = min;\n    else if (e.key === \"End\") next = max;\n    if (next === null) return;\n    e.preventDefault();\n    update(idx, next);\n  };\n\n  const format = (v: number) => (unitPosition === \"prefix\" ? `${unit}${v}` : `${v}${unit}`);\n  const fillStart = range ? pct(vals[0]) : 0;\n  const fillEnd = pct(vals[vals.length - 1]);\n  const markCount = Math.round(span / step);\n  const marks = showMarks && markCount <= 20 ? Array.from({ length: markCount + 1 }, (_, i) => (i / markCount) * 100) : [];\n  const hit = thumbSize + 16;\n\n  return (\n    <div className={cn(\"inline-flex flex-col\", className)} style={{ width, fontFamily: \"Inter, sans-serif\", opacity: disabled ? 0.5 : 1 }}>\n      {(label || showValue) && (\n        <div className=\"flex items-baseline justify-between\" style={{ marginBottom: 6 }}>\n          {label && (\n            <span id={`${uid}-label`} className=\"font-semibold tracking-[-0.01em]\" style={{ color: p.text, fontSize: 14 }}>\n              {label}\n            </span>\n          )}\n          {showValue && (\n            <span className=\"ml-auto font-medium tabular-nums\" style={{ color: p.muted, fontSize: 13 }}>\n              {range ? `${format(vals[0])} – ${format(vals[1])}` : format(vals[0])}\n            </span>\n          )}\n        </div>\n      )}\n\n      <div\n        className=\"relative w-full touch-none select-none\"\n        style={{ height: hit, cursor: disabled ? \"default\" : \"pointer\" }}\n        onPointerDown={onPointerDown}\n        onPointerMove={onPointerMove}\n        onPointerUp={endDrag}\n        onPointerCancel={endDrag}\n      >\n        <div ref={trackRef} className=\"absolute right-0 left-0\" style={{ top: \"50%\", height: trackHeight, marginTop: -trackHeight / 2, borderRadius: trackHeight, background: p.track }}>\n          <div\n            className=\"absolute inset-y-0\"\n            style={{\n              left: `${fillStart}%`,\n              width: `${fillEnd - fillStart}%`,\n              borderRadius: trackHeight,\n              background: accentColor,\n              transition: dragIdx === null ? \"left 0.15s ease, width 0.15s ease\" : \"none\",\n            }}\n          />\n          {marks.map((m) => (\n            <span key={m} className=\"absolute rounded-full\" style={{ left: `${m}%`, top: \"50%\", width: 2, height: 2, marginLeft: -1, marginTop: -1, background: p.mark }} />\n          ))}\n\n          {vals.map((v, i) => {\n            const active = dragIdx === i || hoverIdx === i || focusIdx === i;\n            return (\n              <div\n                key={i}\n                data-thumb={i}\n                role=\"slider\"\n                tabIndex={disabled ? -1 : 0}\n                aria-orientation=\"horizontal\"\n                aria-valuemin={min}\n                aria-valuemax={max}\n                aria-valuenow={v}\n                aria-valuetext={format(v)}\n                aria-disabled={disabled}\n                aria-labelledby={label ? `${uid}-label` : undefined}\n                aria-label={label ? undefined : range ? (i === 0 ? \"Minimum\" : \"Maximum\") : \"Value\"}\n                onKeyDown={onKeyDown(i)}\n                onMouseEnter={() => setHoverIdx(i)}\n                onMouseLeave={() => setHoverIdx(null)}\n                onFocus={(e) => setFocusIdx(e.currentTarget.matches(\":focus-visible\") || dragIdx !== null ? i : null)}\n                onBlur={() => setFocusIdx(null)}\n                className=\"absolute outline-none\"\n                style={{\n                  left: `${pct(v)}%`,\n                  top: \"50%\",\n                  width: thumbSize,\n                  height: thumbSize,\n                  marginLeft: -thumbSize / 2,\n                  marginTop: -thumbSize / 2,\n                  borderRadius: \"50%\",\n                  background: p.thumb,\n                  border: `${Math.max(2, thumbSize * 0.16)}px solid ${accentColor}`,\n                  boxSizing: \"border-box\",\n                  boxShadow: focusIdx === i || dragIdx === i ? `0 0 0 4px color-mix(in srgb, ${accentColor} 28%, transparent)` : \"0 2px 8px rgba(0,0,0,0.35)\",\n                  transform: dragIdx === i ? \"scale(1.12)\" : \"scale(1)\",\n                  transition: `${dragIdx === null ? \"left 0.15s ease, \" : \"\"}transform 0.15s ease, box-shadow 0.15s ease`,\n                  zIndex: active ? 3 : 2,\n                }}\n              >\n                <AnimatePresence>\n                  {showTooltip && active && (\n                    <motion.div\n                      className=\"pointer-events-none absolute left-1/2 rounded-md px-2 py-1 font-semibold whitespace-nowrap tabular-nums\"\n                      style={{ bottom: thumbSize + 6, x: \"-50%\", background: p.tooltipBg, color: p.tooltipText, fontSize: 12 }}\n                      initial={{ opacity: 0, y: 4, scale: 0.9 }}\n                      animate={{ opacity: 1, y: 0, scale: 1 }}\n                      exit={{ opacity: 0, y: 4, scale: 0.9 }}\n                      transition={{ duration: 0.14 }}\n                    >\n                      {format(v)}\n                    </motion.div>\n                  )}\n                </AnimatePresence>\n              </div>\n            );\n          })}\n        </div>\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}