Getting Started
Components
- Advanced Toast
- ArrowButton
- Arrows
- Avatar
- Backdrop
- Basic Toast
- Breadcrumb
- Button
- CardBackground
- Card
- ChatButton
- Checkbox
- Checkboxes
- Chip
- ChoiceExpander
- Clickable
- Date Field
- Dropdown
- ElasticHeight
- ExpandableCard
- Filter
- FormCheckbox
- Form Control
- Form Label
- HamburgerIcon
- Heading
- Image
- Link
- Loader
- Number Field
- Pagination
- Password
- Phone Field
- Popin
- Portal
- Prose
- Radio Group
- Radio
- Range
- Select
- SidebarLayout
- Spinner
- Switch
- Tabs
- Tag
- TextField
- ValidationMessage
MIGRATION NOTICE
If you were using this component before, please switch to using FormCheckbox instead. FormCheckbox provides the same visual checkbox along with additional features like labels, validation support, and error messages. The standalone Checkbox component is now simply a visual element and does not include form-related functionality. Expect the same to happen to the Radio component in the future, where it will be replaced by a FormRadio component with enhanced features.
'use client';
import { Clickable } from '@/ui/Clickable';
import { Checkbox } from '@/ui/forms/checkboxes/Checkbox';
import { useState } from 'react';
export function CheckboxDemo() {
const [checked, setChecked] = useState(false);
return (
<div className="space-y-4">
<Clickable onClick={() => setChecked(!checked)}>
<Checkbox id="demo" name="demo" checked={checked} />
</Clickable>
</div>
);
}
Installation
npx shadcn@latest add https://develop.trident-ui.pro.clubmed/r/checkbox.json
Usage
import { Checkbox } from '@/docs/lib/ui/forms/checkboxes/checkbox';
import { useState } from 'react';
export function Component() {
const [checked, setChecked] = useState(false);
return (
<Checkbox
name="name"
value="value"
checked={checked}
onChange={(e) => setChecked(e.target.checked)}
/>
);
}API Reference
Checkbox
| Prop | Type | Default | Description |
|---|---|---|---|
id | string? | generated | The ID attribute for the checkbox |
name | string | id | The name attribute for the checkbox |
className | string | undefined | Additional CSS classes |
disabled | boolean | false | Whether the checkbox is disabled |
checked | boolean | false | Whether the checkbox is checked |
value | string | undefined | The value attribute for the checkbox |
size | string | "size-24" | The size class for the checkbox |
color | Colors | "black" | The color of the checkbox |
tabIndex | number | 0 | The tab index for keyboard navigation |
onChange | (event: ChangeEvent<HTMLInputElement>) => void | undefined | Native onChange handler |
Examples
Disabled uncheckedDisabled checked
'use client';
import { Checkbox } from '@/ui/forms/checkboxes/Checkbox';
export function CheckboxDisabledDemo() {
return (
<div className="space-y-4">
Disabled unchecked
<Checkbox name="disabled-unchecked" value="disabled" disabled></Checkbox>
Disabled checked
<Checkbox name="disabled-checked" value="disabled-checked" disabled checked></Checkbox>
</div>
);
}
Form Usage
For form usage with validation support, labels, and error messages, see FormCheckbox.
Notes
- Controlled Component: This is a fully controlled component. You must manage the
checkedstate andonChangehandler in the parent component. - Native onChange: Uses standard HTML input onChange behavior. Access the checked state via
event.target.checked. - Simple Visual: This component renders just the checkbox visual. For form features like labels and validation, use FormCheckbox.
- Custom Styling: Accepts className prop for style overrides and customization.
- Client Component: This component uses React hooks and must be used in a client component (requires "use client" directive in Next.js App Router).