import { icons } from "@/lib/client/icons"; import React, { useMemo, useState, lazy, Suspense } from "react"; import Fuse from "fuse.js"; import TextInput from "./TextInput"; import Popover from "./Popover"; import { HexColorPicker } from "react-colorful"; import { useTranslation } from "next-i18next"; import Icon from "./Icon"; import { IconWeight } from "@phosphor-icons/react"; type Props = { alignment?: "left" | "right"; color: string; setColor: Function; iconName?: string; setIconName: Function; weight: "light" | "regular" | "bold" | "fill" | "duotone" | "thin"; setWeight: Function; reset: Function; className?: string; }; const IconPicker = ({ alignment, color, setColor, iconName, setIconName, weight, setWeight, className, reset, }: Props) => { const fuse = new Fuse(icons, { keys: [{ name: "name", weight: 4 }, "tags", "categories"], threshold: 0.2, useExtendedSearch: true, }); const { t } = useTranslation(); const [query, setQuery] = useState(""); const [iconPicker, setIconPicker] = useState(false); const filteredQueryResultsSelector = useMemo(() => { if (!query) { return icons; } return fuse.search(query).map((result) => result.item); }, [query]); return (
setIconPicker(!iconPicker)} className="btn btn-square w-20 h-20" > {iconName ? ( ) : ( )}
{iconPicker && ( setIconPicker(false)} className={ className + " fade-in bg-base-200 border border-neutral-content p-2 h-44 w-[22.5rem] rounded-lg backdrop-blur-sm bg-opacity-90 top-20 left-0 lg:-translate-x-1/3" } >
} > {t("reset")}
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 bg-base-100 border-none aspect-square ${ icon.pascal_name === iconName ? "outline outline-1 outline-primary" : "" }`} >
); })}
)}
); }; export default IconPicker;