import { FC, useState } from "react"; import { Popover, Stack, Text } from "../../../components"; import { getOptionLabel } from "../../../utils"; import { dropdownOption } from "./DropdownFilter.styles"; const DropdownFilter: FC = ({ filter, value, selectedFilters, onChange, icons, textStyles, variant, }) => { const [isChecked, setIsChecked] = useState(false); const [isDirty, setIsDirty] = useState(false); const options = filter?.filters || []; if (options.length < 1) return null; const handleOnChange = (checked: boolean, selectedValue: string) => { let newSelected = selectedFilters ? [...selectedFilters] : []; checked ? !newSelected.includes(selectedValue) && newSelected.push(selectedValue) : newSelected.splice(newSelected.indexOf(selectedValue), 1); onChange(filter?.filterValue, newSelected); setIsChecked(checked); setIsDirty(newSelected.length > 0); }; const title = variant === "selectedInTitle" ? getOptionLabel(filter.filterName, options, selectedFilters) : filter.filterName; return ( {options.map((option: any) => { const isChecked = selectedFilters.includes(option.filterGuid); return ( handleOnChange(!isChecked, option.filterGuid)} > {icons?.checked} ); })} ); }; export default DropdownFilter;