{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "choice-card",
  "type": "registry:ui",
  "title": "Choice Card",
  "description": "Big, tappable tiles for picking: one answer to a question, the topics a reader cares about, the kind of session a group wants. A tile carries a title, an optional line of description and an optional picture or icon, and the whole tile is the control, so a…",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "form",
    "primitive"
  ],
  "dependencies": [
    "@base-ui/react",
    "lucide-react"
  ],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/cn.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/choice-card.tsx",
      "target": "components/ui/choice-card.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport * as React from 'react';\n\n// @interlace/choice-card v1.0.1 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/choice-card\n// What changed since: https://ds.interlace.tools/c/choice-card#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — ChoiceCard\n *\n * Big, tappable tiles for picking: one answer to a question, the topics a\n * reader cares about, the kind of session a group wants. A tile carries a\n * title, an optional line of description and an optional picture or icon, and\n * the whole tile is the control, so a thumb never has to find a small dot.\n *\n * `type=\"single\"` is a radio group (one pick, arrow keys move it); `type=\n * \"multiple\"` is a group of checkboxes (any number, Space toggles each). Both\n * keep the controlled/uncontrolled pair (`value` + `onValueChange` /\n * `defaultValue`) and post their value with a form through `name`.\n * Mirrors: https://base-ui.com/react/components/radio and /checkbox-group\n *\n * ## Anatomy\n *\n *   ChoiceCardGroup               (div[role=radiogroup] | div[role=group] — data-slot=\"choice-card-group\", data-type, data-layout, data-min-viewport=320)\n *     └─ ChoiceCard               (span[role=radio|checkbox] — data-slot=\"choice-card\", data-checked) — repeats\n *         ├─ media?               (data-slot=\"choice-card-media\")\n *         ├─ title                (data-slot=\"choice-card-title\": the accessible name)\n *         ├─ description?         (data-slot=\"choice-card-description\": the accessible description)\n *         ├─ children?            (anything else the tile shows)\n *         └─ indicator            (aria-hidden — data-slot=\"choice-card-indicator\": a ring, or a box when multiple)\n *\n * ## Keyboard (owned by Base UI)\n *\n * | Key        | single                                  | multiple                    |\n * | ---------- | --------------------------------------- | --------------------------- |\n * | Tab        | into the group, on the picked tile      | to each tile in turn        |\n * | ↓ → / ↑ ←  | pick the next / previous tile (wraps)   | —                           |\n * | Space      | pick the focused tile                   | toggle the focused tile     |\n *\n * ## Layout\n *\n * `layout=\"grid\"` (default) fills the row with tiles at least\n * `--choice-card-min` wide (12rem), one per row on a phone; `layout=\"list\"`\n * stacks full-width rows, the shape of quiz answers. Text wraps; nothing is\n * truncated.\n *\n * ## Motion\n *\n * A tile presses in to 0.97 while held and its border and tint follow the\n * pick, timed by `--duration-fast` on `--ease-enter`; under reduced motion it\n * stays still and only the colours change.\n *\n * ## Contrast\n *\n * The picked state never rests on colour alone: the border thickens to the\n * `--primary` ring and the indicator fills and shows a check. Text keeps\n * `--card-foreground` / `--muted-foreground` on a tint of at most 6%\n * `--primary`, so body text keeps its contrast.\n *\n * | Rule | Concept                          | Where in this file                                       |\n * | ---- | -------------------------------- | -------------------------------------------------------- |\n * | R4   | Extends Base UI part props       | group and card extend their Base UI part's props          |\n * | R6   | data-slot per part               | choice-card-group / -card / -media / -title / -description / -indicator |\n * | R7   | className merged + ...rest + ref | `cn(BASE, className)` + `{...props}` + forwarded ref      |\n * | R8   | Enums, not booleans              | `type`, `layout`                                          |\n * | R11  | Composition over prop-drilling   | cards are children, not an `options` array prop           |\n * | R12  | Reuse over wrap                  | Base UI owns roving tabindex, ARIA and the hidden inputs  |\n * | R14  | Declares min viewport            | `data-min-viewport={String(MIN_VIEWPORT)}` + exported const |\n * | R18  | Tailwind only                    | zero inline `style`                                       |\n * | R19  | Tokens only                      | `--primary`, `--border`, `--card`, `--duration-*`, `--ease-*` |\n * | R25  | Client component                 | required — Base UI radio and checkbox ship client hooks   |\n * | R26  | A11y from upstream               | `role=\"radio\"` / `role=\"checkbox\"`, named by the title    |\n */\n\nimport { Checkbox } from '@base-ui/react/checkbox';\nimport { CheckboxGroup } from '@base-ui/react/checkbox-group';\nimport { Radio } from '@base-ui/react/radio';\nimport { RadioGroup } from '@base-ui/react/radio-group';\nimport { CheckIcon } from 'lucide-react';\n\nimport { cn } from '@/lib/utils';\n\n/** Smallest viable viewport (CSS px) for this primitive. */\nexport const MIN_VIEWPORT = 320 as const;\n\nexport type ChoiceCardLayout = 'grid' | 'list';\n\nconst ChoiceCardContext = React.createContext<'single' | 'multiple'>('single');\n\nconst LAYOUT: Record<ChoiceCardLayout, string> = {\n  grid: 'grid-cols-[repeat(auto-fill,minmax(min(100%,var(--choice-card-min,12rem)),1fr))]',\n  list: 'grid-cols-1',\n};\n\ninterface ChoiceCardGroupShared {\n  /** `grid` fills the row with tiles; `list` stacks full-width rows. @default 'grid' */\n  layout?: ChoiceCardLayout;\n  className?: string;\n  children?: React.ReactNode;\n}\n\nexport type ChoiceCardGroupSingleProps = ChoiceCardGroupShared &\n  Omit<React.ComponentProps<typeof RadioGroup>, 'className' | 'children' | 'value' | 'defaultValue' | 'onValueChange'> & {\n    /** One pick: a radio group. */\n    type?: 'single';\n    value?: string | null;\n    defaultValue?: string | null;\n    onValueChange?: (value: string) => void;\n  };\n\nexport type ChoiceCardGroupMultipleProps = ChoiceCardGroupShared &\n  Omit<React.ComponentProps<typeof CheckboxGroup>, 'className' | 'children' | 'value' | 'defaultValue' | 'onValueChange'> & {\n    /** Any number of picks: a group of checkboxes. */\n    type: 'multiple';\n    value?: string[];\n    defaultValue?: string[];\n    onValueChange?: (value: string[]) => void;\n    /** With `multiple`, the field name each picked tile posts with a form. */\n    name?: string;\n  };\n\nexport type ChoiceCardGroupProps = ChoiceCardGroupSingleProps | ChoiceCardGroupMultipleProps;\n\nconst ChoiceCardGroup = React.forwardRef<HTMLDivElement, ChoiceCardGroupProps>(function ChoiceCardGroup(\n  props,\n  ref,\n) {\n  const shared = (type: 'single' | 'multiple', layout: ChoiceCardLayout, className?: string) => ({\n    'data-slot': 'choice-card-group',\n    'data-type': type,\n    'data-layout': layout,\n    'data-min-viewport': String(MIN_VIEWPORT),\n    className: cn('grid gap-3', LAYOUT[layout], className),\n  });\n\n  if (props.type === 'multiple') {\n    const { type, layout = 'grid', className, children, onValueChange, name, ...rest } = props;\n    return (\n      <ChoiceCardContext.Provider value={type}>\n        <NameContext.Provider value={name}>\n          <CheckboxGroup\n            ref={ref}\n            {...shared(type, layout, className)}\n            onValueChange={onValueChange ? (value) => onValueChange(value) : undefined}\n            {...rest}\n          >\n            {children}\n          </CheckboxGroup>\n        </NameContext.Provider>\n      </ChoiceCardContext.Provider>\n    );\n  }\n\n  const { type = 'single', layout = 'grid', className, children, onValueChange, ...rest } = props;\n  return (\n    <ChoiceCardContext.Provider value={type}>\n      <RadioGroup\n        ref={ref}\n        {...shared(type, layout, className)}\n        onValueChange={onValueChange ? (value) => onValueChange(value as string) : undefined}\n        {...rest}\n      >\n        {children}\n      </RadioGroup>\n    </ChoiceCardContext.Provider>\n  );\n});\n\nconst NameContext = React.createContext<string | undefined>(undefined);\n\nconst CARD =\n  // Base UI renders a span with the role; every part inside is a span too, so the markup stays valid.\n  'group/choice-card relative flex min-h-11 cursor-pointer flex-col items-start gap-1 rounded-xl border border-border bg-card p-4 pe-11 text-start text-card-foreground focus-visible:outline-hidden ' +\n  'transition-[border-color,background-color,box-shadow,scale] duration-(--duration-fast) ease-enter motion-safe:active:scale-[0.97] ' +\n  'hover:border-ring/60 hover:bg-muted/40 ' +\n  'focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background ' +\n  'data-[checked]:border-primary data-[checked]:bg-primary/6 data-[checked]:shadow-[inset_0_0_0_1px_var(--primary)] ' +\n  'data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50 data-[disabled]:motion-safe:active:scale-100 ' +\n  'aria-invalid:border-destructive';\n\nconst INDICATOR =\n  'absolute end-3 top-3 flex size-5 items-center justify-center border border-input bg-background text-primary-foreground ' +\n  'transition-[background-color,border-color] duration-(--duration-fast) ease-enter ' +\n  'group-data-[checked]/choice-card:border-primary group-data-[checked]/choice-card:bg-primary';\n\nexport interface ChoiceCardProps extends Omit<React.ComponentPropsWithoutRef<'span'>, 'title' | 'onChange'> {\n  /** The value this tile picks. */\n  value: string;\n  /** The tile's name: short, read first, and the accessible name. */\n  title: React.ReactNode;\n  /** One line under the title, read as the accessible description. */\n  description?: React.ReactNode;\n  /** A picture or icon above the title. Give an image its own `alt`, or `alt=\"\"` when the title says it all. */\n  media?: React.ReactNode;\n  /** The tile cannot be picked. */\n  disabled?: boolean;\n}\n\nconst ChoiceCard = React.forwardRef<HTMLElement, ChoiceCardProps>(function ChoiceCard(\n  { value, title, description, media, disabled, className, children, ...props },\n  ref,\n) {\n  const type = React.useContext(ChoiceCardContext);\n  const name = React.useContext(NameContext);\n  const id = React.useId();\n  const titleId = `${id}-title`;\n  const descriptionId = description ? `${id}-description` : undefined;\n\n  const parts = (\n    <>\n      {media ? (\n        <span data-slot=\"choice-card-media\" className=\"mb-2 flex text-primary [&_svg:not([class*='size-'])]:size-6\">\n          {media}\n        </span>\n      ) : null}\n      <span id={titleId} data-slot=\"choice-card-title\" className=\"font-medium\">\n        {title}\n      </span>\n      {description ? (\n        <span id={descriptionId} data-slot=\"choice-card-description\" className=\"text-muted-foreground text-sm\">\n          {description}\n        </span>\n      ) : null}\n      {children}\n      <span\n        aria-hidden=\"true\"\n        data-slot=\"choice-card-indicator\"\n        className={cn(INDICATOR, type === 'single' ? 'rounded-full' : 'rounded-md')}\n      >\n        <CheckIcon\n          className=\"size-3.5 opacity-0 transition-opacity duration-(--duration-fast) ease-enter group-data-[checked]/choice-card:opacity-100\"\n          strokeWidth={3}\n        />\n      </span>\n    </>\n  );\n\n  const common = {\n    'data-slot': 'choice-card',\n    'aria-labelledby': titleId,\n    'aria-describedby': descriptionId,\n    className: cn(CARD, className),\n    disabled,\n    ...props,\n  };\n\n  if (type === 'multiple') {\n    return (\n      <Checkbox.Root ref={ref} value={value} name={name} {...common}>\n        {parts}\n      </Checkbox.Root>\n    );\n  }\n  return (\n    <Radio.Root\n      ref={ref}\n      value={value}\n      {...common}\n      // Base UI puts `aria-readonly` on the radio too; ARIA allows it only on the group, which also gets it.\n      aria-readonly={undefined}\n    >\n      {parts}\n    </Radio.Root>\n  );\n});\n\nexport { ChoiceCard, ChoiceCardGroup };\n"
    }
  ],
  "meta": {
    "tier": "primitive",
    "client": true,
    "minViewport": 320,
    "loading": false,
    "version": "1.0.1",
    "since": "2.0.0"
  },
  "docs": "## @interlace/choice-card\n\nInstalled to `components/ui/choice-card.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/choice-card';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/choice-card\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
