# Choice card

> Radio options drawn as selectable cards, each with a title, a description and an optional trailing hint such as a price.

- Kind: ui · Category: Forms · Interactivity: native
- Install: `npx shadcn@latest add @haze/choice-card`
- File: `src/components/haze/ui/choice-card.astro`
- npm dependencies: none
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/choice-card

## Use when
- Picking a plan, a role or a deployment target where each option needs a sentence of explanation
- Two to four options that deserve more visual weight than a plain radio list

## Avoid when
- Long lists of options; use select
- Short labels that fit in a compact row; use toggle-group
- Choices where several can be picked at once

## Alternatives
- [radio-group](https://hazeui.com/ui/radio-group.md)
- [toggle-group](https://hazeui.com/ui/toggle-group.md)
- [select](https://hazeui.com/ui/select.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| name | `string` |  | yes | Shared radio name; the form submits the chosen value under it. |
| legend | `string` |  | yes | Visible group title, announced as the group name. |
| options | `{ value: string; title: string; description?: string; hint?: string; disabled?: boolean }[]` |  | yes | The cards; hint is short trailing text such as a price, and disabled turns off that card only. |
| value | `string` |  | no | Value of the card that is checked on load. |
| columns | `1 \| 2` | 1 | no | Layout; two columns apply from the sm breakpoint, narrower screens stack. |
| required | `boolean` |  | no | One card must be picked before the form submits; set on every radio. |
| disabled | `boolean` |  | no | Disables every card through the fieldset. |
| class | `string` |  | no | Extra classes on the fieldset. |
| ...rest | `attributes` |  | no | Any other fieldset attribute, for example form or aria-describedby. |

## Accessibility
- The whole card is one label around a real radio, so the title, description and hint are read as the radio's name and the entire card is the click target.
- The checked card gets a stronger border and a tinted background, and its radio box fills with a dot that scales in, so the state does not rely on color alone. Under forced colors the native radio is shown.
- Disabled cards are dimmed, show a not-allowed cursor and ignore hover.
- The focus outline is drawn around the card with has-focus-visible, not around the small radio.
- Key Arrow keys: Move between cards and select the one reached
- Key Tab: Enters or leaves the group at the checked card

## Agent prompts

### Install and use

Install the Haze UI component "Choice card" with `npx shadcn@latest add @haze/choice-card`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import ChoiceCard from "@/components/haze/ui/choice-card.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/ui/choice-card.md

### Customize with real content

Adapt the Haze choice-card ui for our product. Replace the demo values of these props with our real content: name, legend, options, value, columns, required, disabled, class, ...rest. Keep the layout, the heading level rules and these accessibility details: The whole card is one label around a real radio, so the title, description and hint are read as the radio's name and the entire card is the click target. The checked card gets a stronger border and a tinted background, and its radio box fills with a dot that scales in, so the state does not rely on color alone. Under forced colors the native radio is shown. Disabled cards are dimmed, show a not-allowed cursor and ignore hover. The focus outline is drawn around the card with has-focus-visible, not around the small radio. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using choice-card, check it fits: use it when picking a plan, a role or a deployment target where each option needs a sentence of explanation; two to four options that deserve more visual weight than a plain radio list. Avoid it when long lists of options; use select; short labels that fit in a compact row; use toggle-group; choices where several can be picked at once. Alternatives: @haze/radio-group, @haze/toggle-group, @haze/select.

## Example requests that should lead here
- Add a plan picker with Solo, Team and Scale cards that show a price
- Make a two-column role picker for the invite dialog

## Source

```astro
---
import { cn } from "../../../lib/haze/utils";

interface Option {
  value: string;
  title: string;
  description?: string;
  /** Short trailing text, such as a price. */
  hint?: string;
  /** Disables this card only. */
  disabled?: boolean;
}

interface Props {
  /** Shared radio name. */
  name: string;
  legend: string;
  options: Option[];
  /** The value that is checked on load. */
  value?: string;
  /** 2 columns apply from the sm breakpoint; below it the cards stack. */
  columns?: 1 | 2;
  /** One card must be picked before the form submits. */
  required?: boolean;
  /** Disables every card. */
  disabled?: boolean;
  class?: string;
  /** Any other fieldset attribute, for example form or aria-describedby. */
  [key: string]: unknown;
}

const { name, legend, options, value, columns = 1, required, disabled, class: className, ...rest } = Astro.props;
---

<fieldset disabled={disabled} class={cn("grid min-w-0 gap-3 border-0 p-0", className)} {...rest}>
  <legend class="mb-1 text-[0.8125rem]/5 font-medium text-foreground">{legend}</legend>
  <div class={cn("grid gap-3", columns === 2 && "sm:grid-cols-2")}>
    {
      options.map((option) => (
        <label class="flex cursor-pointer items-start gap-3 rounded-xl border border-border bg-card p-4.5 transition-[border-color,background-color,box-shadow] duration-150 ease-snappy hover:border-border-strong hover:shadow-lift has-checked:border-foreground has-checked:bg-muted has-checked:hover:border-foreground has-focus-visible:outline-2 has-focus-visible:outline-offset-1 has-focus-visible:outline-ring has-disabled:cursor-not-allowed has-disabled:opacity-50 has-disabled:hover:border-border-strong has-disabled:hover:shadow-none has-disabled:has-checked:hover:border-foreground">
          <span class="relative mt-0.5 inline-grid size-4.5 shrink-0 place-items-center">
            <input
              type="radio"
              name={name}
              value={option.value}
              checked={option.value === value}
              disabled={option.disabled}
              required={required}
              class="peer col-start-1 row-start-1 size-4.5 cursor-pointer appearance-none rounded-full border border-border-strong bg-field transition-[background-color,border-color,scale] duration-150 ease-snappy active:scale-90 active:duration-75 checked:border-primary checked:bg-primary disabled:cursor-not-allowed disabled:active:scale-100 aria-invalid:border-destructive! forced-colors:appearance-auto"
            />
            <span class="pointer-events-none col-start-1 row-start-1 size-2 scale-0 rounded-full bg-primary-foreground transition-[scale] duration-200 ease-spring peer-checked:scale-100 forced-colors:hidden" aria-hidden="true" />
          </span>
          <span class="grid min-w-0 flex-1 gap-1">
            <span class="flex items-baseline justify-between gap-3">
              <span class="text-[0.8125rem]/5 font-medium text-foreground">{option.title}</span>
              {option.hint && <span class="shrink-0 text-[0.8125rem]/5 text-muted-foreground tabular-nums">{option.hint}</span>}
            </span>
            {option.description && <span class="text-[0.8125rem]/5 text-muted-foreground">{option.description}</span>}
          </span>
        </label>
      ))
    }
  </div>
</fieldset>
```
