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
This field is required
'use client';
import { FormCheckbox } from '@/ui/forms/checkboxes/FormCheckbox';
import { useState } from 'react';
export function FormCheckboxDemo() {
const [checked1, setChecked1] = useState(false);
const [checked2, setChecked2] = useState(false);
return (
<div className="space-y-4">
<FormCheckbox
name="demo"
value="demo-value"
checked={checked1}
onChange={(e) => setChecked1(e.target.checked)}
>
Basic checkbox
</FormCheckbox>
<FormCheckbox
name="demo2"
value="demo-value2"
checked={checked2}
onChange={(e) => setChecked2(e.target.checked)}
validationStatus="error"
errorMessage="This field is required"
>
Checkbox with validation
</FormCheckbox>
</div>
);
}
Installation
npx shadcn@latest add https://develop.trident-ui.pro.clubmed/r/form-checkbox.json
Usage
import { FormCheckbox } from '@/docs/lib/ui/forms/checkboxes/form-checkbox';
import { useState } from 'react';
export function Component() {
const [checked, setChecked] = useState(false);
return (
<FormCheckbox
name="name"
value="value"
checked={checked}
onChange={(e) => setChecked(e.target.checked)}
validationStatus="default"
>
Checkbox label
</FormCheckbox>
);
}With Validation
import { FormCheckbox } from '@/docs/lib/ui/forms/checkboxes/form-checkbox';
import { useState } from 'react';
export function Component() {
const [checked, setChecked] = useState(false);
const [error, setError] = useState('This field is required');
return (
<FormCheckbox
name="terms"
value="accepted"
checked={checked}
onChange={(e) => {
setChecked(e.target.checked);
setError(e.target.checked ? '' : 'This field is required');
}}
validationStatus={error ? 'error' : 'default'}
errorMessage={error}
>
I agree to the terms and conditions
</FormCheckbox>
);
}API Reference
FormCheckbox
| 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 for container |
dataTestId | string | undefined | The data-testid attribute for testing |
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 |
validationStatus | "default" | "error" | "success" | "default" | Validation status for styling |
errorMessage | string | undefined | Error message to display when status=error |
children | ReactNode | undefined | Label content displayed next to checkbox |
onChange | (event: ChangeEvent<HTMLInputElement>) => void | undefined | Native onChange handler |
Examples
Disabled State
'use client';
import { FormCheckbox } from '@/ui/forms/checkboxes/FormCheckbox';
export function FormCheckboxDisabledDemo() {
return (
<div className="space-y-4">
<FormCheckbox name="disabled-unchecked" value="disabled" disabled>
Disabled unchecked
</FormCheckbox>
<FormCheckbox name="disabled-checked" value="disabled-checked" disabled checked>
Disabled checked
</FormCheckbox>
</div>
);
}
Relationship to Checkbox
FormCheckbox is a wrapper around the Checkbox component that provides:
- Label support via
childrenprop (displayed next to the checkbox) - Built-in validation status handling
- Error message display with icon
- Container structure with data-testid support
When to use each:
- Use FormCheckbox when building forms with validation requirements
- Use Checkbox when you need a simple checkbox visual without form wrapper features
Notes
- Controlled Component: This is a fully controlled component. You must manage the
checkedstate andonChangehandler in the parent component. - Validation Display: Error messages appear below the checkbox when
validationStatus="error"anderrorMessageis provided. - Disabled Priority: Disabled state takes precedence over validation states. When disabled, validation styling is replaced with disabled styling.
- Label Rendering: The
childrenprop renders as label text next to the checkbox within a<label>element for proper accessibility. - Client Component: This component uses React hooks and must be used in a client component (requires "use client" directive in Next.js App Router).