Skip to main content

Checkbox

A basic widget for getting the user input, used for selecting multiple values from several options.

'use client';

import { Checkbox } from 'rizzui/checkbox';

Default

The default style of Checkbox component.

'use client';

import { Checkbox } from 'rizzui/checkbox';

export default function App() {
return <Checkbox label="Remember me" />;
}

Variants

You can change the style of Checkbox using variant property.

'use client';

import { Checkbox } from 'rizzui/checkbox';

export default function App() {
return (
<>
<Checkbox className="m-2" label="Outline" variant="outline" />
<Checkbox className="m-2" label="Flat" variant="flat" />
</>
);
}

Sizes

You can change the sizes of Checkbox using size property.

'use client';

import { Checkbox } from 'rizzui/checkbox';

export default function App() {
return (
<>
<Checkbox className="m-2" label="Small" size="sm" />
<Checkbox className="m-2" label="Default" size="md" />
<Checkbox className="m-2" label="Large" size="lg" />
</>
);
}

Label Placement

You can set label on the two different sides using labelPlacement property.

'use client';

import { Checkbox } from 'rizzui/checkbox';

export default function App() {
return (
<>
<Checkbox className="m-2" label="Left Placement" labelPlacement="left" />
<Checkbox
className="m-2"
label="Right Placement"
labelPlacement="right"
/>
</>
);
}

Disabled

The disabled style of the Checkbox component.

'use client';

import { Checkbox } from 'rizzui/checkbox';

export default function App() {
return <Checkbox className="m-2" label="Left Placement" disabled />;
}

With Helper Text

You can add helper text to Checkbox using helperText property.

Hi! My name is John Doe.
'use client';

import { Checkbox } from 'rizzui/checkbox';

export default function App() {
return (
<Checkbox
className="m-2"
label="John"
value="john"
helperText="Hi! My name is John Doe."
/>
);
}

With Error Message

You can show the validation error message using error property.

'use client';

import { Checkbox } from 'rizzui/checkbox';

export default function App() {
return (
<Checkbox
className="m-2"
label="Yes"
value="yes"
error="This field is required"
/>
);
}

API Reference


Checkbox Props

Here is the API documentation of the Checkbox component. And the rest of the props of Checkbox are the same as the original html input field.

PropsTypeDescriptionDefault
labelReactNodeSet field label__
labelWeightLabelWeightSet label font weight"medium"
labelPlacementleft rightChange label direction"right"
variantCheckboxVariantsThe variants of the component are:"outline"
sizeCheckboxSizesThe size of the component.
"sm" is equivalent to the dense input styling.
"md"
disabledbooleanWhether the input is disabled or not__
indeterminatebooleanWhether the input indeterminate or not__
errorstringShow error message using this prop__
helperTextReactNodeAdd helper text. Can be a string or a React component__
iconClassNamestringUse iconClassName prop to apply some additional style for check mark icon__
labelClassNamestringUse labelClassName prop to apply some additional style for the field label__
inputClassNamestringAdd custom classes for the input field extra style__
helperClassNamestringThis prop allows you to customize the helper message style__
errorClassNamestringThis prop allows you to customize the error message style__
classNamestringAdd custom classes to the root of the component__
refRef<HTMLInputElement>__
...InputHTMLAttributesnative props like value, onChange, onFocus, onBlur ...__

Checkbox Variants

type CheckboxVariants = 'outline' | 'flat';

Label Weight

type LabelWeight = 'normal' | 'medium' | 'semibold' | 'bold';

Checkbox Sizes

type CheckboxSizes = 'sm' | 'md' | 'lg';