import { Fragment, useState } from "react"; import { Combobox, Transition } from "@headlessui/react"; import { CheckIcon, ChevronDownIcon } from "@heroicons/react/20/solid"; import React from "react"; export default function MultiSelector({ data, other, label, selected, setSelected, inputRef, }) { // const [selected, setSelected] = useState(); const [query, setQuery] = useState(""); const filteredMain = query === "" ? data : data.filter((item) => item.name .toLowerCase() .replace(/\s+/g, "") .includes(query.toLowerCase().replace(/\s+/g, "")) ); const filteredOther = query === "" ? other : other.filter((item) => item.name .toLowerCase() .replace(/\s+/g, "") .includes(query.toLowerCase().replace(/\s+/g, "")) ); return (
{label}
item?.map((item) => item?.name).join(", ")} placeholder="Any" onChange={(event) => setQuery(event.target.value)} />
setQuery("")} > {filteredOther.length === 0 && filteredMain.length === 0 && query !== "" ? (
Nothing found.
) : (
GENRES
{filteredMain.map((item) => ( `relative cursor-pointer select-none py-2 px-2 ml-2 mr-1 rounded-md ${ active ? "bg-white/5 text-action" : "text-gray-300" }` } value={item} > {({ selected, active }) => ( {item.name} {selected ? ( ) : null} )} ))}
TAGS
{filteredOther.map((item) => ( `relative cursor-pointer select-none py-2 px-2 ml-2 mr-1 rounded-md ${ active ? "bg-white/5 text-white" : "text-gray-300" }` } value={item} > {({ selected, active }) => ( {item.name} {selected ? ( ) : null} )} ))}
)}
); }