import { Option, Options, PropsOf } from '@codeleap/types' import { AppIcon, StyledProp } from '@codeleap/styles' import { GetKeyboardAwarePropsOptions, StylesOf } from '../../types/utility' import { ButtonProps } from '../Button' import { Icon } from '../Icon' import { FlatListProps } from '../List' import { ModalProps } from '../Modal' import { Text } from '../Text' import { TextInputComposition } from '../TextInput' import { SearchInputProps } from '../SearchInput' import { Touchable } from '../Touchable' import { SelectComposition } from './styles' import { SelectableField } from '@codeleap/form' export type SelectRenderFNProps = { style: StylesOf onPress: () => void selected?: boolean item: Option touchableProps?: Partial> textProps?: Partial> iconProps?: Partial> index: number debugName: string text?: string } export type SelectRenderFN = (props: SelectRenderFNProps) => React.ReactElement type SelectModalProps = Omit export type SelectValue = Multi extends true ? T[] : T type SelectHeaderProps = { searchComponent?: React.ReactNode } export type SelectOuterInputProps = SelectProps & { currentValueLabel: string styles?: StylesOf clearButton?: Partial } type OuterInputComponent = (props: SelectOuterInputProps) => React.ReactElement /** * `loadOptions` is the escape hatch for server-driven search; when present it suppresses local * `filterItems` and the component reports a loading state while the promise resolves. * `defaultOptions` is shown before any search — omitting it when `loadOptions` is set means the * list is empty until the user types. */ export type ValueBoundSelectProps< T extends string | number, Multi extends boolean = false > = { options?: Options defaultOptions?: Options loadOptions?: (search: string) => Promise> renderItem?: SelectRenderFN> filterItems?: (search: string, items: Options) => Options onLoadOptionsError?: (error: any) => void multiple?: Multi getLabel?: (forOption: Multi extends true ? Options : Option) => string outerInputComponent?: OuterInputComponent inputProps?: Partial> disabled?: boolean } export type ReplaceSelectProps = Omit< Props, keyof ValueBoundSelectProps > & ValueBoundSelectProps export type SelectProps = SelectModalProps & ValueBoundSelectProps & { placeholder?: string label?: string hideInput?: boolean selectedIcon?: AppIcon arrowIconName?: AppIcon closeOnSelect?: boolean listProps?: Partial clearable?: boolean clearIconName?: AppIcon keyboardAware?: GetKeyboardAwarePropsOptions multiple?: Multi itemProps?: Partial, 'iconProps' | 'textProps' | 'touchableProps'>> searchable?: boolean limit?: number ListHeaderComponent?: React.ComponentType ListComponent?: React.ComponentType searchInputProps?: Partial loadOptionsOnMount?: boolean loadOptionsOnOpen?: boolean style?: StyledProp field?: SelectableField value?: T onValueChange?: (value: T) => void onSelect?: (value: T) => void }