{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "choice-card",
  "title": "ChoiceCard",
  "description": "A set of choices shown as cards, each with a picture, a label and a line of description, for picking exactly one: a cover photo, a plan, a layout.",
  "registryDependencies": [
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-env",
    "@ouro/lib-use-dev-messages",
    "@ouro/lib-use-field"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/choice-card/choice-card.tsx",
      "content": "\"use client\";\n\nimport { useId, useState, type ChangeEvent, type JSX, type ReactNode, type Ref } from \"react\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { errorMessages, type ReadonlyErrorMessages } from \"@/registry/ouro/lib/ouro/use-field\";\n\n/** One card in a {@link ChoiceCard}'s `items`. */\nexport interface ChoiceCardItem {\n  /** What the group submits when this card is chosen, and its `value` then. */\n  value: string;\n  /** The choice's name, under its media. */\n  label: string;\n  /** Supporting text under the label, read after it. */\n  description?: ReactNode | undefined;\n  /**\n   * A picture of the choice above its label, such as `<img src={cover} alt=\"\" />`: give it\n   * `alt=\"\"` when the label says what it shows. It fills the card's width.\n   */\n  media?: ReactNode | undefined;\n  /** Disables this one card; the arrow keys skip it. */\n  disabled?: boolean | undefined;\n}\n\n/** Props for {@link ChoiceCard}. */\nexport interface ChoiceCardProps {\n  /** What is being chosen, above the cards and read as the group's name. */\n  legend: string;\n  /** Keeps the legend for screen readers only, when a heading above already says it. */\n  hideLegend?: boolean | undefined;\n  /** Supporting text under the legend, read with the group. */\n  description?: ReactNode | undefined;\n  /** The choices. */\n  items: readonly ChoiceCardItem[];\n  /** The chosen value, for a controlled group; pair it with `onValueChange`. */\n  value?: string | undefined;\n  /** The value chosen at first, for an uncontrolled group. */\n  defaultValue?: string | undefined;\n  /** Called with the value of the card the person chooses. */\n  onValueChange?: ((value: string) => void) | undefined;\n  /** The form field name the chosen value submits under. */\n  name?: string | undefined;\n  /**\n   * What is wrong, shown under the cards in the destructive tone and read with each choice.\n   *\n   * @claim \"What is wrong, shown under the\" registry/ouro/components/ouro/choice-card/choice-card.test.tsx verify:testExists(registry/ouro/components/ouro/choice-card/choice-card.test.tsx::ChoiceCard > shows an error under the cards, read with each choice, and marks them invalid)\n   */\n  error?: ReadonlyErrorMessages | undefined;\n  /** A choice must be made before the form submits; the legend shows the required mark. */\n  required?: boolean | undefined;\n  /**\n   * Disables every card.\n   *\n   * @claim \"Disables every card\" registry/ouro/components/ouro/choice-card/choice-card.test.tsx verify:testExists(registry/ouro/components/ouro/choice-card/choice-card.test.tsx::ChoiceCard > disables every card, or one)\n   */\n  disabled?: boolean | undefined;\n  /**\n   * How many cards a row holds on a wide screen; on a phone each row holds one, or two with\n   * `columns` of 3 or more. @default 3\n   * @claim \"How many cards a row holds\" registry/ouro/components/ouro/choice-card/choice-card.touch.test.tsx verify:testExists(registry/ouro/components/ouro/choice-card/choice-card.touch.test.tsx::gives each card and each photo button a 44px target, and stacks the cards on a phone)\n   * @claim \"How many cards a row holds\" registry/ouro/components/ouro/choice-card/choice-card.test.tsx verify:fileLine(registry/ouro/components/ouro/choice-card/choice-card.test.tsx, /puts\\s%s\\scards\\sin\\sa\\srow\\son\\sa\\swide\\sscreen\\sand\\sfewer\\son\\sa\\sphone/)\n   */\n  columns?: 2 | 3 | 4 | (number & { 'Use 2, 3 or 4': never }) | undefined;\n  /** Layout only: margins, width (`mt-6`). Appearance classes warn in development. */\n  className?: string | undefined;\n  ref?: Ref<HTMLFieldSetElement> | undefined;\n\n  /** Not a prop. The choices are `items`: `<ChoiceCard items={[{ value, label, media }]} />`. */\n  options?: { 'Use items={[{ value, label, media }]}': never };\n  /** Not a prop. The group's name is `legend`: `<ChoiceCard legend=\"Cover photo\" />`. */\n  label?: { 'Use <ChoiceCard legend=\"Cover photo\" />': never };\n  /** Not a prop. Ouro UI says `onValueChange`: `<ChoiceCard onValueChange={setCover} />`. */\n  onChange?: { 'Use onValueChange={setValue}': never };\n}\n\nconst columnClasses = {\n  2: \"sm:grid-cols-2\",\n  3: \"grid-cols-2 sm:grid-cols-3\",\n  4: \"grid-cols-2 sm:grid-cols-4\",\n} as const;\n\nconst cardClass =\n  \"group/card relative flex min-h-11 min-w-0 cursor-pointer flex-col overflow-hidden rounded-ouro-lg border border-solid border-border bg-background text-foreground \" +\n  \"transition-[background-color,border-color] duration-(--ouro-duration-fast) ease-[ease] \" +\n  \"data-checked:border-primary data-checked:bg-primary/5 \" +\n  \"pointer-fine:hover:not-data-checked:not-data-disabled:border-[color-mix(in_oklab,var(--border)_50%,var(--foreground))] \" +\n  \"has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-solid has-focus-visible:outline-ring \" +\n  \"data-disabled:cursor-not-allowed data-disabled:opacity-50 data-invalid:not-data-checked:border-destructive \" +\n  \"contrast-more:data-checked:border-2\";\n\n/**\n * A set of choices shown as cards, each with a picture, a label and a line of description,\n * for picking exactly one: a cover photo, a plan, a layout. The cards are a native radio group\n * under a legend, so the arrow keys move between them, a plain form submits the chosen value,\n * and screen readers hear \"Cover photo, radio group\" and each card's label and description.\n * The chosen card takes the primary color and a check.\n *\n * Use `RadioGroup` instead for plain text choices, `SegmentedControl` for two to five short\n * options that switch a view, and `Select` for a long list.\n *\n * @group Forms\n * @see https://ui.ouroboros.bot/docs/choice-card\n *\n * @example\n * <ChoiceCard\n *   legend=\"Cover photo\"\n *   name=\"cover\"\n *   items={photos.map((photo) => ({ value: photo.id, label: photo.title, media: <img src={photo.url} alt=\"\" /> }))}\n * />\n * @claim \"A set of choices shown as\" registry/ouro/components/ouro/choice-card/choice-card.test.tsx verify:testExists(registry/ouro/components/ouro/choice-card/choice-card.test.tsx::ChoiceCard > is a group named by its legend, of radios named by their labels and described by their descriptions)\n * @claim \"The cards are a native radio\" registry/ouro/components/ouro/choice-card/choice-card.test.tsx verify:testExists(registry/ouro/components/ouro/choice-card/choice-card.test.tsx::ChoiceCard > moves between cards with the arrow keys, as a radio group does)\n * @claim \"The cards are a native radio\" registry/ouro/components/ouro/choice-card/choice-card.test.tsx verify:testExists(registry/ouro/components/ouro/choice-card/choice-card.test.tsx::ChoiceCard > is a group named by its legend, of radios named by their labels and described by their descriptions)\n * @claim \"The cards are a native radio\" registry/ouro/components/ouro/choice-card/choice-card.test.tsx verify:testExists(registry/ouro/components/ouro/choice-card/choice-card.test.tsx::ChoiceCard > submits the chosen value under its name)\n */\nexport function ChoiceCard(props: ChoiceCardProps): JSX.Element {\n  const {\n    legend,\n    hideLegend,\n    description,\n    items,\n    value,\n    defaultValue,\n    onValueChange,\n    name,\n    error,\n    required,\n    disabled,\n    columns: columnsProp = 3,\n    className,\n    ref,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    options,\n    label,\n    onChange,\n  } = props;\n  const columns: 2 | 3 | 4 = columnsProp === 2 ? 2 : columnsProp === 4 ? 4 : 3;\n  useAppearanceClassNameCheck(\n    \"ChoiceCard\",\n    className,\n    process.env.NODE_ENV !== \"production\"\n      ? (token: string) => `remove \"${token}\"; ChoiceCard sets its own look from the theme`\n      : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"ChoiceCard\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          columns !== columnsProp && [`columns={${String(columnsProp)}} is not a column count; use 2, 3 or 4`, \"<ChoiceCard columns={3} />\"],\n          options !== undefined && [\"options is not a prop\", \"<ChoiceCard items={[{ value, label, media }]} />\"],\n          label !== undefined && [\"label is not a prop; the group's name is legend\", `<ChoiceCard legend=\"${typeof label === \"string\" ? label : \"Cover photo\"}\" />`],\n          onChange !== undefined && [\"onChange is not a prop\", \"<ChoiceCard onValueChange={setValue} />\"],\n          new Set(items.map((item) => item.value)).size !== items.length && [\"two items share a value, so they choose together\", \"<ChoiceCard items={[{ value: 'a', label: 'A' }, { value: 'b', label: 'B' }]} />\"],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n  const id = useId();\n  const group = name ?? id;\n  const [own, setOwn] = useState(defaultValue);\n  const chosen = value !== undefined ? value : own;\n  const messages = errorMessages(error);\n  const invalid = messages.length > 0;\n  const describedBy = [description != null ? `${id}-description` : null, invalid ? `${id}-error` : null].filter(Boolean).join(\" \") || undefined;\n\n  const choose = (event: ChangeEvent<HTMLInputElement>) => {\n    setOwn(event.target.value);\n    onValueChange?.(event.target.value);\n  };\n\n  return (\n    <fieldset\n      ref={ref}\n      data-ouro=\"choice-card\"\n      disabled={disabled}\n      aria-labelledby={`${id}-legend`}\n      aria-describedby={describedBy}\n      className={cn(\"[@layer_ouro-reset]:m-0 grid min-w-0 gap-3 border-0 p-0\", className)}\n    >\n      <legend\n        data-ouro-legend=\"\"\n        data-ouro-required={required ? \"\" : undefined}\n        className={cn(\n          \"p-0 text-sm leading-5 font-medium text-foreground\",\n          // The mark sits outside the text the group is named by, so it never joins the name.\n          \"data-ouro-required:after:ms-0.5 data-ouro-required:after:font-medium data-ouro-required:after:text-destructive data-ouro-required:after:content-['*'] supports-[content:'*'_/_'']:data-ouro-required:after:content-['*'_/_'']\",\n          hideLegend ? \"sr-only\" : \"mb-1\",\n        )}\n      >\n        <span id={`${id}-legend`}>{legend}</span>\n      </legend>\n      {description != null ? (\n        <div id={`${id}-description`} className=\"text-sm leading-5 text-muted-foreground\">\n          {description}\n        </div>\n      ) : null}\n      <div className={cn(\"grid gap-3\", columnClasses[columns])}>\n        {items.map((item, index) => {\n          const checked = chosen === item.value;\n          const key = `${id}-${index}`;\n          const off = disabled || item.disabled;\n          return (\n            <label\n              key={`${index}:${item.value}`}\n              data-ouro-part=\"card\"\n              data-checked={checked ? \"\" : undefined}\n              data-disabled={off ? \"\" : undefined}\n              data-invalid={invalid ? \"\" : undefined}\n              className={cardClass}\n            >\n              <input\n                data-ouro-control=\"choice-card\"\n                data-ouro-part=\"input\"\n                type=\"radio\"\n                name={group}\n                value={item.value}\n                checked={checked}\n                onChange={choose}\n                disabled={off}\n                required={required}\n                aria-invalid={invalid || undefined}\n                aria-labelledby={`${key}-label`}\n                aria-describedby={[item.description != null ? `${key}-description` : \"\", invalid ? `${id}-error` : \"\"].join(\" \").trim() || undefined}\n                className=\"peer sr-only\"\n              />\n              {item.media != null ? (\n                <span className=\"block aspect-[4/3] w-full overflow-hidden bg-muted [&>img]:block [&>img]:size-full [&>img]:object-cover\">{item.media}</span>\n              ) : null}\n              <span className=\"grid gap-0.5 p-3 pe-10\">\n                <span id={`${key}-label`} className=\"text-sm leading-5 font-medium\">\n                  {item.label}\n                </span>\n                {item.description != null ? (\n                  // Mixed toward the foreground: the chosen card's tint is a muted surface.\n                  <span id={`${key}-description`} className=\"text-sm leading-5 text-[color-mix(in_oklab,var(--muted-foreground)_80%,var(--foreground))]\">\n                    {item.description}\n                  </span>\n                ) : null}\n              </span>\n              <span\n                aria-hidden=\"true\"\n                className=\"absolute end-2 bottom-2.5 flex size-6 items-center justify-center rounded-full border border-solid border-border bg-background text-transparent group-data-checked/card:border-primary group-data-checked/card:bg-primary group-data-checked/card:text-primary-foreground\"\n              >\n                <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"3\" strokeLinecap=\"round\" strokeLinejoin=\"round\" className=\"size-3.5\">\n                  <path d=\"M20 6 9 17l-5-5\" />\n                </svg>\n              </span>\n            </label>\n          );\n        })}\n      </div>\n      {invalid ? (\n        <div id={`${id}-error`} className=\"grid gap-1 text-sm leading-5 text-destructive\">\n          {messages.map((message, index) => (\n            <p key={index} className=\"m-0\">\n              {message}\n            </p>\n          ))}\n        </div>\n      ) : null}\n    </fieldset>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/choice-card/choice-card.tsx"
    }
  ],
  "docs": "A set of choices shown as cards, each with a picture, a label and a line of description, for picking exactly one: a cover photo, a plan, a layout. Import: import { ChoiceCard } from \"@/components/ouro/choice-card/choice-card\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: the helpers it imports in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/choice-card.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}