import React, { type HTMLAttributes } from 'react' import classnames from 'classnames' import { Text } from '~components/Text' import { VisuallyHidden } from '~components/VisuallyHidden' import { type OverrideClassName } from '~components/types/OverrideClassName' import { type MultiSelectOption } from '../../types' import { MultiSelectOptionField } from '../MultiSelectOptionField' import styles from './MultiSelectOptions.module.scss' export type MultiSelectOptionsProps = { id: string options: MultiSelectOption[] selectedValues: Set onChange: (selectedValues: Set) => void } & OverrideClassName, 'onChange'>> export const MultiSelectOptions = ({ id, options, selectedValues, onChange, classNameOverride, ...restProps }: MultiSelectOptionsProps): JSX.Element => { const optionsCountId = `${id}--options-count` const handleOptionChange = (optionValue: MultiSelectOption['value']): void => { const newValues = new Set(selectedValues.values()) if (newValues.has(optionValue)) { newValues.delete(optionValue) } else { newValues.add(optionValue) } onChange(newValues) } return (
Options available: {options.length} {options.length === 0 ? ( No options available ) : ( options.map((option) => ( handleOptionChange(option.value)} checkedStatus={selectedValues.has(option.value) ? 'checked' : 'unchecked'} option={option} /> )) )}
) } MultiSelectOptions.displayName = 'MultiSelectOptions'