{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "checkbox-group",
  "title": "Checkbox Group",
  "description": "A group of checkboxes with a Select all row that shows a dash when only some are picked, checks that draw themselves, list or card layouts, a maximum that disables the rest, a live count and an error state.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/checkbox-group/checkbox-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\nexport type CheckboxGroupSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface CheckboxGroupOption {\n  value: string;\n  label: string;\n  description?: string;\n  disabled?: boolean;\n}\n\nexport interface CheckboxGroupProps {\n  options?: CheckboxGroupOption[];\n  value?: string[];\n  defaultValue?: string[];\n  onValueChange?: (value: string[]) => void;\n  /** The group's legend. */\n  label?: string;\n  description?: string;\n  /** A \"Select all\" row above the options that shows a dash when only some are picked. */\n  selectAll?: boolean;\n  selectAllLabel?: string;\n  /** list: rows with a box on the left. cards: bordered tiles that light up when picked. */\n  variant?: \"list\" | \"cards\";\n  orientation?: \"vertical\" | \"horizontal\";\n  /** At most this many can be picked; the rest disable once it's reached. */\n  max?: number;\n  /** Error text to show (e.g. \"Pick at least one\"). */\n  error?: string;\n  showCount?: boolean;\n  name?: string;\n  disabled?: boolean;\n  size?: CheckboxGroupSize;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.5)\", faint: \"rgba(245,244,241,0.14)\", bg: \"rgba(255,255,255,0.03)\", hover: \"rgba(255,255,255,0.06)\", border: \"rgba(255,255,255,0.14)\", borderHover: \"rgba(255,255,255,0.28)\", focus: \"rgba(245,244,241,0.85)\", check: \"#F5F4F1\", checkFg: \"#0A0A0A\", selectedBg: \"rgba(255,255,255,0.07)\", error: \"#FF7A6B\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.5)\", faint: \"rgba(10,10,10,0.1)\", bg: \"#FFFFFF\", hover: \"rgba(10,10,10,0.04)\", border: \"rgba(10,10,10,0.2)\", borderHover: \"rgba(10,10,10,0.36)\", focus: \"rgba(10,10,10,0.85)\", check: \"#0A0A0A\", checkFg: \"#FFFFFF\", selectedBg: \"rgba(10,10,10,0.04)\", error: \"#E5484D\" },\n};\n\nconst SIZES: Record<CheckboxGroupSize, { box: number; font: number; small: number; gap: number; radius: number; pad: number }> = {\n  sm: { box: 16, font: 13, small: 12, gap: 9, radius: 5, pad: 11 },\n  md: { box: 18, font: 14.5, small: 12.5, gap: 10, radius: 6, pad: 13 },\n  lg: { box: 20, font: 16, small: 13.5, gap: 11, radius: 7, pad: 15 },\n};\n\nconst DEFAULT_OPTIONS: CheckboxGroupOption[] = [\n  { value: \"product\", label: \"Product updates\", description: \"New features and improvements, about twice a month.\" },\n  { value: \"tips\", label: \"Tips and tutorials\", description: \"Short guides to get more out of your plan.\" },\n  { value: \"events\", label: \"Events and webinars\", description: \"Invitations to live sessions near you.\" },\n  { value: \"offers\", label: \"Offers\", description: \"Discounts and early access, a few times a year.\" },\n];\n\nfunction Box({ state, size, radius, p, focused, disabled, reduce }: { state: \"on\" | \"off\" | \"mixed\"; size: number; radius: number; p: (typeof PALETTES)[\"dark\"]; focused: boolean; disabled: boolean; reduce: boolean }) {\n  const on = state !== \"off\";\n  return (\n    <span\n      aria-hidden=\"true\"\n      className=\"relative flex shrink-0 items-center justify-center\"\n      style={{\n        width: size,\n        height: size,\n        borderRadius: radius,\n        border: `1.5px solid ${on ? p.check : p.border}`,\n        background: on ? p.check : \"transparent\",\n        boxShadow: focused ? `0 0 0 3px color-mix(in srgb, ${p.focus} 18%, transparent)` : \"none\",\n        opacity: disabled ? 0.45 : 1,\n        transition: \"background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease\",\n      }}\n    >\n      <svg width={size - 6} height={size - 6} viewBox=\"0 0 12 12\" fill=\"none\">\n        <motion.path\n          d=\"M2.4 6.3 4.9 8.7 9.6 3.4\"\n          stroke={p.checkFg}\n          strokeWidth=\"1.9\"\n          strokeLinecap=\"round\"\n          strokeLinejoin=\"round\"\n          initial={false}\n          animate={{ pathLength: state === \"on\" ? 1 : 0, opacity: state === \"on\" ? 1 : 0 }}\n          transition={reduce ? { duration: 0 } : { duration: 0.2, ease: \"easeOut\" }}\n        />\n        <motion.path d=\"M3 6h6\" stroke={p.checkFg} strokeWidth=\"1.9\" strokeLinecap=\"round\" initial={false} animate={{ pathLength: state === \"mixed\" ? 1 : 0, opacity: state === \"mixed\" ? 1 : 0 }} transition={reduce ? { duration: 0 } : { duration: 0.16 }} />\n      </svg>\n    </span>\n  );\n}\n\nexport function CheckboxGroup({\n  options = DEFAULT_OPTIONS,\n  value,\n  defaultValue = [\"product\"],\n  onValueChange,\n  label = \"Email preferences\",\n  description,\n  selectAll = true,\n  selectAllLabel = \"Select all\",\n  variant = \"list\",\n  orientation = \"vertical\",\n  max,\n  error,\n  showCount = true,\n  name,\n  disabled = false,\n  size = \"md\",\n  theme = \"dark\",\n  className,\n}: CheckboxGroupProps) {\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<string[]>(defaultValue);\n  const selected = value ?? internal;\n  const [focused, setFocused] = React.useState<string | null>(null);\n  const [hovered, setHovered] = React.useState<string | null>(null);\n\n  const enabled = options.filter((o) => !o.disabled);\n  const pickedEnabled = enabled.filter((o) => selected.includes(o.value));\n  const allState: \"on\" | \"off\" | \"mixed\" = pickedEnabled.length === 0 ? \"off\" : pickedEnabled.length === enabled.length ? \"on\" : \"mixed\";\n  const atMax = max !== undefined && selected.length >= max;\n\n  const commit = (next: string[]) => {\n    // Keep the options' own order, whatever order they were clicked in.\n    const ordered = options.map((o) => o.value).filter((v) => next.includes(v));\n    if (value === undefined) setInternal(ordered);\n    onValueChange?.(ordered);\n  };\n\n  const toggle = (v: string) => commit(selected.includes(v) ? selected.filter((x) => x !== v) : [...selected, v]);\n  const toggleAll = () => {\n    if (allState === \"on\") commit(selected.filter((v) => !enabled.some((o) => o.value === v)));\n    else {\n      const room = max === undefined ? Infinity : max - selected.length;\n      const add = enabled.filter((o) => !selected.includes(o.value)).slice(0, Math.max(0, room)).map((o) => o.value);\n      commit([...selected, ...add]);\n    }\n  };\n\n  const cards = variant === \"cards\";\n  const horizontal = orientation === \"horizontal\";\n\n  const row = (key: string, opt: { label: string; description?: string }, state: \"on\" | \"off\" | \"mixed\", isDisabled: boolean, onChange: () => void, isAll = false) => {\n    const on = state !== \"off\";\n    const hot = hovered === key && !isDisabled;\n    return (\n      <label\n        key={key}\n        onMouseEnter={() => setHovered(key)}\n        onMouseLeave={() => setHovered(null)}\n        className={cn(\"relative flex select-none\", isDisabled ? \"cursor-default\" : \"cursor-pointer\")}\n        style={{\n          gap: s.gap,\n          alignItems: opt.description ? \"flex-start\" : \"center\",\n          padding: cards ? s.pad : `${s.pad / 2.4}px ${cards ? s.pad : 8}px`,\n          margin: cards ? 0 : \"0 -8px\",\n          borderRadius: cards ? s.radius + 6 : s.radius + 3,\n          border: cards ? `1px solid ${on && !isAll ? p.check : hot ? p.borderHover : p.border}` : \"1px solid transparent\",\n          background: cards ? (on && !isAll ? p.selectedBg : hot ? p.hover : p.bg) : hot ? p.hover : \"transparent\",\n          opacity: isDisabled ? 0.55 : 1,\n          flex: horizontal && cards ? \"1 1 0\" : undefined,\n          transition: \"background 0.16s ease, border-color 0.16s ease\",\n        }}\n      >\n        <input\n          type=\"checkbox\"\n          name={isAll ? undefined : name}\n          value={isAll ? undefined : key}\n          checked={state === \"on\"}\n          ref={(el) => {\n            if (el) el.indeterminate = state === \"mixed\";\n          }}\n          disabled={isDisabled}\n          onChange={onChange}\n          onFocus={(e) => setFocused(e.currentTarget.matches(\":focus-visible\") ? key : null)}\n          onBlur={() => setFocused(null)}\n          aria-describedby={opt.description ? `${uid}-${key}-d` : undefined}\n          className=\"sr-only\"\n        />\n        <span className=\"flex items-center\" style={{ height: opt.description ? s.font * 1.45 : undefined }}>\n          <Box state={state} size={s.box} radius={s.radius} p={p} focused={focused === key} disabled={isDisabled} reduce={reduce} />\n        </span>\n        <span className=\"flex min-w-0 flex-col\" style={{ gap: 2 }}>\n          <span className=\"font-medium\" style={{ color: p.text, fontSize: s.font, lineHeight: 1.45 }}>\n            {opt.label}\n          </span>\n          {opt.description && (\n            <span id={`${uid}-${key}-d`} style={{ color: p.muted, fontSize: s.small, lineHeight: 1.45 }}>\n              {opt.description}\n            </span>\n          )}\n        </span>\n      </label>\n    );\n  };\n\n  return (\n    <fieldset\n      disabled={disabled}\n      aria-invalid={error ? true : undefined}\n      aria-describedby={[description ? `${uid}-desc` : \"\", error ? `${uid}-err` : \"\"].filter(Boolean).join(\" \") || undefined}\n      className={cn(\"m-0 flex min-w-0 flex-col border-none p-0\", className)}\n      style={{ gap: 12, fontFamily: \"Inter, sans-serif\", opacity: disabled ? 0.55 : 1 }}\n    >\n      {/* The legend has to be the fieldset's first child to name the group; the visible heading\n          row below repeats it next to the count. */}\n      {label && <legend className=\"sr-only\">{label}</legend>}\n      {(label || showCount) && (\n        <div className=\"flex items-baseline justify-between\" style={{ gap: 12 }}>\n          {label && (\n            <span aria-hidden=\"true\" className=\"font-semibold tracking-[-0.01em]\" style={{ color: p.text, fontSize: s.font }}>\n              {label}\n            </span>\n          )}\n          {showCount && (\n            <span className=\"tabular-nums\" style={{ color: atMax ? p.text : p.muted, fontSize: s.small }} aria-live=\"polite\">\n              {max !== undefined ? `${selected.length} of ${max}` : `${selected.length} selected`}\n            </span>\n          )}\n        </div>\n      )}\n      {description && (\n        <p id={`${uid}-desc`} className=\"m-0\" style={{ color: p.muted, fontSize: s.small, lineHeight: 1.5, marginTop: -6 }}>\n          {description}\n        </p>\n      )}\n\n      {selectAll && (\n        <div style={{ paddingBottom: cards ? 0 : 6, borderBottom: cards ? undefined : `1px solid ${p.faint}` }}>\n          {row(\"__all\", { label: selectAllLabel }, allState, disabled || (allState === \"off\" && max === 0), toggleAll, true)}\n        </div>\n      )}\n\n      <div className={cn(\"flex\", horizontal ? \"flex-row flex-wrap\" : \"flex-col\")} style={{ gap: cards ? 8 : horizontal ? 18 : 2 }}>\n        {options.map((o) => {\n          const on = selected.includes(o.value);\n          return row(o.value, o, on ? \"on\" : \"off\", disabled || Boolean(o.disabled) || (!on && atMax), () => toggle(o.value));\n        })}\n      </div>\n\n      <AnimatePresence initial={false}>\n        {error && (\n          <motion.div\n            key=\"err\"\n            id={`${uid}-err`}\n            role=\"alert\"\n            initial={{ opacity: 0, height: 0 }}\n            animate={{ opacity: 1, height: \"auto\" }}\n            exit={{ opacity: 0, height: 0 }}\n            transition={{ duration: 0.18 }}\n            className=\"overflow-hidden font-medium\"\n            style={{ color: p.error, fontSize: s.small }}\n          >\n            {error}\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </fieldset>\n  );\n}\n\nexport default CheckboxGroup;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}