import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';
import { Checkbox } from './checkbox';
# Checkbox
Checkbox is a graphical element that allows users to select one or more options from a set of choices.
## Props
### Label
Use the `label` string prop to set the label of the `Checkbox`
```jsx
import { Checkbox } from '../../component-library';
;
```
### IsChecked
Use the `isChecked` boolean prop to set the checked state of the `Checkbox`
```jsx
import { Checkbox } from '../../component-library';
;
```
### IsIndeterminate
Use the `isIndeterminate` boolean prop to set the indeterminate state of the `Checkbox`
```jsx
import React from 'react';
import { Checkbox, Box } from '../../component-library';
const [checkedItems, setCheckedItems] = React.useState([false, true, false]);
const allChecked = checkedItems.every(Boolean);
const isIndeterminate = checkedItems.some(Boolean) && !allChecked;
const handleIndeterminateChange = () => {
if (allChecked || isIndeterminate) {
setCheckedItems([false, false, false]);
} else {
setCheckedItems([true, true, true]);
}
};
const handleCheckboxChange = (index, value) => {
const newCheckedItems = [...checkedItems];
newCheckedItems[index] = value;
setCheckedItems(newCheckedItems);
};
handleCheckboxChange(0, e.target.checked)}
label="Checkbox 1"
/>
handleCheckboxChange(1, e.target.checked)}
label="Checkbox 2"
/>
handleCheckboxChange(2, e.target.checked)}
label="Checkbox 3"
/>
```
### IsDisabled
Use the `isDisabled` boolean prop to set the disabled state of the `Checkbox`
```jsx
import { Checkbox } from '../../component-library';
;
```
### IsReadOnly
Use the `isReadOnly` boolean prop to set the readOnly attribute of the `Checkbox`
```jsx
import { Checkbox } from '../../component-library';
;
```
### OnChange
Use the `onChange` function prop to set the onChange handler of the `Checkbox`
```jsx
import React from 'react';
import { Checkbox } from '../../component-library';
const [isChecked, setIsChecked] = React.useState(false);
setIsChecked(!isChecked)}
isChecked={isChecked}
label="isReadOnly demo"
/>;
```
### IsRequired
Use the `isRequired` boolean prop to set the required attribute of the `Checkbox`
```jsx
import { Checkbox } from '../../component-library';
;
```
### Title
Use the `title` string prop to set the title attribute of the `Checkbox`
The title attribute is used to provide additional context or information about the checkbox. It is primarily used for browser native tooltip functionality.
```jsx
import { Checkbox } from '../../component-library';
;
```
### Name
Use the `name` string prop to set the name attribute of the `Checkbox`
This is best used when working with a form and submitting the value of the `Checkbox`
```jsx
import { Checkbox } from '../../component-library';
;
```
### InputProps
Use the `inputProps` object prop to add additonal props or attributes to the hidden input element
If needing to pass a ref to the input element, use the `inputRef` prop
```jsx
import { Checkbox } from '../../component-library';
;
```