{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "segmented-control",
  "title": "Segmented Control",
  "description": "A compact radio-style switch between a few options with a sliding animated thumb, solid or soft styles, icons, icon-only mode, vertical orientation and arrow-key navigation.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/segmented-control/segmented-control.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion } 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 type SegmentedControlSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface SegmentedOption {\n  value: string;\n  label: string;\n  icon?: React.ReactNode;\n  disabled?: boolean;\n}\n\nexport interface SegmentedControlProps {\n  options?: SegmentedOption[];\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (value: string) => void;\n  variant?: \"solid\" | \"soft\";\n  orientation?: \"horizontal\" | \"vertical\";\n  fullWidth?: boolean;\n  iconOnly?: boolean;\n  label?: string;\n  size?: SegmentedControlSize;\n  theme?: \"dark\" | \"light\";\n  disabled?: boolean;\n  className?: string;\n  \"aria-label\"?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.55)\", track: \"rgba(255,255,255,0.05)\", border: \"rgba(255,255,255,0.1)\", hover: \"rgba(245,244,241,0.9)\", thumb: \"#F5F4F1\", thumbText: \"#0A0A0A\", soft: \"rgba(255,255,255,0.12)\", softBorder: \"rgba(255,255,255,0.14)\", focus: \"rgba(245,244,241,0.85)\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.55)\", track: \"rgba(10,10,10,0.05)\", border: \"rgba(10,10,10,0.12)\", hover: \"#0A0A0A\", thumb: \"#0A0A0A\", thumbText: \"#FFFFFF\", soft: \"#FFFFFF\", softBorder: \"rgba(10,10,10,0.14)\", focus: \"rgba(10,10,10,0.85)\" },\n};\n\nconst SIZES: Record<SegmentedControlSize, { font: number; h: number; padX: number; radius: number; gap: number; icon: number }> = {\n  sm: { font: 13, h: 30, padX: 12, radius: 10, gap: 6, icon: 14 },\n  md: { font: 14.5, h: 36, padX: 16, radius: 12, gap: 7, icon: 16 },\n  lg: { font: 16, h: 44, padX: 20, radius: 14, gap: 8, icon: 18 },\n};\n\nconst DEFAULT_OPTIONS: SegmentedOption[] = [\n  { value: \"day\", label: \"Day\" },\n  { value: \"week\", label: \"Week\" },\n  { value: \"month\", label: \"Month\" },\n  { value: \"year\", label: \"Year\" },\n];\n\nexport function SegmentedControl({\n  options = DEFAULT_OPTIONS,\n  value,\n  defaultValue,\n  onValueChange,\n  variant = \"solid\",\n  orientation = \"horizontal\",\n  fullWidth = false,\n  iconOnly = false,\n  label,\n  size = \"md\",\n  theme = \"dark\",\n  disabled = false,\n  className,\n  \"aria-label\": ariaLabel,\n}: SegmentedControlProps) {\n  const p = PALETTES[theme];\n  const s = SIZES[size];\n  const uid = React.useId();\n  const refs = React.useRef<(HTMLButtonElement | null)[]>([]);\n  const controlled = value !== undefined;\n  const [internal, setInternal] = React.useState(defaultValue ?? options.find((o) => !o.disabled)?.value ?? \"\");\n  const [hovered, setHovered] = React.useState<string | null>(null);\n  const current = controlled ? value : internal;\n  const vertical = orientation === \"vertical\";\n  const pad = 4;\n\n  const select = (v: string) => {\n    if (v === current) return;\n    if (!controlled) setInternal(v);\n    onValueChange?.(v);\n  };\n\n  const onKeyDown = (e: React.KeyboardEvent, index: number) => {\n    let dir = 0;\n    if (e.key === \"ArrowRight\" || e.key === \"ArrowDown\") dir = 1;\n    else if (e.key === \"ArrowLeft\" || e.key === \"ArrowUp\") dir = -1;\n    let target = -1;\n    if (dir !== 0) {\n      for (let step = 1; step <= options.length; step++) {\n        const i = (index + dir * step + options.length * 2) % options.length;\n        if (!options[i].disabled) { target = i; break; }\n      }\n    } else if (e.key === \"Home\") target = options.findIndex((o) => !o.disabled);\n    else if (e.key === \"End\") target = options.length - 1 - [...options].reverse().findIndex((o) => !o.disabled);\n    if (target < 0) return;\n    e.preventDefault();\n    refs.current[target]?.focus();\n    select(options[target].value);\n  };\n\n  const hasCurrent = options.some((o) => o.value === current && !o.disabled);\n  const tabStop = hasCurrent ? current : options.find((o) => !o.disabled)?.value;\n\n  return (\n    <div className={cn(\"inline-flex flex-col gap-2\", fullWidth && \"w-full\", className)} style={{ fontFamily: \"Inter, sans-serif\", opacity: disabled ? 0.5 : 1 }}>\n      {label && (\n        <span id={`${uid}-label`} className=\"font-semibold tracking-[-0.01em]\" style={{ color: p.text, fontSize: s.font }}>\n          {label}\n        </span>\n      )}\n      <div\n        role=\"radiogroup\"\n        aria-labelledby={label ? `${uid}-label` : undefined}\n        aria-label={label ? undefined : (ariaLabel ?? \"Options\")}\n        aria-orientation={orientation}\n        className={cn(\"relative\", vertical ? \"inline-flex flex-col\" : \"inline-flex\", fullWidth && \"w-full\")}\n        style={{ padding: pad, gap: 2, borderRadius: s.radius + pad, background: p.track, border: `1px solid ${p.border}`, pointerEvents: disabled ? \"none\" : undefined }}\n      >\n        {options.map((o, i) => {\n          const selected = o.value === current;\n          const isHover = hovered === o.value && !selected && !o.disabled;\n          const textColor = selected ? (variant === \"solid\" ? p.thumbText : p.text) : isHover ? p.hover : p.muted;\n          return (\n            <button\n              key={o.value}\n              ref={(el) => {\n                refs.current[i] = el;\n              }}\n              type=\"button\"\n              role=\"radio\"\n              aria-checked={selected}\n              aria-label={iconOnly ? o.label : undefined}\n              title={iconOnly ? o.label : undefined}\n              disabled={o.disabled || disabled}\n              tabIndex={o.value === tabStop ? 0 : -1}\n              onClick={() => select(o.value)}\n              onKeyDown={(e) => onKeyDown(e, i)}\n              onMouseEnter={() => setHovered(o.value)}\n              onMouseLeave={() => setHovered(null)}\n              className={cn(\"relative flex cursor-pointer items-center justify-center border-none bg-transparent font-semibold outline-none focus-visible:ring-2 disabled:cursor-not-allowed disabled:opacity-40\", fullWidth && !vertical && \"flex-1\", vertical && \"w-full justify-start\")}\n              style={{ height: s.h, padding: iconOnly ? `0 ${Math.round(s.padX * 0.65)}px` : `0 ${s.padX}px`, borderRadius: s.radius, gap: s.gap, fontSize: s.font, color: textColor, transition: \"color 0.2s ease\", [\"--tw-ring-color\" as string]: p.focus }}\n            >\n              {selected && (\n                <motion.span\n                  layoutId={`${uid}-thumb`}\n                  aria-hidden=\"true\"\n                  className=\"absolute inset-0\"\n                  style={{ borderRadius: s.radius, background: variant === \"solid\" ? p.thumb : p.soft, border: variant === \"soft\" ? `1px solid ${p.softBorder}` : \"1px solid transparent\", boxShadow: variant === \"solid\" ? \"0 2px 10px rgba(0,0,0,0.25)\" : theme === \"light\" ? \"0 1px 4px rgba(0,0,0,0.1)\" : \"none\" }}\n                  transition={{ type: \"spring\", stiffness: 520, damping: 38 }}\n                />\n              )}\n              {o.icon && (\n                <span className=\"relative z-10 flex shrink-0 items-center justify-center\" style={{ width: s.icon, height: s.icon }}>\n                  {o.icon}\n                </span>\n              )}\n              {!iconOnly && <span className=\"relative z-10 whitespace-nowrap\">{o.label}</span>}\n            </button>\n          );\n        })}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}