{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"chip-group","type":"registry:ui","title":"Chip group","description":"A set of toggleable chips for single or multiple choices.","dependencies":["clsx","tailwind-merge"],"registryDependencies":["https://caliperui.site/r/styles.json"],"files":[{"path":"ui/chip-group.tsx","type":"registry:ui","target":"components/ui/chip-group.tsx","content":"\"use client\";\n\nimport { useState, type KeyboardEvent } from \"react\";\nimport { cn } from \"./lib/cn\";\nimport \"./shared/chip-option.css\";\n\nexport type ChipOption = { value: string; label: string; disabled?: boolean };\n\nexport function ChipGroup({\n  label,\n  options,\n  value,\n  defaultValue,\n  onValueChange,\n  selection = \"multiple\",\n  name,\n  className,\n}: {\n  label: string;\n  options: readonly ChipOption[];\n  value?: string | readonly string[];\n  defaultValue?: string | readonly string[];\n  onValueChange?: (value: string | string[]) => void;\n  selection?: \"single\" | \"multiple\";\n  name?: string;\n  className?: string;\n}) {\n  const initial = defaultValue ?? (selection === \"single\" ? options[0]?.value ?? \"\" : []);\n  const [local, setLocal] = useState(initial);\n  const current = value ?? local;\n  const picked = new Set(Array.isArray(current) ? current : [current]);\n\n  function commit(next: string | string[]) {\n    if (value == null) setLocal(next);\n    onValueChange?.(next);\n  }\n\n  function toggle(option: ChipOption) {\n    if (option.disabled) return;\n    if (selection === \"single\") {\n      commit(option.value);\n      return;\n    }\n    const list = Array.isArray(current) ? [...current] : [];\n    commit(list.includes(option.value) ? list.filter((item) => item !== option.value) : [...list, option.value]);\n  }\n\n  function move(event: KeyboardEvent<HTMLDivElement>) {\n    const buttons = [...event.currentTarget.querySelectorAll<HTMLButtonElement>(\"button:not([aria-disabled=true])\")];\n    const index = buttons.indexOf(document.activeElement as HTMLButtonElement);\n    if (index < 0) return;\n    const next = event.key === \"ArrowRight\" || event.key === \"ArrowDown\" ? index + 1 : event.key === \"ArrowLeft\" || event.key === \"ArrowUp\" ? index - 1 : -1;\n    if (next < 0) return;\n    event.preventDefault();\n    buttons[(next + buttons.length) % buttons.length]?.focus();\n  }\n\n  const hidden = selection === \"single\" ? [String(current)] : Array.isArray(current) ? [...current] : [];\n\n  return (\n    <div className={cn(\"grid gap-2\", className)}>\n      <div\n        role={selection === \"single\" ? \"radiogroup\" : \"group\"}\n        aria-label={label}\n        className=\"flex flex-wrap gap-2\"\n        onKeyDown={move}\n      >\n        {options.map((option) => {\n          const on = picked.has(option.value);\n          return (\n            <button\n              key={option.value}\n              data-slot=\"chip-option\"\n              type=\"button\"\n              role={selection === \"single\" ? \"radio\" : undefined}\n              aria-checked={selection === \"single\" ? on : undefined}\n              aria-pressed={selection === \"multiple\" ? on : undefined}\n              aria-disabled={option.disabled || undefined}\n              className=\"h-[var(--control-height)] rounded-full border border-border px-3 text-sm font-medium outline-none hover:bg-muted focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring aria-checked:border-accent aria-checked:bg-accent aria-checked:text-accent-foreground aria-pressed:border-accent aria-pressed:bg-accent aria-pressed:text-accent-foreground aria-disabled:opacity-45\"\n              onClick={() => toggle(option)}\n            >\n              {option.label}\n            </button>\n          );\n        })}\n      </div>\n      {name ? hidden.map((item) => <input key={item} type=\"hidden\" name={name} value={item} />) : null}\n    </div>\n  );\n}\n"},{"path":"ui/lib/cn.ts","type":"registry:ui","target":"components/ui/lib/cn.ts","content":"import { clsx, type ClassValue } from \"clsx\";\nimport { extendTailwindMerge } from \"tailwind-merge\";\n\nconst twMerge = extendTailwindMerge({\n  extend: { theme: { radius: [\"control\", \"surface\", \"overlay\"], shadow: [\"overlay\"] } },\n});\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n"},{"path":"ui/shared/chip-option.css","type":"registry:file","target":"components/ui/shared/chip-option.css","content":"/* Shared by calendar.tsx, chart-parts.tsx, chip-group.tsx, data-table.tsx, number-field.tsx, password-field.tsx, stepper.tsx; each imports it. Edit freely. */\n@layer theme, base, components, utilities;\n\n@layer components {\n  /* Depth sets 2 and 3 end */\n\n  /* Press feedback (2026-10-20, motion audit): every pressable control answers a press. Compact controls take the\n     system press scale, as Button does; wide rows deepen their fill instead, since scaling a full-width row reads as a\n     jump. Disabled controls stay still. */\n  :is([data-slot=\"chip-option\"], [data-slot=\"number-field\"] button, [data-slot=\"password-toggle\"], [data-slot=\"calendar\"] button, [data-slot=\"chart-legend-item\"], [data-slot=\"sort-button\"], [data-slot=\"stepper\"] button):active:not(:disabled):not([aria-disabled=\"true\"]) {\n    scale: var(--motion-press-scale);\n  }\n}\n"}],"categories":["inputs"],"meta":{"tier":"free","license":"MIT","family":"choices","docs":"/docs/components/chip-group"}}