Checkbox

A checkbox component for selecting one or multiple options.

Beer Styles

Select your favorite craft beer styles

<Fieldset 
    title="Beer Styles" 
    subtitle="Select your favorite craft beer styles">
    <Field>
        <CheckboxGroup horizontal>
            <Checkbox>IPA</Checkbox>
            <Checkbox defaultChecked>Stout</Checkbox>
            <Checkbox>Pilsner</Checkbox>
        </CheckboxGroup>
    </Field>
</Fieldset>

Overview

The Checkbox component provides a way for users to select one or multiple options from a set. It supports various sizes, labels, and subtitles for additional context. Checkboxes are typically used in forms or settings where users need to toggle options on or off.

Checkbox

Description

A flexible checkbox component that can be used individually or within a CheckboxGroup for managing multiple options.

Usage

import { Checkbox, CheckboxGroup, Field } from "@crafted-ui/react";

<Field>
    <CheckboxGroup>
        <Checkbox>IPA</Checkbox>
        <Checkbox defaultChecked>Stout</Checkbox>
        <Checkbox>Pilsner</Checkbox>
    </CheckboxGroup>
</Field>

Props

The Checkbox component accepts the following props:

PropTypeDefaultDescription
titlestringundefinedThe main label text for the checkbox
subtitlestringundefinedAdditional descriptive text displayed below the title
size’xs’ | ‘sm’ | ‘md’ | ‘lg’ | ‘xl''md’Size of the checkbox indicator
defaultCheckedbooleanfalseInitial checked state (uncontrolled)
checkedbooleanundefinedControlled checked state
classNamestringundefinedAdditional CSS class names
childrenReactNodeundefinedContent to display as the label (used when title is not provided)

The component also accepts all standard HTML input attributes for checkboxes.

CheckboxGroup

Description

A container component for organizing multiple checkboxes with consistent spacing and layout.

Usage

import { CheckboxGroup, Checkbox } from "@crafted-ui/react";

<CheckboxGroup>
    <Checkbox>Option 1</Checkbox>
    <Checkbox>Option 2</Checkbox>
    <Checkbox>Option 3</Checkbox>
</CheckboxGroup>

Props

The CheckboxGroup component accepts the following props:

PropTypeDefaultDescription
horizontalbooleanfalseDisplay checkboxes in a horizontal row instead of vertical column
classNamestringundefinedAdditional CSS class names for custom layout
childrenReactNodeundefinedCheckbox components to display

Basic Usage

Simple Checkboxes

Create a group of checkboxes for selecting beer styles.

Beer Styles

Select your favorite craft beer styles

<Fieldset 
    title="Beer Styles" 
    subtitle="Select your favorite craft beer styles">
    <Field>
        <CheckboxGroup>
            <Checkbox>IPA</Checkbox>
            <Checkbox defaultChecked>Stout</Checkbox>
            <Checkbox>Pilsner</Checkbox>
        </CheckboxGroup>
    </Field>
</Fieldset>

Horizontal Layout

Horizontal Checkboxes

Display checkboxes in a horizontal row using the horizontal prop.

Hop Varieties

Select your preferred hop profiles

<Fieldset 
    title="Hop Varieties" 
    subtitle="Select your preferred hop profiles">
    <Field>
        <CheckboxGroup horizontal>
            <Checkbox>Citra</Checkbox>
            <Checkbox defaultChecked>Mosaic</Checkbox>
            <Checkbox>Cascade</Checkbox>
        </CheckboxGroup>
    </Field>
</Fieldset>

Sizes

Different Checkbox Sizes

Checkboxes support five size variants: xs, sm, md, lg, and xl.

Craft Beer Package Sizes

Select your preferred packaging options

<Fieldset 
    title="Craft Beer Package Sizes" 
    subtitle="Select your preferred packaging options">
    <Field>
        <CheckboxGroup>
            <Checkbox size="xs">Nip</Checkbox>
            <Checkbox size="sm">Sleek</Checkbox>
            <Checkbox size="md" defaultChecked>Tallboy</Checkbox>
            <Checkbox size="lg">Bomber</Checkbox>
            <Checkbox size="xl">Crowler</Checkbox>
        </CheckboxGroup>
    </Field>
</Fieldset>

Labels and Subtitles

Different Labeling Options

Checkboxes can use children as labels, or use the title and subtitle props for more complex labeling.

Brewery Features

Different ways to label checkboxes

<Fieldset 
    title="Brewery Features" 
    subtitle="Different ways to label checkboxes">
    <Field>
        <CheckboxGroup>
            <Checkbox>Taproom</Checkbox>
            <Checkbox title="Outdoor Seating" />
            <Checkbox 
                title="Flight Options" 
                subtitle="Sample multiple beers in smaller portions" 
            />
            <Checkbox 
                title="Seasonal Releases" 
                subtitle="Limited edition and experimental brews" 
                defaultChecked 
            />
        </CheckboxGroup>
    </Field>
</Fieldset>

Horizontal with Subtitles

Horizontal Layout with Descriptions

Combine horizontal layout with subtitles for compact, informative checkbox groups.

Brewing Methods

Select your preferred brewing techniques

<Fieldset 
    title="Brewing Methods" 
    subtitle="Select your preferred brewing techniques">
    <Field>
        <CheckboxGroup horizontal className="gap-6">
            <Checkbox title="Barrel-Aged" />
            <Checkbox 
                title="Dry-Hopped" 
                subtitle="Enhanced hop aroma and flavor" 
                defaultChecked 
            />
            <Checkbox 
                title="Sour Mash" 
                subtitle="Traditional acidic fermentation" 
            />
        </CheckboxGroup>
    </Field>
</Fieldset>

Accessibility

The Checkbox component follows accessibility best practices:

  • Uses semantic HTML with proper label associations
  • Supports keyboard navigation (Space to toggle)
  • Maintains proper focus styles for keyboard users
  • Provides visual feedback for checked/unchecked states
  • Ensures sufficient color contrast for the checkbox indicator

When implementing checkboxes, ensure that:

  1. Labels clearly describe what the checkbox controls
  2. Related checkboxes are grouped using CheckboxGroup
  3. Subtitles provide additional context when needed
  4. Form validation messages are clearly associated with checkbox groups

Examples

Single Checkbox

<Checkbox>Accept terms and conditions</Checkbox>

Controlled Checkbox

const [checked, setChecked] = useState(false);

<Checkbox 
    checked={checked} 
    onChange={(e) => setChecked(e.target.checked)}
>
    Subscribe to newsletter
</Checkbox>

Checkbox with Detailed Description

<Checkbox 
    title="Marketing Communications" 
    subtitle="Receive updates about new products and special offers"
/>

Custom Styled Group

<CheckboxGroup className="grid grid-cols-2 gap-4">
    <Checkbox>Option 1</Checkbox>
    <Checkbox>Option 2</Checkbox>
    <Checkbox>Option 3</Checkbox>
    <Checkbox>Option 4</Checkbox>
</CheckboxGroup>