{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-group",
  "title": "Button Group",
  "description": "Buttons joined into one control: plain action groups like Previous / Today / Next, a single-choice group whose fill slides between options, multi-toggle groups, and a split button whose chevron opens a menu of alternative actions.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/button-group/button-group.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\ntype Theme = \"dark\" | \"light\";\nexport type ButtonGroupSize = \"sm\" | \"md\" | \"lg\";\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.55)\", border: \"rgba(255,255,255,0.14)\", bg: \"rgba(255,255,255,0.03)\", hover: \"rgba(255,255,255,0.07)\", sel: \"#F5F4F1\", onSel: \"#0A0A0A\", menu: \"#141414\", menuBorder: \"rgba(255,255,255,0.1)\", focus: \"rgba(245,244,241,0.85)\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.55)\", border: \"rgba(10,10,10,0.16)\", bg: \"#FFFFFF\", hover: \"rgba(10,10,10,0.05)\", sel: \"#0A0A0A\", onSel: \"#FFFFFF\", menu: \"#FFFFFF\", menuBorder: \"rgba(10,10,10,0.1)\", focus: \"rgba(10,10,10,0.85)\" },\n};\n\nconst SIZES: Record<ButtonGroupSize, { h: number; font: number; pad: number; radius: number; icon: number }> = {\n  sm: { h: 32, font: 13, pad: 11, radius: 9, icon: 14 },\n  md: { h: 38, font: 14, pad: 14, radius: 11, icon: 16 },\n  lg: { h: 46, font: 15.5, pad: 18, radius: 13, icon: 18 },\n};\n\nexport interface ButtonGroupItem {\n  id: string;\n  label?: React.ReactNode;\n  icon?: React.ReactNode;\n  /** Needed for icon-only items. */\n  ariaLabel?: string;\n  disabled?: boolean;\n  onClick?: () => void;\n}\n\nexport interface ButtonGroupProps {\n  items: ButtonGroupItem[];\n  /** none: plain actions. single: one pressed at a time (a fill slides between them). multiple: each toggles. */\n  selection?: \"none\" | \"single\" | \"multiple\";\n  value?: string[];\n  defaultValue?: string[];\n  onValueChange?: (value: string[]) => void;\n  orientation?: \"horizontal\" | \"vertical\";\n  size?: ButtonGroupSize;\n  theme?: Theme;\n  ariaLabel?: string;\n  className?: string;\n}\n\nexport function ButtonGroup({ items, selection = \"none\", value, defaultValue = [], onValueChange, orientation = \"horizontal\", size = \"md\", theme = \"dark\", ariaLabel, className }: ButtonGroupProps) {\n  const p = PALETTES[theme];\n  const s = SIZES[size];\n  const uid = React.useId();\n  const reduce = Boolean(useReducedMotion());\n  const [internal, setInternal] = React.useState(defaultValue);\n  const sel = value ?? internal;\n  const vertical = orientation === \"vertical\";\n\n  const press = (it: ButtonGroupItem) => {\n    it.onClick?.();\n    if (selection === \"none\") return;\n    const next = selection === \"single\" ? [it.id] : sel.includes(it.id) ? sel.filter((v) => v !== it.id) : [...sel, it.id];\n    if (value === undefined) setInternal(next);\n    onValueChange?.(next);\n  };\n\n  return (\n    <div\n      role=\"group\"\n      aria-label={ariaLabel}\n      className={cn(\"inline-flex overflow-hidden\", vertical ? \"flex-col\" : \"flex-row\", className)}\n      style={{ borderRadius: s.radius, border: `1px solid ${p.border}`, background: p.bg, fontFamily: \"Inter, sans-serif\" }}\n    >\n      {items.map((it, i) => {\n        const on = sel.includes(it.id);\n        return (\n          <motion.button\n            key={it.id}\n            type=\"button\"\n            disabled={it.disabled}\n            aria-label={it.ariaLabel}\n            aria-pressed={selection === \"none\" ? undefined : on}\n            onClick={() => press(it)}\n            whileTap={reduce || it.disabled ? undefined : { scale: 0.96 }}\n            className={cn(\"relative flex cursor-pointer items-center justify-center font-medium whitespace-nowrap outline-none focus-visible:z-10 focus-visible:ring-2 focus-visible:ring-inset disabled:cursor-not-allowed disabled:opacity-40\", !on && \"hover:bg-[var(--bg-hover)]\")}\n            style={{\n              height: s.h,\n              minWidth: s.h,\n              padding: it.label ? `0 ${s.pad}px` : 0,\n              gap: 7,\n              fontSize: s.font,\n              color: on ? p.onSel : p.text,\n              borderLeft: !vertical && i > 0 ? `1px solid ${p.border}` : undefined,\n              borderTop: vertical && i > 0 ? `1px solid ${p.border}` : undefined,\n              transition: \"color 0.2s ease, background-color 0.15s ease\",\n              [\"--bg-hover\" as string]: p.hover,\n              [\"--tw-ring-color\" as string]: p.focus,\n            }}\n          >\n            {on && selection === \"single\" && <motion.span layoutId={`${uid}-sel`} aria-hidden=\"true\" className=\"absolute inset-0\" style={{ background: p.sel }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 500, damping: 38 }} />}\n            {on && selection === \"multiple\" && <motion.span aria-hidden=\"true\" className=\"absolute inset-0\" style={{ background: p.sel }} initial={reduce ? false : { opacity: 0 }} animate={{ opacity: 1 }} />}\n            {it.icon && (\n              <span className=\"relative flex [&>svg]:h-full [&>svg]:w-full\" style={{ width: s.icon, height: s.icon }}>\n                {it.icon}\n              </span>\n            )}\n            {it.label && <span className=\"relative\">{it.label}</span>}\n          </motion.button>\n        );\n      })}\n    </div>\n  );\n}\n\nexport interface SplitButtonOption {\n  id: string;\n  label: string;\n  description?: string;\n}\n\nexport interface SplitButtonProps {\n  options: SplitButtonOption[];\n  /** The option the main button runs. */\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (id: string) => void;\n  /** Runs the chosen option. */\n  onAction?: (id: string) => void;\n  icon?: React.ReactNode;\n  size?: ButtonGroupSize;\n  theme?: Theme;\n  className?: string;\n}\n\n/** A main action with a chevron that opens a menu of alternatives; picking one makes it the main action. */\nexport function SplitButton({ options, value, defaultValue, onValueChange, onAction, icon, size = \"md\", theme = \"dark\", className }: SplitButtonProps) {\n  const p = PALETTES[theme];\n  const s = SIZES[size];\n  const uid = React.useId();\n  const reduce = Boolean(useReducedMotion());\n  const [internal, setInternal] = React.useState(defaultValue ?? options[0]?.id);\n  const current = value ?? internal;\n  const chosen = options.find((o) => o.id === current) ?? options[0];\n  const [open, setOpen] = React.useState(false);\n  const [active, setActive] = React.useState(0);\n  const root = React.useRef<HTMLDivElement>(null);\n  const trigger = React.useRef<HTMLButtonElement>(null);\n\n  React.useEffect(() => {\n    if (!open) return;\n    const away = (e: PointerEvent) => !root.current?.contains(e.target as Node) && setOpen(false);\n    document.addEventListener(\"pointerdown\", away);\n    return () => document.removeEventListener(\"pointerdown\", away);\n  }, [open]);\n\n  const pick = (o: SplitButtonOption) => {\n    if (value === undefined) setInternal(o.id);\n    onValueChange?.(o.id);\n    setOpen(false);\n    trigger.current?.focus();\n  };\n\n  const onKey = (e: React.KeyboardEvent) => {\n    if (e.key === \"Escape\") {\n      setOpen(false);\n      trigger.current?.focus();\n    } else if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n      e.preventDefault();\n      if (!open) {\n        setActive(Math.max(0, options.indexOf(chosen)));\n        setOpen(true);\n        return;\n      }\n      setActive((a) => (a + (e.key === \"ArrowDown\" ? 1 : options.length - 1)) % options.length);\n    } else if ((e.key === \"Enter\" || e.key === \" \") && open) {\n      e.preventDefault();\n      pick(options[active]);\n    }\n  };\n\n  return (\n    <div ref={root} className={cn(\"relative inline-flex\", className)} style={{ fontFamily: \"Inter, sans-serif\" }} onKeyDown={onKey}>\n      <div className=\"inline-flex overflow-hidden\" style={{ borderRadius: s.radius, background: p.sel }}>\n        <motion.button\n          type=\"button\"\n          onClick={() => onAction?.(chosen.id)}\n          whileTap={reduce ? undefined : { scale: 0.97 }}\n          className=\"relative flex cursor-pointer items-center font-semibold whitespace-nowrap outline-none focus-visible:ring-2 focus-visible:ring-inset hover:brightness-95\"\n          style={{ height: s.h, padding: `0 ${s.pad}px`, gap: 8, fontSize: s.font, color: p.onSel, [\"--tw-ring-color\" as string]: p.onSel }}\n        >\n          {icon && (\n            <span className=\"flex [&>svg]:h-full [&>svg]:w-full\" style={{ width: s.icon, height: s.icon }}>\n              {icon}\n            </span>\n          )}\n          <span className=\"relative grid overflow-hidden\" style={{ height: s.font * 1.4 }}>\n            {/* Every label sits in the same cell, so the button keeps the widest width. */}\n            {options.map((o) => (\n              <span key={o.id} aria-hidden=\"true\" className=\"invisible col-start-1 row-start-1\" style={{ lineHeight: `${s.font * 1.4}px` }}>\n                {o.label}\n              </span>\n            ))}\n            <AnimatePresence initial={false} mode=\"popLayout\">\n              <motion.span key={chosen.id} className=\"col-start-1 row-start-1\" style={{ lineHeight: `${s.font * 1.4}px` }} initial={reduce ? false : { y: \"100%\", opacity: 0 }} animate={{ y: 0, opacity: 1 }} exit={reduce ? undefined : { y: \"-100%\", opacity: 0 }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 600, damping: 38 }}>\n                {chosen.label}\n              </motion.span>\n            </AnimatePresence>\n          </span>\n        </motion.button>\n        <span aria-hidden=\"true\" className=\"self-stretch\" style={{ width: 1, margin: `${s.h * 0.22}px 0`, background: `color-mix(in srgb, ${p.onSel} 22%, transparent)` }} />\n        <button\n          ref={trigger}\n          type=\"button\"\n          aria-label=\"More options\"\n          aria-haspopup=\"menu\"\n          aria-expanded={open}\n          aria-controls={`${uid}-menu`}\n          onClick={() => {\n            setActive(Math.max(0, options.indexOf(chosen)));\n            setOpen((o) => !o);\n          }}\n          className=\"flex cursor-pointer items-center justify-center outline-none focus-visible:ring-2 focus-visible:ring-inset hover:brightness-95\"\n          style={{ width: s.h, height: s.h, color: p.onSel, background: p.sel, [\"--tw-ring-color\" as string]: p.onSel }}\n        >\n          <motion.svg width=\"12\" height=\"12\" viewBox=\"0 0 12 12\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" animate={{ rotate: open ? 180 : 0 }} transition={{ duration: reduce ? 0 : 0.2 }}>\n            <path d=\"M3 4.5 6 7.5 9 4.5\" />\n          </motion.svg>\n        </button>\n      </div>\n      <AnimatePresence>\n        {open && (\n          <motion.div\n            id={`${uid}-menu`}\n            role=\"menu\"\n            className=\"absolute top-full right-0 z-20 flex flex-col\"\n            style={{ marginTop: 8, width: 280, padding: 5, borderRadius: 14, background: p.menu, border: `1px solid ${p.menuBorder}`, boxShadow: \"0 18px 40px -12px rgba(0,0,0,0.5)\", transformOrigin: \"top right\" }}\n            initial={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.94, y: -6 }}\n            animate={{ opacity: 1, scale: 1, y: 0 }}\n            exit={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.96, y: -4 }}\n            transition={{ duration: 0.16, ease: [0.22, 1, 0.36, 1] }}\n          >\n            {options.map((o, i) => {\n              const on = o.id === chosen.id;\n              return (\n                <button\n                  key={o.id}\n                  type=\"button\"\n                  role=\"menuitemradio\"\n                  aria-checked={on}\n                  onClick={() => pick(o)}\n                  onMouseMove={() => setActive(i)}\n                  className=\"relative flex cursor-pointer items-start text-left outline-none\"\n                  style={{ gap: 10, padding: \"9px 10px\", borderRadius: 10 }}\n                >\n                  {active === i && <motion.span layoutId={`${uid}-hl`} aria-hidden=\"true\" className=\"absolute inset-0\" style={{ borderRadius: 10, background: p.hover }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 600, damping: 40 }} />}\n                  <span className=\"relative flex shrink-0 items-center justify-center\" style={{ width: 16, height: 19, color: p.text }}>\n                    {on && (\n                      <svg width=\"14\" height=\"14\" viewBox=\"0 0 12 12\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                        <path d=\"M2.4 6.3 4.9 8.7 9.6 3.4\" />\n                      </svg>\n                    )}\n                  </span>\n                  <span className=\"relative flex flex-col\" style={{ gap: 2 }}>\n                    <span className=\"text-[13.5px] font-medium\" style={{ color: p.text }}>\n                      {o.label}\n                    </span>\n                    {o.description && (\n                      <span className=\"text-[12px] leading-snug\" style={{ color: p.muted }}>\n                        {o.description}\n                      </span>\n                    )}\n                  </span>\n                </button>\n              );\n            })}\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n\nconst svg = { width: 24, height: 24, viewBox: \"0 0 24 24\", fill: \"none\", stroke: \"currentColor\", strokeWidth: 1.8, strokeLinecap: \"round\" as const, strokeLinejoin: \"round\" as const, \"aria-hidden\": true };\n\nexport const GroupIcons = {\n  left: <svg {...svg}><path d=\"m15 6-6 6 6 6\" /></svg>,\n  right: <svg {...svg}><path d=\"m9 6 6 6-6 6\" /></svg>,\n  list: <svg {...svg}><path d=\"M9 6h11M9 12h11M9 18h11M4.5 6h.01M4.5 12h.01M4.5 18h.01\" /></svg>,\n  grid: <svg {...svg}><rect x=\"4\" y=\"4\" width=\"6.5\" height=\"6.5\" rx=\"1.5\" /><rect x=\"13.5\" y=\"4\" width=\"6.5\" height=\"6.5\" rx=\"1.5\" /><rect x=\"4\" y=\"13.5\" width=\"6.5\" height=\"6.5\" rx=\"1.5\" /><rect x=\"13.5\" y=\"13.5\" width=\"6.5\" height=\"6.5\" rx=\"1.5\" /></svg>,\n  board: <svg {...svg}><rect x=\"4\" y=\"4\" width=\"16\" height=\"16\" rx=\"2.5\" /><path d=\"M9.5 4v16M14.5 4v16\" /></svg>,\n  merge: <svg {...svg}><circle cx=\"7\" cy=\"5.5\" r=\"2\" /><circle cx=\"7\" cy=\"18.5\" r=\"2\" /><circle cx=\"17\" cy=\"12\" r=\"2\" /><path d=\"M7 7.5v9M7 9a6 6 0 0 0 8 3\" /></svg>,\n};\n\nexport function ButtonGroupDemo({ theme = \"dark\" }: { theme?: Theme }) {\n  return (\n    <div className=\"flex flex-col items-center\" style={{ gap: 20 }}>\n      <SplitButton\n        theme={theme}\n        icon={GroupIcons.merge}\n        options={[\n          { id: \"merge\", label: \"Merge pull request\", description: \"All commits are added to the base branch with a merge commit.\" },\n          { id: \"squash\", label: \"Squash and merge\", description: \"The commits are combined into one commit on the base branch.\" },\n          { id: \"rebase\", label: \"Rebase and merge\", description: \"The commits are rebased onto the base branch one by one.\" },\n        ]}\n      />\n      <ButtonGroup\n        theme={theme}\n        ariaLabel=\"Pages\"\n        items={[\n          { id: \"prev\", icon: GroupIcons.left, ariaLabel: \"Previous\" },\n          { id: \"today\", label: \"Today\" },\n          { id: \"next\", icon: GroupIcons.right, ariaLabel: \"Next\" },\n        ]}\n      />\n      <ButtonGroup\n        theme={theme}\n        ariaLabel=\"View\"\n        selection=\"single\"\n        defaultValue={[\"list\"]}\n        items={[\n          { id: \"list\", label: \"List\", icon: GroupIcons.list },\n          { id: \"grid\", label: \"Grid\", icon: GroupIcons.grid },\n          { id: \"board\", label: \"Board\", icon: GroupIcons.board },\n        ]}\n      />\n    </div>\n  );\n}\n\nexport default ButtonGroup;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}