import { icons } from "@/lib/client/icons"; import React, { useMemo, useState } from "react"; import Fuse from "fuse.js"; import TextInput from "./TextInput"; import Popover from "./Popover"; import { HexColorPicker } from "react-colorful"; import Icon from "./Icon"; const fuse = new Fuse(icons, { keys: [{ name: "name", weight: 4 }, "tags", "categories"], threshold: 0.2, useExtendedSearch: true, }); type Props = { onClose: Function; alignment?: "left" | "right" | "bottom" | "top"; color: string; setColor: Function; iconName: string; setIconName: Function; weight: "light" | "regular" | "bold" | "fill" | "duotone"; setWeight: Function; className?: string; }; const IconPicker = ({ onClose, alignment, color, setColor, iconName, setIconName, weight, setWeight, className, }: Props) => { const [query, setQuery] = useState(""); const filteredQueryResultsSelector = useMemo(() => { if (!query) { return icons; } return fuse.search(query).map((result) => result.item); }, [query]); return (
setColor(e)} />
setQuery(e.target.value)} />
{filteredQueryResultsSelector.map((icon) => { const IconComponent = icon.Icon; return (
setIconName(icon.pascal_name)} className={`cursor-pointer btn p-1 box-border ${ icon.pascal_name === iconName ? "outline outline-1 outline-primary" : "" }`} >
); })}
); }; export default IconPicker;