/** * @format */ import React, {FC} from 'react' import { Button, Menu, MenuButton, MenuList, MenuOptionGroup, Box, Checkbox, Input, InputGroup, InputLeftElement } from '@chakra-ui/react' import {ChevronDown, ChevronUp} from 'react-feather' import {FaSearch} from 'react-icons/fa' type SelectDropDownProps = { optionList: Array dropdownWidth: any selectedOptions: Array searchInputValue: string selectAll: boolean setSearchInputValue(event: React.ChangeEvent): void handleSelectAll(event: any): void onChange(event: React.ChangeEvent): void } export const CheckBoxDrowpdown: FC = ({ optionList, dropdownWidth, selectedOptions, handleSelectAll, onChange, searchInputValue, setSearchInputValue, selectAll }) => ( {({isOpen}) => ( <> : } width={'100%'} fontWeight={'normal'} variant={'menu'}> {selectedOptions.length === optionList.length || selectedOptions.length === 0 ? 'All' : selectedOptions.map((item, index) => index + 1 === selectedOptions.length ? `${item.name}` : `${item.name}, ` )} } /> {searchInputValue.length === 0 && ( handleSelectAll(e.target.checked)} isChecked={selectAll}> Select All )} {optionList.map((option, index) => { const regex = new RegExp(searchInputValue, 'gi') let string if (searchInputValue) { string = option.name.replace( regex, (match: any) => `${match}` ) } else { string = `${option.name}` } return ( onChange(e)} isChecked={!!selectedOptions.find(item => item.value === option.value)}> ) })} )} )