DocsComponentsTemplatesThemesGitHub

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.json

Guidelines

  • 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

PropTypeRequired
checkedbooleanNo
defaultCheckedbooleanNo
indeterminatebooleanNo
onChange(checked: boolean) => voidNo
onBlur() => voidNo
hintReact.ReactNodeNo
errorReact.ReactNodeNo
requiredbooleanNo
disabledbooleanNo
namestringNo
labelstringNo
classNamestringNo
childrenReact.ReactNodeNo

Edit this example on GitHub