Choice card
Radio options drawn as selectable cards, each with a title, a description and an optional trailing hint such as a price.
pnpm dlx shadcn@latest add @haze/choice-card---
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>When to use
- 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
When not to use
- 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
Installation
Add the Haze registry to components.json once, then install Choice card with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/choice-cardnpx shadcn@latest add @haze/choice-cardyarn dlx shadcn@latest add @haze/choice-cardbunx --bun shadcn@latest add @haze/choice-cardFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| name* | string | – | Shared radio name; the form submits the chosen value under it. |
| legend* | string | – | Visible group title, announced as the group name. |
| options* | { value: string; title: string; description?: string; hint?: string; disabled?: boolean }[] | – | The cards; hint is short trailing text such as a price, and disabled turns off that card only. |
| value | string | – | Value of the card that is checked on load. |
| columns | 1 | 2 | 1 | Layout; two columns apply from the sm breakpoint, narrower screens stack. |
| required | boolean | – | One card must be picked before the form submits; set on every radio. |
| disabled | boolean | – | Disables every card through the fieldset. |
| class | string | – | Extra classes on the fieldset. |
| ...rest | attributes | – | Any other fieldset attribute, for example form or aria-describedby. |
Keyboard interactions
- Arrow keys
- Move between cards and select the one reached
- Tab
- Enters or leaves the group at the checked card
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.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
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": "http://localhost:4329/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: http://localhost:4329/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.
Dependencies
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.