import React, { useState } from 'react' import Button from '../Button/Button' import EmptyState from '../EmptyState/EmptyState' import Icon from '../Icons/Icon' import { type IconStringList } from '../Icons/Icon.models' import ListLoading from '../Loaders/ListLoading' import SearchBar from '../SearchBar/SearchBar' import SelectDisplay from '../Selects/SelectDisplay/SelectDisplay' import { SideDrawer } from '../SideDrawer/SideDrawer' import styles from './_drawer-select.module.scss' import { type SelectDisplayOption, type SelectDisplayProps, } from '../Selects/SelectDisplay/SelectDisplay' import { c } from '../../translations/LibraryTranslationService' export type DrawerSelectProps = { /** Array of options to be displayed in the SelectDisplay */ options: SelectDisplayProps['options'] /** Header text for the drawer */ header: string /** Function to set the active option */ setActive: SelectDisplayProps['callout'] /** Placeholder text when no option is selected */ placeholder: string /** Currently active option */ active?: SelectDisplayProps['options'][number] /** Optional Icon to be displayed in the button */ buttonIcon?: IconStringList /** Optionally set a loading state */ loading?: boolean /** Optional disabled state */ disabled?: boolean /** Optional test id for the drawer select */ qaTestId?: string } const DrawerSelect = ({ options, active, setActive, buttonIcon, header, placeholder, loading, disabled, qaTestId = 'drawer-select', }: DrawerSelectProps): React.JSX.Element => { const [isDrawerOpen, setIsDrawerOpen] = useState(false) const [search, setSearch] = useState('') const openDrawer = () => { setIsDrawerOpen(true) } const closeDrawer = () => { setIsDrawerOpen(false) } const filteredOptions = options.filter((option) => option.label.toLowerCase().includes(search.toLowerCase()), ) return ( <> {({ close }) => (
{options.length > 10 ? (
{ setSearch(newSearch) }} />
) : null} {loading ? ( ) : filteredOptions.length > 0 ? ( { setActive(option) close() }} active={active?.name} /> ) : ( )}
)} ) } export default DrawerSelect