SelectableCard
A card that toggles between selected and unselected states with an accent border. For navigation use ClickableCard.
Installation
npm install @astryxdesign/core@0.7.1 @astryxdesign/theme-neutral@0.7.1 @stylexjs/stylex@0.19.0
Requires React 19+, base CSS and a Theme provider. See Setup.
Selectable Card
A card that toggles between selected and unselected states with an accent border. For navigation use ClickableCard.
| Prop | Type | Default | Description |
|---|---|---|---|
| label * | string | Accessibility label. | |
| isSelected * | boolean | Controlled selection state. | |
| onChange * | (isSelected: boolean) => void | Called when toggled. | |
| isDisabled | boolean | false | Disables the card. |
| children | ReactNode | Card content. | |
| padding | 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10 | 4 | Inner padding. |
| variant | 'default' | 'transparent' | 'muted' | 'blue' | 'cyan' | 'gray' | 'green' | 'orange' | 'pink' | 'purple' | 'red' | 'teal' | 'yellow' | 'default' | Background color variant. |
| elevation | 'none' | 'low' | 'med' | 'high' | 'none' | Resting shadow depth. The selection ring composes on top, so a selected card keeps its shadow. |
| width | SizeValue | Card width. | |
| height | SizeValue | Card height. | |
| maxWidth | SizeValue | Maximum card width. | |
| xstyle | StyleXStyles | StyleX styles for layout customization (margins, positioning, sizing). Must be a stylex.create() value, not an inline style object like style={{}}. |
Usage guidance
- Use for plan pickers, filter chips, or option grids.
- For single-select track one ID; for multi-select use a Set.
- When focused, toggle selection with Space or Enter.
- Avoid: Use for navigation; use ClickableCard for that.
Theming API
{
"container": true,
"targets": [
{
"className": "astryx-selectable-card",
"visualProps": [
"selected",
"variant"
]
}
],
"vars": [
{
"name": "--selectable-card-ring-color",
"description": "Colour of the selection ring drawn for a variant a theme added. The built-in variants each ring in their own border token and ignore this; a theme that adds a variant sets it in the same rule as that variant's `backgroundColor`, because no token the component could pick is guaranteed to contrast with a fill it cannot know.",
"default": "var(--color-accent)"
},
{
"name": "--_press-overlay",
"description": "Fill of the ::after interaction overlay: transparent at rest, the hover overlay token on hover (hover-capable pointers), the pressed overlay token while pressed (`:active` on a mouse; `data-astryx-press=\"on\"` written by the touch press controller under a finger) and the hover token for the release fade. Set on the card element by its own interaction arms.",
"default": "transparent",
"private": true
},
{
"name": "--_press-overlay-transition",
"description": "Duration of the overlay's background-color transition: the fast duration token, except 0s while a believed touch press paints so it lands on the first frame.",
"default": "var(--duration-fast)",
"private": true
}
]
}
Anatomy
- Container: Interactive div with accent border on selection.
- Content: Children rendered inside the card.
Examples
- Selectable Card: A plan picker with single-select radio behavior. Cards show an accent border when selected.
- Selectable Card — Elevated: Raised selectable cards with
elevation="low". The inset selection ring composes on top of the shadow, so a selected card keeps its elevation. - Selectable Card — Multi-select: Multi-select tag picker using color variant selectable cards with color-matched selection borders.