{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "content-switch",
  "title": "Content Switch",
  "description": "A switch that swaps the content below it: a pill or underline thumb slides to the chosen option, the new panel slides in from that side (or fades or blurs in), and the box eases to the new height instead of jumping.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/content-switch/content-switch.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence, useReducedMotion } 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 ContentSwitchOption {\n  value: string;\n  label: string;\n  icon?: React.ReactNode;\n  content: React.ReactNode;\n}\n\nexport interface ContentSwitchProps {\n  options?: ContentSwitchOption[];\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (value: string) => void;\n  /** pill: a filled thumb slides behind the labels. underline: a line slides under them. */\n  variant?: \"pill\" | \"underline\";\n  /** How panels change: slide in from the side of the new option, fade, or blur. */\n  transition?: \"slide\" | \"fade\" | \"blur\";\n  align?: \"start\" | \"center\";\n  label?: string;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.55)\", seg: \"rgba(255,255,255,0.05)\", border: \"rgba(255,255,255,0.12)\", thumb: \"#F5F4F1\", thumbText: \"#0A0A0A\", line: \"rgba(255,255,255,0.1)\", panel: \"#0E0E0E\", code: \"#111111\", focus: \"rgba(245,244,241,0.85)\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.55)\", seg: \"rgba(10,10,10,0.04)\", border: \"rgba(10,10,10,0.12)\", thumb: \"#0A0A0A\", thumbText: \"#FFFFFF\", line: \"rgba(10,10,10,0.1)\", panel: \"#FFFFFF\", code: \"#F6F6F4\", focus: \"rgba(10,10,10,0.85)\" },\n};\n\nfunction demoOptions(p: (typeof PALETTES)[\"dark\"]): ContentSwitchOption[] {\n  return [\n    {\n      value: \"preview\",\n      label: \"Preview\",\n      content: (\n        <div className=\"flex flex-col items-center gap-3 py-8\">\n          <span className=\"flex items-center justify-center rounded-full text-[15px] font-semibold\" style={{ width: 52, height: 52, background: p.thumb, color: p.thumbText }}>\n            MC\n          </span>\n          <span className=\"text-[16px] font-semibold\" style={{ color: p.text }}>\n            Maya Chen\n          </span>\n          <span className=\"text-[13px]\" style={{ color: p.muted }}>\n            Head of Design · Northwind\n          </span>\n          <span className=\"mt-2 rounded-full text-[13px] font-semibold\" style={{ padding: \"8px 16px\", background: p.thumb, color: p.thumbText }}>\n            Follow\n          </span>\n        </div>\n      ),\n    },\n    {\n      value: \"code\",\n      label: \"Code\",\n      content: (\n        <pre className=\"m-0 overflow-x-auto rounded-xl text-[12.5px] leading-relaxed\" style={{ padding: 16, background: p.code, color: p.text, border: `1px solid ${p.line}` }}>\n          <code>{`<ProfileCard\n  name=\"Maya Chen\"\n  role=\"Head of Design · Northwind\"\n  action=\"Follow\"\n/>`}</code>\n        </pre>\n      ),\n    },\n    {\n      value: \"notes\",\n      label: \"Notes\",\n      content: (\n        <ul className=\"m-0 flex list-disc flex-col gap-2 py-2 pl-5 text-[14px] leading-relaxed\" style={{ color: p.muted }}>\n          <li>Avatar falls back to initials when there is no photo.</li>\n          <li>The action button is optional; hide it on your own profile.</li>\n          <li>Long names truncate after one line.</li>\n        </ul>\n      ),\n    },\n  ];\n}\n\nexport function ContentSwitch({ options, value, defaultValue, onValueChange, variant = \"pill\", transition = \"slide\", align = \"start\", label = \"View\", theme = \"dark\", className }: ContentSwitchProps) {\n  const p = PALETTES[theme];\n  const uid = React.useId();\n  const reduce = Boolean(useReducedMotion());\n  const opts = options ?? demoOptions(p);\n  const [internal, setInternal] = React.useState(defaultValue ?? opts[0]?.value);\n  const current = value ?? internal;\n  const idx = Math.max(0, opts.findIndex((o) => o.value === current));\n  const [dir, setDir] = React.useState(1);\n  const bodyRef = React.useRef<HTMLDivElement>(null);\n  const [h, setH] = React.useState<number | \"auto\">(\"auto\");\n\n  // Animate the container to each panel's natural height.\n  React.useLayoutEffect(() => {\n    const el = bodyRef.current;\n    if (!el) return;\n    const ro = new ResizeObserver(() => setH(el.offsetHeight));\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, []);\n\n  const select = (i: number) => {\n    const v = opts[i].value;\n    if (v === current) return;\n    setDir(i > idx ? 1 : -1);\n    if (value === undefined) setInternal(v);\n    onValueChange?.(v);\n  };\n\n  const onKey = (e: React.KeyboardEvent) => {\n    const d = e.key === \"ArrowRight\" ? 1 : e.key === \"ArrowLeft\" ? -1 : 0;\n    if (!d) return;\n    e.preventDefault();\n    const n = (idx + d + opts.length) % opts.length;\n    select(n);\n    (e.currentTarget.children[n] as HTMLElement | undefined)?.focus();\n  };\n\n  const pill = variant === \"pill\";\n  const fx = {\n    slide: { enter: (d: number) => ({ opacity: 0, x: d * 36 }), center: { opacity: 1, x: 0, filter: \"blur(0px)\" }, exit: (d: number) => ({ opacity: 0, x: d * -36 }) },\n    fade: { enter: () => ({ opacity: 0 }), center: { opacity: 1, x: 0, filter: \"blur(0px)\" }, exit: () => ({ opacity: 0 }) },\n    blur: { enter: () => ({ opacity: 0, filter: \"blur(8px)\" }), center: { opacity: 1, x: 0, filter: \"blur(0px)\" }, exit: () => ({ opacity: 0, filter: \"blur(8px)\" }) },\n  }[reduce ? \"fade\" : transition];\n\n  return (\n    <div className={cn(\"flex w-full flex-col\", className)} style={{ gap: 16, fontFamily: \"Inter, sans-serif\", color: p.text }}>\n      <div role=\"tablist\" aria-label={label} onKeyDown={onKey} className={cn(\"relative flex\", align === \"center\" && \"self-center\", pill ? \"self-start rounded-full\" : \"w-full\")} style={pill ? { padding: 4, gap: 2, background: p.seg, border: `1px solid ${p.border}`, alignSelf: align === \"center\" ? \"center\" : \"flex-start\" } : { gap: 22, borderBottom: `1px solid ${p.line}` }}>\n        {opts.map((o, i) => {\n          const on = i === idx;\n          return (\n            <button\n              key={o.value}\n              type=\"button\"\n              role=\"tab\"\n              id={`${uid}-tab-${o.value}`}\n              aria-selected={on}\n              aria-controls={`${uid}-panel`}\n              tabIndex={on ? 0 : -1}\n              onClick={() => select(i)}\n              className=\"relative flex cursor-pointer items-center border-none bg-transparent text-[14px] font-semibold outline-none focus-visible:ring-2\"\n              style={{ gap: 7, height: pill ? 34 : 40, padding: pill ? \"0 16px\" : \"0 2px\", borderRadius: pill ? 999 : 6, color: on ? (pill ? p.thumbText : p.text) : p.muted, transition: \"color 0.2s ease\", [\"--tw-ring-color\" as string]: p.focus }}\n            >\n              {on && (pill ? <motion.span layoutId={`${uid}-thumb`} className=\"absolute inset-0 rounded-full\" style={{ background: p.thumb }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 500, damping: 36 }} /> : <motion.span layoutId={`${uid}-line`} className=\"absolute right-0 -bottom-px left-0 block\" style={{ height: 2, background: p.thumb, borderRadius: 2 }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 500, damping: 36 }} />)}\n              {o.icon && <span className=\"relative flex\">{o.icon}</span>}\n              <span className=\"relative\">{o.label}</span>\n            </button>\n          );\n        })}\n      </div>\n      <motion.div className=\"relative overflow-hidden\" initial={false} animate={{ height: h }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 320, damping: 34 }}>\n        <div ref={bodyRef}>\n          <AnimatePresence mode=\"popLayout\" initial={false} custom={dir}>\n            <motion.div key={current} id={`${uid}-panel`} role=\"tabpanel\" aria-labelledby={`${uid}-tab-${current}`} custom={dir} variants={fx} initial=\"enter\" animate=\"center\" exit=\"exit\" transition={{ duration: reduce ? 0.12 : 0.3, ease: [0.22, 1, 0.36, 1] }}>\n              {opts[idx]?.content}\n            </motion.div>\n          </AnimatePresence>\n        </div>\n      </motion.div>\n    </div>\n  );\n}\n\nexport default ContentSwitch;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}