import { useRef, useState } from "react"; import { ChevronDownIcon, SearchIcon } from "@heroicons/react/solid"; import classNames from "classnames"; import { useClickAway, useUpdateEffect } from "react-use"; import { Dropdown } from "components/search/comps/dropdown"; import { useSearch } from "./hooks/useSearch"; import { useIntl } from "react-intl"; export const Search = ({ search, setSearch, }: { search: string; setSearch: (t: string) => void; }) => { const intl = useIntl(); const [dropdownSearch, setDropdownSearch] = useState(""); const [dropdown, setDropdown] = useState(false); const [tags, setTags] = useState([]); const dropdownRef = useRef(null); const inputRef = useRef(null); useSearch(search, tags); useClickAway(dropdownRef, () => setDropdown(false)); const handleSelect = (tag: string) => { if (tags.includes(tag)) { setTags(tags.filter((t) => t !== tag)); } else { setTags([...tags, tag]); } }; useUpdateEffect(() => { if (dropdown) { inputRef?.current?.focus(); } }, [dropdown]); return (
setSearch(target.value)} />
setDropdown(true)} >
{dropdown ? ( setDropdownSearch(target.value)} /> ) : (

{intl.formatMessage({ id: "iconsEditor.editor.listIcons.category", })}

)}
{tags.length}
); };