Primitives

CheckboxGroup

A labelled set of checkboxes sharing one form name, on a native fieldset

Basic

Interests
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

Notifications

Pick every channel you want updates on.

help
---
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

Interests
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

Gap none
Gap tight
Gap normal
Gap loose
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

Interests

Pick at least one.

Choose one or more interests.

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.

Extras
custom
---
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

Interests
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

PropTypeDefaultDescription
labelstring—Visible label; always the control's accessible name, even when hidden.
hideLabelbooleanfalseRenders the label screen-reader-only (default: false).
helpstring—Help text below the control, announced as part of its description.
errorstring—Error text below the control; marks it invalid and forces the `error` intent.
disabledbooleanfalseDisables 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').
classstring''Classes on the wrapper around label, control and supporting text.
labelClassstring''Classes on the label; `[&_[data-field-required]]:…` restyles the required marker.
helpClassstring''Classes on the help text.
errorClassstring''Classes on the error text.
namestring—Form field name shared by every option.
optionsOmit<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').
optionsClassstring''Classes on the wrapper around the options.
defaultOptionConfigLayerConfig<Omit<CheckboxProps, 'name' | 'label'>>—Layer merged into every option, under the option's own fields.