diff --git a/packages/react/src/components/checkbox/checkbox.stories.tsx b/packages/react/src/components/checkbox/checkbox.stories.tsx index 8bedf7901d..caa40d35bc 100644 --- a/packages/react/src/components/checkbox/checkbox.stories.tsx +++ b/packages/react/src/components/checkbox/checkbox.stories.tsx @@ -12,6 +12,7 @@ export { Group } from './examples/group' export { GroupControlled } from './examples/group-controlled' export { GroupWithForm } from './examples/group-with-form' export { GroupWithInvalid } from './examples/group-with-invalid' +export { GroupWithSelectAll } from './examples/group-with-select-all' export { Indeterminate } from './examples/indeterminate' export { RenderProp } from './examples/render-prop' export { RootProvider } from './examples/root-provider' diff --git a/packages/react/src/components/checkbox/examples/group-with-select-all.tsx b/packages/react/src/components/checkbox/examples/group-with-select-all.tsx new file mode 100644 index 0000000000..ca2c1c9b7b --- /dev/null +++ b/packages/react/src/components/checkbox/examples/group-with-select-all.tsx @@ -0,0 +1,59 @@ +import { Checkbox } from '@ark-ui/react/checkbox' +import { CheckIcon, MinusIcon } from 'lucide-react' +import { useState } from 'react' + +const items = [ + { label: 'React', value: 'react' }, + { label: 'Solid', value: 'solid' }, + { label: 'Vue', value: 'vue' }, +] + +const CheckboxItem = (props: Checkbox.RootProps) => { + return ( + + {props.children} + + + + + + + + + + + ) +} + +export const GroupWithSelectAll = () => { + const [value, setValue] = useState([]) + + const handleSelectAll = (checked: boolean) => { + setValue(checked ? items.map((item) => item.value) : []) + } + + const allSelected = value.length === items.length + const indeterminate = value.length > 0 && value.length < items.length + + return ( + + handleSelectAll(!!e.checked)} + > + Select All + + + + {items.map((item) => ( + + {item.label} + + ))} + + + Selected: {JSON.stringify(value)} + + ) +}
Selected: {JSON.stringify(value)}