radkradk

Checkbox

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

Installation

npx radk add checkbox

Usage

import { Checkbox } from "@/components/ui/checkbox"
<Checkbox id="terms" />

Examples

With Label

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

<div className="flex items-center space-x-2">
  <Checkbox id="terms" />
  <Label htmlFor="terms">Accept terms and conditions</Label>
</div>

Disabled

<div className="flex items-center space-x-2">
  <Checkbox id="disabled" disabled />
  <Label htmlFor="disabled" className="text-muted-foreground">
    Disabled
  </Label>
</div>

Controlled

"use client"

import { useState } from "react"

export function CheckboxControlled() {
  const [checked, setChecked] = useState(false)

  return (
    <div className="flex items-center space-x-2">
      <Checkbox
        id="controlled"
        checked={checked}
        onCheckedChange={setChecked}
      />
      <Label htmlFor="controlled">
        {checked ? "Checked" : "Unchecked"}
      </Label>
    </div>
  )
}