Checkbox
Checkbox with checked, unchecked and indeterminate states, plus required, hint and visible error.
Code
import * as React from 'react';
import { Checkbox } from '@fruit-labs/design';
export default function Demo() {
return (
<div
style={{
display: 'flex',
flexDirection: 'column',
gap: 12,
}}
>
<Checkbox defaultChecked>Sync photos</Checkbox>
<Checkbox indeterminate>Select all</Checkbox>
<Checkbox hint="You can unsubscribe at any time.">Send me the newsletter</Checkbox>
<Checkbox required error="Accept the terms to continue.">
I accept the terms
</Checkbox>
</div>
);
}A group
import { Checkbox } from '@fruit-labs/design';
export default function Example() {
return (
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 12, alignItems: 'center' }}>
<Checkbox defaultChecked>Product news</Checkbox>
<Checkbox>Weekly digest</Checkbox>
<Checkbox disabled>Security alerts (always on)</Checkbox>
</div>
);
}Install
From npm:
npm install @fruit-labs/design
import { Checkbox } from '@fruit-labs/design';Or copy the TypeScript source into your project:
npx shadcn@latest add https://design.fruitlabs.online/r/checkbox.jsonGuidelines
- Use in forms, lists and table selection. Indeterminate = some children selected.
- Consent boxes:
required+error. With useForm:<Checkbox {...f.field('terms', 'checked')}>I accept the terms</Checkbox>; the error appears under the box on submit and when it's unticked again.
Props
| Prop | Type | Required |
|---|---|---|
checked | boolean | No |
defaultChecked | boolean | No |
indeterminate | boolean | No |
onChange | (checked: boolean) => void | No |
onBlur | () => void | No |
hint | React.ReactNode | No |
error | React.ReactNode | No |
required | boolean | No |
disabled | boolean | No |
name | string | No |
label | string | No |
className | string | No |
children | React.ReactNode | No |