import React, { Fragment } from 'react'; import { StyledSelectOption } from './style'; import { useTheme } from '@emotion/react'; import { capitalize } from '../../functions'; import { BnIcon, Checkbox } from '..'; import { Typography } from '../../atoms'; import { ETypography, ETypographyColor, Icons } from '../../types/theme'; type Option = { label: string; value: string | number | Date; icon?: Icons; }; export interface ISelectOptions { options: Option[]; onSelect: (val: unknown) => void; value?: string | string[] | number[] | Date[]; isMultiple?: boolean; autoFocus?: boolean; } export const SelectOptions = ({ options, onSelect, value = [], autoFocus = true, isMultiple = false, }: ISelectOptions) => { const colors = useTheme(); const newValue = Array.isArray(value) ? value : value ? [value] : []; return (
{options.length === 0 &&
No Results
} {options.map((opt, index) => { const val: string = opt.value as string; return ( onSelect(opt.value)} tabIndex={0} autoFocus={autoFocus ? index === 0 : false} > {isMultiple && ( {}} checked={(newValue as string[]) .map((v) => String(v)) .includes(String(val))} /> )} {opt.icon && } {capitalize(opt.label)} {!isMultiple && String(value) === val && } ); })}
); };