import React, { useRef } from 'react'; import { mergeProps, useHover, useOption } from 'react-aria'; import type { Node } from 'react-stately'; import { omit } from '../../../../utils/omit'; import { DataList } from '../../../DataList/DataList'; import { Text } from '../../../Typography/Text/Text'; import { getCheckboxProps } from '../../Checkbox/Checkbox'; import type { CommonInputProps } from '../../types'; import type { MultiSelectState } from '../hooks/useMultiSelectState'; interface MultiSelectOptionProps extends Pick { item: Node; state: MultiSelectState; mode: 'content' | 'dropdown' | undefined; } export const MultiSelectOption = ({ item, state, warning, error, mode, ...rest }: MultiSelectOptionProps) => { const ref = useRef(null); const { optionProps, isDisabled, isSelected, isFocused, isFocusVisible } = useOption( { key: item.key, }, state, ref ); const { isHovered, hoverProps } = useHover({ isDisabled: mode === 'content' || isDisabled, }); const checkboxProps = omit( getCheckboxProps({ label: typeof item.rendered === 'string' ? item.rendered : '', error, warning, checked: isSelected, disabled: isDisabled, }), 'checked', 'disabled', 'type' ); return ( {typeof item.rendered === 'string' ? {item.rendered} : item.rendered} ); };