Primitives
CheckboxGroup
A labelled set of checkboxes sharing one form name, on a native fieldset
Basic
---
import CheckboxGroup from '@alfadormx/blocks/primitives/CheckboxGroup.astro';
const interests = [
{ label: 'Laptops', value: 'laptops' },
{ label: 'Phones', value: 'phones' },
{ label: 'Televisions', value: 'televisions' },
];
---
<div class="flex flex-col gap-4 max-w-md">
<CheckboxGroup label="Interests" name="interests" options={interests} />
</div>Help text
---
import CheckboxGroup from '@alfadormx/blocks/primitives/CheckboxGroup.astro';
---
<div class="flex flex-col gap-4 max-w-md">
<CheckboxGroup
label="Notifications"
name="notifications"
help="Pick every channel you want updates on."
options={[
{ label: 'Email', value: 'email', checked: true },
{ label: 'SMS', value: 'sms' },
]}
/>
</div>Horizontal
---
import CheckboxGroup from '@alfadormx/blocks/primitives/CheckboxGroup.astro';
const interests = [
{ label: 'Laptops', value: 'laptops' },
{ label: 'Phones', value: 'phones' },
{ label: 'Televisions', value: 'televisions' },
];
---
<div class="flex flex-col gap-4 max-w-md">
<CheckboxGroup
label="Interests"
name="interests-horizontal"
orientation="horizontal"
options={interests}
/>
</div>Gap
---
import CheckboxGroup from '@alfadormx/blocks/primitives/CheckboxGroup.astro';
const interests = [
{ label: 'Laptops', value: 'laptops' },
{ label: 'Phones', value: 'phones' },
{ label: 'Televisions', value: 'televisions' },
];
const gaps = ['none', 'tight', 'normal', 'loose'] as const;
---
<div class="flex flex-col gap-6 max-w-md">
{gaps.map((gap) => (
<CheckboxGroup
label={`Gap ${gap}`}
name={`interests-gap-${gap}`}
optionsGap={gap}
options={interests}
/>
))}
</div>Error
---
import CheckboxGroup from '@alfadormx/blocks/primitives/CheckboxGroup.astro';
const interests = [
{ label: 'Laptops', value: 'laptops' },
{ label: 'Phones', value: 'phones' },
{ label: 'Televisions', value: 'televisions' },
];
---
<div class="flex flex-col gap-4 max-w-md">
<CheckboxGroup
label="Interests"
name="interests-error"
help="Pick at least one."
error="Choose one or more interests."
options={interests}
/>
</div>Option layer
defaultOptionConfig is merged into every option, under the option’s own fields.
---
import CheckboxGroup from '@alfadormx/blocks/primitives/CheckboxGroup.astro';
---
<div class="flex flex-col gap-4 max-w-md">
<CheckboxGroup
label="Extras"
name="extras"
defaultOptionConfig={{ intent: 'success', shape: 'square' }}
options={[
{ label: 'Installation', value: 'installation', checked: true },
{ label: 'Take away the old one', value: 'takeaway' },
]}
/>
</div>Disabled
---
import CheckboxGroup from '@alfadormx/blocks/primitives/CheckboxGroup.astro';
const interests = [
{ label: 'Laptops', value: 'laptops' },
{ label: 'Phones', value: 'phones' },
{ label: 'Televisions', value: 'televisions' },
];
---
<div class="flex flex-col gap-4 max-w-md">
<CheckboxGroup label="Interests" name="interests-disabled" disabled options={interests} />
</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. |
| 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. |
| helpClass | string | '' | Classes on the help text. |
| errorClass | string | '' | Classes on the error text. |
| name | string | — | Form field name shared by every option. |
| options | Omit<CheckboxProps, 'name'>[] | — | The checkboxes, in order; each needs a unique `value`. |
| orientation | 'horizontal' | 'vertical' | 'vertical' | Flow direction of the options (default: 'vertical'). |
| optionsGap | 'none' | 'tight' | 'normal' | 'loose' | 'normal' | Space between options (default: 'normal'). |
| optionsClass | string | '' | Classes on the wrapper around the options. |
| defaultOptionConfig | LayerConfig<Omit<CheckboxProps, 'name' | 'label'>> | — | Layer merged into every option, under the option's own fields. |