{
  "name": "slider",
  "type": "registry:ui",
  "framework": "react",
  "title": "Slider",
  "description": "A range control with a filled track, a grabber and optional labelled marks, for volumes and thresholds.",
  "dependencies": [
    "radix-ui"
  ],
  "files": [
    {
      "path": "ui/slider.tsx",
      "content": "\"use client\"\n\nimport { Slider as SliderPrimitive } from \"radix-ui\"\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\n/** A named point on the track, drawn above it. */\nexport interface SliderMark {\n  value: number\n  /** What the mark says. Omitted, it shows the number. */\n  label?: string\n}\n\nexport interface SliderProps extends React.ComponentPropsWithoutRef<\n  typeof SliderPrimitive.Root\n> {\n  /** Labelled points along the track. */\n  marks?: readonly SliderMark[]\n}\n\n/*\n * Radix owns the behaviour: pointer and touch dragging, arrow keys, Page Up\n * and Page Down, Home and End, and the hidden input a form reads. Only the\n * look is newt/ui's. The value is an array, one entry per grabber.\n */\nconst Slider = React.forwardRef<\n  React.ComponentRef<typeof SliderPrimitive.Root>,\n  SliderProps\n>(\n  (\n    {\n      className,\n      marks,\n      min = 0,\n      max = 100,\n      value,\n      defaultValue,\n      disabled,\n      \"aria-label\": ariaLabel,\n      \"aria-labelledby\": ariaLabelledby,\n      \"aria-valuetext\": ariaValueText,\n      ...props\n    },\n    ref\n  ) => {\n    const span = max - min\n    const ratioOf = (point: number) =>\n      span === 0 ? 0 : Math.min(1, Math.max(0, (point - min) / span))\n    const thumbs = (value ?? defaultValue ?? [min]).length\n    /*\n     * `role=\"slider\"` is on the grabber, so that is where the name goes. Two\n     * grabbers keep Radix's \"Minimum\" and \"Maximum\", and the name moves to a\n     * group around them.\n     */\n    const single = thumbs === 1\n\n    return (\n      <div\n        className={cn(\n          \"flex w-full flex-col gap-1\",\n          disabled && \"opacity-50\",\n          className\n        )}\n      >\n        {marks === undefined || marks.length === 0 ? null : (\n          // Inset by half a grabber, which is where the grabber's centre stops.\n          <div aria-hidden=\"true\" className=\"relative mx-[5px] h-[22px]\">\n            {marks.map((mark) => (\n              <span\n                key={mark.value}\n                className=\"absolute top-0 flex translate-x-[calc(var(--newt-dir)*-50%)] flex-col items-center gap-0.5 text-[10px] font-bold leading-3 text-newt-text-muted after:h-1.5 after:w-0.5 after:rounded-full after:bg-newt-bg-active after:content-['']\"\n                style={{ insetInlineStart: `${ratioOf(mark.value) * 100}%` }}\n              >\n                {mark.label ?? mark.value}\n              </span>\n            ))}\n          </div>\n        )}\n        <SliderPrimitive.Root\n          ref={ref}\n          min={min}\n          max={max}\n          value={value}\n          defaultValue={defaultValue}\n          disabled={disabled}\n          role={single ? undefined : \"group\"}\n          aria-label={single ? undefined : ariaLabel}\n          aria-labelledby={single ? undefined : ariaLabelledby}\n          className=\"relative flex h-6 w-full cursor-pointer touch-none select-none items-center data-[disabled]:cursor-not-allowed\"\n          {...props}\n        >\n          <SliderPrimitive.Track className=\"relative h-2 w-full grow overflow-hidden rounded-full bg-newt-bg-active\">\n            <SliderPrimitive.Range className=\"absolute h-full bg-newt-brand\" />\n          </SliderPrimitive.Track>\n          {Array.from({ length: thumbs }, (_, index) => (\n            <SliderPrimitive.Thumb\n              key={index}\n              /* An explicit undefined would replace the \"Minimum\" and \"Maximum\" names. */\n              {...(single\n                ? {\n                    \"aria-label\": ariaLabel,\n                    \"aria-labelledby\": ariaLabelledby,\n                    \"aria-valuetext\": ariaValueText,\n                  }\n                : {})}\n              className=\"block h-6 w-2.5 rounded-[var(--newt-radius-sm)] border border-newt-border bg-newt-on-accent shadow-elevation-low focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-newt-text-link\"\n            />\n          ))}\n        </SliderPrimitive.Root>\n      </div>\n    )\n  }\n)\nSlider.displayName = \"Slider\"\n\nexport { Slider }\n",
      "type": "registry:ui"
    }
  ]
}