import ChevronDownIcon from 'blockbite-icons/dist/ChevronDown'; import classNames from 'classnames'; import { useState, useEffect } from '@wordpress/element'; import { Button, TextControl, Dropdown } from '@wordpress/components'; import { ButtonToggle } from '@components/ui/ButtonToggle'; import { OptionProps } from '@components/DesignPanel/types'; interface OptionPanelDropdownProps { defaultValue: string; options: { label: string; value: string }[]; onPressedChange: (value: string) => void; swatch?: boolean; } export default function OptionPanelDropdown({ defaultValue, options, swatch, onPressedChange, }: OptionPanelDropdownProps) { const [activeKeyword, setActiveKeyword] = useState(''); const [filteredOptions, setFilteredOptions] = useState([]); useEffect(() => { setFilteredOptions( options.filter((option: OptionProps) => option.label.toLowerCase().includes(activeKeyword.toLowerCase()) ) ); }, [activeKeyword, options]); useEffect(() => { setActiveKeyword(''); setFilteredOptions(options); }, [defaultValue, options]); return ( (
)} renderContent={() => (
setActiveKeyword(value)} autoComplete="off" />
{filteredOptions.length === 0 && (
No options found.
)} {filteredOptions.map((option: OptionProps, index: Number) => ( { onPressedChange(value ? option.value : ''); }} > {swatch && (
)} {option.label} ))}
)} /> ); }