{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "slider",
  "title": "Slider",
  "description": "An input where the user selects a value from within a given range, built on Base UI.",
  "dependencies": [
    "@base-ui/react"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "registry/base/ui/slider.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { DirectionProvider } from \"@base-ui/react/direction-provider\"\nimport { Slider as SliderPrimitive } from \"@base-ui/react/slider\"\n\nimport { cn } from \"@/lib/utils\"\n\n/**\n * Base UI's Slider resolves drag and keyboard direction through its own\n * DirectionContext (default \"ltr\"), not the DOM `dir` attribute — so a\n * slider rendered under an ambient `dir=\"rtl\"` wrapper still drags and\n * responds to arrow keys as if LTR unless told otherwise. Measure the\n * ambient computed direction and feed it into Base UI's own\n * DirectionProvider, the same fix already applied to\n * ContextMenu/Menubar/Tooltip in this repo.\n */\nfunction useAmbientDirection() {\n  const ref = React.useRef<HTMLDivElement>(null)\n  const [dir, setDir] = React.useState<\"ltr\" | \"rtl\">(\"ltr\")\n\n  React.useEffect(() => {\n    function update() {\n      if (!ref.current) return\n      setDir(getComputedStyle(ref.current).direction === \"rtl\" ? \"rtl\" : \"ltr\")\n    }\n\n    update()\n\n    const observer = new MutationObserver(update)\n    observer.observe(document.documentElement, {\n      attributes: true,\n      attributeFilter: [\"dir\"],\n      subtree: true,\n    })\n\n    return () => observer.disconnect()\n  }, [])\n\n  return { ref, dir }\n}\n\nfunction Slider({\n  className,\n  defaultValue,\n  value,\n  onValueChange,\n  min = 0,\n  max = 100,\n  ...props\n}: SliderPrimitive.Root.Props) {\n  const { ref: controlRef, dir } = useAmbientDirection()\n\n  const _values = Array.isArray(value)\n    ? value\n    : Array.isArray(defaultValue)\n      ? defaultValue\n      : [min, max]\n\n  const isArrayValue = Array.isArray(value) || Array.isArray(defaultValue)\n\n  // Base UI's pointer-drag path reports a bare number for a single-thumb\n  // slider even when value/defaultValue is an array — keyboard input goes\n  // through a different internal code path that gets this right, so the\n  // shape only breaks on drag. Normalize to the shape the consumer opted\n  // into so `value[0]` never turns undefined mid-drag.\n  const handleValueChange: SliderPrimitive.Root.Props[\"onValueChange\"] = (\n    next,\n    eventDetails\n  ) => {\n    const normalized: typeof next =\n      isArrayValue && !Array.isArray(next) ? ([next] as typeof next) : next\n    onValueChange?.(normalized, eventDetails)\n  }\n\n  return (\n    <DirectionProvider direction={dir}>\n      <SliderPrimitive.Root\n        data-slot=\"slider\"\n        defaultValue={defaultValue}\n        value={value}\n        onValueChange={handleValueChange}\n        min={min}\n        max={max}\n        thumbAlignment=\"edge\"\n        className={cn(\"data-horizontal:w-full data-vertical:h-full\", className)}\n        {...props}\n      >\n        <SliderPrimitive.Control\n          ref={controlRef}\n          className=\"relative flex w-full touch-none items-center select-none data-disabled:opacity-50 data-vertical:h-full data-vertical:min-h-40 data-vertical:w-auto data-vertical:flex-col\"\n        >\n          <SliderPrimitive.Track\n            data-slot=\"slider-track\"\n            className=\"relative grow overflow-hidden rounded-full bg-primary/20 select-none data-horizontal:h-1.5 data-horizontal:w-full data-vertical:h-full data-vertical:w-1.5\"\n          >\n            <SliderPrimitive.Indicator\n              data-slot=\"slider-range\"\n              className=\"bg-primary select-none data-horizontal:h-full data-vertical:w-full\"\n            />\n          </SliderPrimitive.Track>\n          {Array.from({ length: _values.length }, (_, index) => (\n            <SliderPrimitive.Thumb\n              data-slot=\"slider-thumb\"\n              key={index}\n              className=\"relative block size-4 shrink-0 touch-manipulation rounded-full border-2 border-primary bg-background ring-ring/50 transition-[color,box-shadow] select-none after:absolute after:-inset-2.5 hover:ring-3 focus-visible:ring-3 focus-visible:outline-hidden active:ring-3 disabled:pointer-events-none disabled:opacity-50\"\n            />\n          ))}\n        </SliderPrimitive.Control>\n      </SliderPrimitive.Root>\n    </DirectionProvider>\n  )\n}\n\nexport { Slider }\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}