import * as React from 'react'; import classnames from 'classnames'; import { FloatingFocusManager, FloatingOverlay, useMergeRefs, } from '@floating-ui/react'; import {isTouchScreen, __DEV__, invariant, generateId} from '../utils'; import Icon from '../icons/Icon'; import SubjectIcon from '../subject-icons/SubjectIcon'; import type {IconTypeType as SubjectIconTypeType} from '../subject-icons/SubjectIcon'; import type {IconTypeType} from '../icons/Icon'; import Text from '../text/Text'; import useSelectMenu from './useSelectMenu'; import useFloatingSelectMenu from './useFloatingSelectMenu'; import useSelectMenuAnimations from './useSelectMenuAnimations'; import SelectMenuOption from './SelectMenuOption'; export type SelectMenuOptionType = { value: string; label: string; icon?: { name: IconTypeType | SubjectIconTypeType; isSubjectIcon?: boolean; }; }; export type SelectMenuSizeType = 's' | 'm' | 'l'; export const SIZE = { S: 's', M: 'm', L: 'l', } as const; const DEFAULT_SIZE = SIZE.M; const ICON_SIZE_MAP = { [SIZE.L]: 32, [SIZE.M]: 24, [SIZE.S]: 16, } as const; type SelectMenuColorType = 'default' | 'white'; export const COLOR = { DEFAULT: 'default', WHITE: 'white', } as const; export type SelectMenuPropsType = { /** * Optional string. Additional class names. */ className?: string; /** * Optional string. Select placeholder text. * @example * @default false * */ valid?: boolean; /** * Optional boolean. Set to true if select is invalid. * @example * @default [] */ options?: ReadonlyArray; /** * Optional array. Select selected options. * @example */ multiSelect?: boolean; /** * Optional boolean. Set when you want to manually controll select popup menu appearance. If not set, the component will manage it itself. * @example * @default undefined */ defaultExpanded?: boolean; /** * Optional boolean. Set to `true` when you want to display option icon (if it has any). * @example */ disabled?: boolean; /** * Set to change the Select size. There are three sizes options: `s`, `m` and `l`. * @example */ color?: SelectMenuColorType | null | undefined; /** * Optional callback. Called by clicking on the any part of the Select component. * @example { * // update component selected options array * }} * options={[{value: 'option1', label: 'Option1'},{value: 'option2', label: 'Select selector'}]} * /> */ // @ts-ignore TS7051 onOptionChange: (SelectMenuOptionType) => unknown; /** * Callback. Called only when expanded state is controlled, called when component informs the expanded state should change. * @example