Skip to Content
ComponentsCheckbox

Checkbox

The Checkbox component provides you with checkbox components and groups.

Live Examples

Live Example
☀️
Copy
View Code
import { Checkbox } from '@jarllyng/nostromo' export default function CheckboxExample() { return ( <div className="space-y-4"> <div className="flex items-center space-x-2"> <Checkbox id="terms" /> <label htmlFor="terms">Accept terms and conditions</label> </div> ...

Import

import { Checkbox } from "@jarllyng/nostromo"; // or import { Checkbox } from "@jarllyng/nostromo/checkbox";

Usage

import { Checkbox, Label } from "@jarllyng/nostromo"; export default function Example() { const [checked, setChecked] = React.useState(false); return ( <div className="flex items-center space-x-2"> <Checkbox id="terms" checked={checked} onCheckedChange={setChecked} /> <Label htmlFor="terms">Accept terms</Label> </div> ); }

With Label

Live Example
☀️
Copy
View Code
import { Checkbox, Label } from '@jarllyng/nostromo' export default function CheckboxWithLabel() { return ( <div className="space-y-4"> <div className="flex items-center space-x-2"> <Checkbox id="option1" /> <Label htmlFor="option1">Option 1</Label> </div> <div className="flex items-center space-x-2">...

Props

PropTypeDefaultRequiredDescription
checkedbooleanfalseNoWhether the checkbox is checked (controlled)
defaultCheckedbooleanfalseNoDefault checked state (uncontrolled)
onCheckedChange(checked: boolean) => voidundefinedNoCallback when checked state changes
disabledbooleanfalseNoWhether the checkbox is disabled
requiredbooleanfalseNoWhether the checkbox is required
errorbooleanfalseNoWhether the checkbox is in an error state
labelstringundefinedNoLabel text (alternative to Label component)
helperTextstringundefinedNoHelper text displayed below checkbox
idstringundefinedNoCheckbox ID (auto-generated if not provided)
namestringundefinedNoName for form submission
valuestringundefinedNoValue for form submission
classNamestringundefinedNoAdditional CSS classes

Standard HTML Input Props

The Checkbox component extends all standard HTML input attributes (except size), including:

  • autoFocus, form, formAction, formEncType, formMethod, formNoValidate, formTarget
  • aria-* attributes for accessibility
  • data-* attributes for custom data
Last updated on