import React, { ReactElement } from 'react'; import css from '../../utils/css'; import { GroupWrapper } from './StyledCheckbox'; import Checkbox from './Checkbox'; import { CommonProps } from '../common'; export interface CheckboxGroupProps extends CommonProps { /** * Layout to render checkboxes. */ layout?: 'vertical' | 'horizontal'; /** * Checkbox group name, used for form submission. */ name?: string; /** * Change event handler. */ onChange: (value: (string | number)[]) => void; /** * An array of checkbox options to be selected. */ options: { disabled?: boolean; text: string; value: string | number; }[]; /** * Selected value. */ value: (string | number)[]; } const CheckboxGroup = ({ name, value, options, onChange, layout = 'vertical', id, className, style, sx = {}, 'data-test-id': dataTestId, }: CheckboxGroupProps): ReactElement => { return ( {options.map(option => ( { const newValue = e.target.checked ? [...value, option.value] : value.filter(v => v !== option.value); onChange(newValue); }} /> ))} ); }; export default CheckboxGroup;