{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "segmented-control",
  "title": "Segmented Control",
  "author": "VenusUI",
  "description": "A single-choice switcher with a highlight that slides to the selected option.",
  "dependencies": [
    "motion"
  ],
  "files": [
    {
      "path": "registry/default/ui/segmented-control.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { LayoutGroup, motion, useReducedMotion } from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface SegmentedControlOption {\n  value: string\n  label: React.ReactNode\n  disabled?: boolean\n}\n\ninterface SegmentedControlProps {\n  options: SegmentedControlOption[]\n  /** Controlled value. */\n  value?: string\n  /** Initial value when uncontrolled. Defaults to the first option. */\n  defaultValue?: string\n  onValueChange?: (value: string) => void\n  /** Accessible name for the group, e.g. \"View\". */\n  label: string\n  className?: string\n}\n\n/**\n * A single-choice control with a highlight that slides to the selected\n * option. Behaves like a radio group: Tab focuses the selected option, and\n * the arrow keys, Home and End move the selection.\n */\nfunction SegmentedControl({\n  options,\n  value: controlled,\n  defaultValue,\n  onValueChange,\n  label,\n  className,\n}: SegmentedControlProps) {\n  const [uncontrolled, setUncontrolled] = React.useState(defaultValue ?? options[0]?.value)\n  const value = controlled ?? uncontrolled\n  const reduceMotion = useReducedMotion()\n  const groupId = React.useId()\n  const refs = React.useRef<(HTMLButtonElement | null)[]>([])\n\n  function select(next: string) {\n    if (controlled === undefined) setUncontrolled(next)\n    onValueChange?.(next)\n  }\n\n  function onKeyDown(event: React.KeyboardEvent, index: number) {\n    const enabled = options.map((o, i) => (o.disabled ? -1 : i)).filter((i) => i >= 0)\n    const position = enabled.indexOf(index)\n    const target =\n      event.key === \"ArrowRight\" || event.key === \"ArrowDown\" ? enabled[(position + 1) % enabled.length]\n      : event.key === \"ArrowLeft\" || event.key === \"ArrowUp\" ? enabled[(position - 1 + enabled.length) % enabled.length]\n      : event.key === \"Home\" ? enabled[0]\n      : event.key === \"End\" ? enabled[enabled.length - 1]\n      : undefined\n    if (target === undefined) return\n    event.preventDefault()\n    const option = options[target]\n    if (!option) return\n    select(option.value)\n    refs.current[target]?.focus()\n  }\n\n  return (\n    <LayoutGroup id={groupId}>\n      <div\n        role=\"radiogroup\"\n        aria-label={label}\n        data-slot=\"segmented-control\"\n        className={cn(\"inline-flex items-center gap-1 rounded-lg border bg-muted/50 p-1\", className)}\n      >\n        {options.map((option, index) => {\n          const selected = option.value === value\n          return (\n            <button\n              key={option.value}\n              ref={(node) => {\n                refs.current[index] = node\n              }}\n              type=\"button\"\n              role=\"radio\"\n              aria-checked={selected}\n              tabIndex={selected ? 0 : -1}\n              disabled={option.disabled}\n              onClick={() => select(option.value)}\n              onKeyDown={(event) => onKeyDown(event, index)}\n              className={cn(\n                \"relative rounded-md px-3 py-1.5 text-sm font-medium transition-colors outline-none focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50\",\n                selected ? \"text-foreground\" : \"text-muted-foreground hover:text-foreground\"\n              )}\n            >\n              {selected ? (\n                <motion.span\n                  layoutId=\"segmented-control-indicator\"\n                  aria-hidden=\"true\"\n                  className=\"absolute inset-0 rounded-md bg-background shadow-xs\"\n                  transition={reduceMotion ? { duration: 0 } : { type: \"spring\", stiffness: 500, damping: 40 }}\n                />\n              ) : null}\n              <span className=\"relative\">{option.label}</span>\n            </button>\n          )\n        })}\n      </div>\n    </LayoutGroup>\n  )\n}\n\nexport { SegmentedControl, type SegmentedControlOption, type SegmentedControlProps }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "navigation",
    "inputs",
    "animations"
  ],
  "type": "registry:ui"
}