import type { ReactNode } from 'react' import React from 'react' import type { Option, OptionGroups, ItemProps, Selection } from '../SelectBase' import { isOptionsType } from '../SelectBase' export interface Props { options: Option[] | OptionGroups selection: Selection renderOption: (option: Option, index: number) => ReactNode getItemProps: (option: Option, index: number) => ItemProps } const renderOptions = ({ options, getItemProps, renderOption, selection, }: Pick & { options: Option[] }) => { return ( <> {options.map((option, index) => ( ))} ) } const NativeSelectOptions = ({ options, renderOption, getItemProps, selection, }: Props) => { if (isOptionsType(options)) { return renderOptions({ options, getItemProps, renderOption, selection }) } return ( <> {Object.keys(options).map(group => ( {renderOptions({ options: options[group], getItemProps, renderOption, selection, })} ))} ) } NativeSelectOptions.displayName = 'NativeSelectOptions' export default NativeSelectOptions