Primitives

Checkbox

A labelled checkbox on a native input, with help and error text

Basic

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.

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

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

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

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

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.

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

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

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

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.
idstring—Id of the native control; help and error ids derive from it. Generated when omitted.
namestring—Form field name.
requiredbooleanfalseMarks the control as required and shows a `*` after the label (default: false).
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.
fieldClassstring''Classes on the native control.
helpClassstring''Classes on the help text.
errorClassstring''Classes on the error text.
valuestring—Submitted value when checked (browser default: 'on').
checkedbooleanfalseInitially checked (default: false).