import React, { useState } from "react"; // headless ui import { Combobox, Transition } from "@headlessui/react"; import { Search } from "lucide-react"; type Props = { onChange: (value: string[]) => void; value: string[]; }; const FILE_EXTENSIONS: { [category: string]: string[]; } = { image: [".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tif", ".tiff", ".svg", ".eps", ".psd", ".ai"], video: [".mp4", ".avi", ".mkv", ".mpg", ".mpeg", ".flv", ".wmv"], audio: [".mp3", ".wav", ".ogg", ".flac", ".aac"], document: [ ".txt", ".doc", ".docx", ".pdf", ".ppt", ".pptx", ".xls", ".xlsx", ".html", ".htm", ".csv", ".xml", ], }; const searchExtensions = (query: string) => { query = query.toLowerCase(); const filteredExtensions: { [category: string]: string[]; } = {}; for (const category in FILE_EXTENSIONS) { const extensions = FILE_EXTENSIONS[category].filter((extension) => extension.toLowerCase().includes(query) ); if (extensions.length > 0) { filteredExtensions[category] = extensions; } } return filteredExtensions; }; export const FileFormatsDropdown: React.FC = ({ onChange, value }) => { const [query, setQuery] = useState(""); const options = searchExtensions(query); return ( { console.log(val); onChange(val); }} className="relative flex-shrink-0 text-left" multiple > {({ open }: { open: boolean }) => ( <> All Formats
setQuery(e.target.value)} placeholder="Type to search..." displayValue={(assigned: any) => assigned?.name} />
{Object.keys(options).map((category) => options[category].map((extension) => ( `flex items-center gap-1 cursor-pointer select-none truncate rounded px-1 py-1.5 accent-custom-primary-100 ${ active ? "bg-custom-background-80" : "" } ${selected ? "text-custom-text-100" : "text-custom-text-200"}` } > {({ active, selected }) => ( <> {extension} )} )) )}
)}
); };