Checkbox

A control that allows the user to toggle between checked and not checked.

Installation

bash
npx @smicolon/fasla-ui@latest add checkbox

Run init once per project before adding components. See Installation.

Preview

With Label & Description

Receive emails about new products and features

Get notified about security updates

States

Props

PropTypeDefaultDescription
checkedboolean—Checked state. Use it with onChange.
indeterminatebooleanfalseShows a dash for a partly selected group.
disabledbooleanfalseDisables the checkbox and dims it.
errorbooleanfalseMarks the checkbox as invalid.
labelstring—Label text.
descriptionstring—Secondary line below the label.
namestring—Name submitted with the form.
valuestring—Value submitted when checked.
onChange(event) => void—Called when the checkbox changes.
classNamestring—Extra classes for the component.

Usage

Basic checkbox

tsx
"use client"

import { Checkbox } from "@/components/ui/checkbox"

export function TermsCheckbox() {
  return <Checkbox name="terms" aria-label="Accept terms and conditions" />
}

With label

tsx
"use client"

import { Checkbox } from "@/components/ui/checkbox"

export function TermsCheckbox() {
  return <Checkbox name="terms" label="Accept terms and conditions" />
}

With description

tsx
"use client"

import { Checkbox } from "@/components/ui/checkbox"

export function MarketingCheckbox() {
  return (
    <Checkbox
      name="marketing"
      label="Marketing emails"
      description="Receive emails about new products"
    />
  )
}

Indeterminate state

tsx
"use client"

import { Checkbox } from "@/components/ui/checkbox"

export function SelectAllCheckbox() {
  return <Checkbox label="Select all" indeterminate />
}

Error state

tsx
"use client"

import { Checkbox } from "@/components/ui/checkbox"

export function RequiredCheckbox() {
  return <Checkbox name="terms" label="Required field" required error />
}