Primitives
Checkbox
A labelled checkbox on a native input, with help and error text
Basic
---
import Checkbox from '@alfadormx/blocks/primitives/Checkbox.astro';
---
<div class="flex flex-col gap-4 max-w-md">
<Checkbox label="Subscribe to the newsletter" name="newsletter" />
</div>Help text
Adds a card with your message.
---
import Checkbox from '@alfadormx/blocks/primitives/Checkbox.astro';
---
<div class="flex flex-col gap-4 max-w-md">
<Checkbox label="Gift wrap" help="Adds a card with your message." />
</div>Checked
---
import Checkbox from '@alfadormx/blocks/primitives/Checkbox.astro';
---
<div class="flex flex-col gap-4 max-w-md">
<Checkbox label="Remember me" checked />
</div>Sizes
---
import Checkbox from '@alfadormx/blocks/primitives/Checkbox.astro';
const sizes = ['xs', 'sm', 'md', 'lg', 'xl'] as const;
---
<div class="flex flex-col gap-4 max-w-md">
{sizes.map((size) => (
<Checkbox label={`Size ${size}`} size={size} checked />
))}
</div>Intents
---
import Checkbox from '@alfadormx/blocks/primitives/Checkbox.astro';
const intents = [
'primary',
'secondary',
'tertiary',
'accent',
'success',
'warning',
'error',
'neutral',
] as const;
---
<div class="flex flex-col gap-4 max-w-md">
{intents.map((intent) => (
<Checkbox label={`Intent ${intent}`} intent={intent} checked />
))}
</div>Shapes
---
import Checkbox from '@alfadormx/blocks/primitives/Checkbox.astro';
const shapes = ['rounded', 'square'] as const;
---
<div class="flex flex-col gap-4 max-w-md">
{shapes.map((shape) => (
<Checkbox label={`Shape ${shape}`} shape={shape} checked />
))}
</div>Error
Read them before ordering.
Accept the terms to continue.
---
import Checkbox from '@alfadormx/blocks/primitives/Checkbox.astro';
---
<div class="flex flex-col gap-4 max-w-md">
<Checkbox
label="I accept the terms"
help="Read them before ordering."
error="Accept the terms to continue."
/>
</div>Required
---
import Checkbox from '@alfadormx/blocks/primitives/Checkbox.astro';
---
<div class="flex flex-col gap-4 max-w-md">
<Checkbox label="I accept the terms and conditions" name="terms" required />
</div>Disabled
---
import Checkbox from '@alfadormx/blocks/primitives/Checkbox.astro';
---
<div class="flex flex-col gap-4 max-w-md">
<Checkbox label="Disabled" disabled />
<Checkbox label="Disabled and checked" disabled checked />
</div>API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | — | Visible label; always the control's accessible name, even when hidden. |
| hideLabel | boolean | false | Renders the label screen-reader-only (default: false). |
| help | string | — | Help text below the control, announced as part of its description. |
| error | string | — | Error text below the control; marks it invalid and forces the `error` intent. |
| id | string | — | Id of the native control; help and error ids derive from it. Generated when omitted. |
| name | string | — | Form field name. |
| required | boolean | false | Marks the control as required and shows a `*` after the label (default: false). |
| disabled | boolean | false | Disables the control (default: false). |
| size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'md' | Padding and text size, matching Button (default: 'md'). |
| intent | 'primary' | 'secondary' | 'tertiary' | 'accent' | 'success' | 'warning' | 'error' | 'neutral' | 'primary' | Colour of the focus ring and focused border, matching Button (default: 'primary'). |
| shape | 'rounded' | 'square' | 'rounded' | Corner shape (default: 'rounded'). |
| class | string | '' | Classes on the wrapper around label, control and supporting text. |
| labelClass | string | '' | Classes on the label; `[&_[data-field-required]]:…` restyles the required marker. |
| fieldClass | string | '' | Classes on the native control. |
| helpClass | string | '' | Classes on the help text. |
| errorClass | string | '' | Classes on the error text. |
| value | string | — | Submitted value when checked (browser default: 'on'). |
| checked | boolean | false | Initially checked (default: false). |