import { TextFieldProps, StandardProps } from '@material-ui/core'; import { AutocompleteProps, AutocompleteClassKey, } from '@material-ui/lab/Autocomplete'; import { UseAutocompleteCommonProps, UseAutocompleteMultipleProps, UseAutocompleteSingleProps, } from '@material-ui/lab/useAutocomplete'; import { Option } from './Option'; import { AddItemProps } from './AddItem'; export type PopupContentsCommonProps = { onClose: () => void; onSelectAll: () => void; onClear: () => void; /** Used as the label for the search box and no options text */ labelPlural?: string; /** * Backup label if `labelPlural` is `undefined`. * Also used for “add item” text */ label?: string; /** Optionally prevent the user from searching options */ searchable?: boolean; /** Optionally prevent the user to select all options if `multiple: true` */ selectAll?: boolean; /** Optionally prevent from clearing the value */ clearable?: boolean; /** * Optionally allow the user to add any custom value. * Option value **must** be string */ freeText?: boolean; /** Optionally override the text shown in the count on the left of the footer */ countText?: React.ReactNode; /** * Optionally override how each option is rendered, while still showing the * checkbox or radio icon. * * To hide or change the icon, use * [Autocomplete’s `renderOption` prop](https://material-ui.com/api/autocomplete/) */ itemRenderer?: (option: Option, selected: boolean) => React.ReactNode; /** * Override certain props of the search box MUI TextField component. * [See props here](https://material-ui.com/api/text-field/) */ SearchBoxProps?: Partial; /** * Override certain props of the Autocomplete component. * [See props here](https://material-ui.com/api/autocomplete/) */ AutocompleteProps?: Partial< ExposedUseAutocompleteProps & ExposedAutocompleteProps >; /** * Override certain props of the “Add New” Button component. * [See props here](https://material-ui.com/api/button/) */ AddButtonProps?: AddItemProps['AddButtonProps']; /** Override certain props of the “Add New” Dialog. */ AddDialogProps?: AddItemProps['AddDialogProps']; }; // AutocompleteProps that can be overridden from the root MultiSelect props type ExposedAutocompleteProps = Omit< AutocompleteProps>, | keyof UseAutocompleteCommonProps> | keyof StandardProps< React.HTMLAttributes, AutocompleteClassKey, 'defaultValue' | 'onChange' | 'children' > | 'disabled' | 'disablePortal' | 'multiple' | 'PaperComponent' | 'PopperComponent' | 'renderTags' | 'renderInput' > & { classes: Partial> }; // UseAutocompleteProps that can be overridden from the root MultiSelect props type ExposedUseAutocompleteProps = Omit< UseAutocompleteCommonProps>, | 'open' | 'getOptionLabel' | 'getOptionSelected' | 'clearOnBlur' | 'disableCloseOnSelect' | 'onOpen' | 'openOnFocus' >; export type PopupContentsMultipleProps = { multiple: true; options: Option[]; value: Option[]; max?: number; onChange: NonNullable>['onChange']>; } & PopupContentsCommonProps; export type PopupContentsSingleProps = { multiple: false; options: Option[]; value: Option | null; max?: undefined; onChange: NonNullable>['onChange']>; } & PopupContentsCommonProps; // Explicitly separate type intersections based off `multiple` prop export type PopupContentsProps = | PopupContentsMultipleProps | PopupContentsSingleProps;