Checkbox Group
A Checkbox Group ties several checkboxes to one value, so a set of independent choices is read and written as a single array. It keeps the group's label, its layout and its disabled state in one place instead of spread across the individual boxes.
Rendered live, with the same build of the library you install.
Vertical:
Horizontal:
CheckboxGroup.tsx
import { useState } from 'react';import { NCheckGroup } from '@nayan-ui/react';const items = [{ label: 'Email', value: 'email' },{ label: 'Push', value: 'push' },{ label: 'SMS', value: 'sms', disabled: true }];const CheckboxGroup = () => {const [value, setValue] = useState<string[]>(['email']);return (<div><h3 className="text-foreground mb-2 mt-4 text-sm font-semibold">Vertical:</h3><div className="mb-5"><NCheckGroup label="Notify me by" items={items} value={value} onChange={setValue} /></div><h3 className="text-foreground mb-2 mt-4 text-sm font-semibold">Horizontal:</h3><NCheckGroup label="Notify me by" items={items} value={value} onChange={setValue} orientation="horizontal" /></div>);};export default CheckboxGroup;
| Name | Type | Default | Details |
|---|---|---|---|
| items | NCheckGroupItem[] | Required | The items prop. |
| value | string[] | Required | The value prop. |
| onChange | (selected: string[]) => void | Required | The onChange prop. |
| orientation | 'horizontal' | 'vertical' | 'vertical' | The orientation prop. |
| label | string | Optional | The label prop. |
| showLabel | boolean | true | The showLabel prop. |
| disabled | boolean | false | The disabled prop. |
| id | string | Optional | The id prop. |
| className | string | '' | The className prop. |
| labelClassName | string | '' | The labelClassName prop. |
| itemClassName | string | '' | The itemClassName prop. |
Other components solving nearby problems.