// @flow strict import * as React from 'react'; import {classify} from '../../utils/classify'; import {UnstyledButton} from '../Button'; import {Checkbox} from '../Checkbox'; import {Icon} from '../Icon'; import {RadioButton} from '../RadioButton'; import {Truncate} from '../Truncate'; import type {BaseMenuProps, MenuOption} from './Menu'; import css from './Menu.module.css'; export type MenuOptionProps = { ...BaseMenuProps, option: MenuOption, }; export const MenuOptionButton = (props: MenuOptionProps): React.Node => { const { option, size, onSelect, selectedOption, menuDisabled, classNames, optionsVariant = 'normal', selectedKeys, } = props; const { key, label, secondaryLabel, customComponent, iconLeft, iconLeftType, iconRight, iconRightType, disabled, optionSize, optionVariant = optionsVariant, } = option; const [buttonSize, setButtonSize] = React.useState(optionSize || size); const isSelected = () => { if (!selectedKeys || !Array.isArray(selectedKeys) || !selectedKeys.length) { return false; } return selectedKeys.includes(option.key); }; React.useEffect(() => { setButtonSize(optionSize || size); }, [optionSize, size]); return ( onSelect && onSelect(option)} autoFocus={selectedOption?.key === key} > {optionVariant === 'checkbox' && ( )} {optionVariant === 'radio' && ( )} {!!iconLeft && ( )}
{React.isValidElement(customComponent) ? ( customComponent ) : (
{label}
)} {!!secondaryLabel && (
{secondaryLabel}
)}
{!!iconRight && ( )}
); };