import React, { useEffect, useState } from "react"; import { InfoIcon, Search } from "lucide-react"; import { cn } from "../../utils/classname"; import { adjustColorForContrast, DEFAULT_COLORS } from "../helper"; import { LucideIconsList } from "./lucide-root"; import { MaterialIconList } from "./material-root"; type IconRootProps = { onChange: (value: { name: string; color: string }) => void; defaultColor: string; searchDisabled?: boolean; iconType: "material" | "lucide"; }; export const IconRoot: React.FC = (props) => { const { defaultColor, onChange, searchDisabled = false, iconType } = props; // states const [activeColor, setActiveColor] = useState(defaultColor); const [showHexInput, setShowHexInput] = useState(false); const [hexValue, setHexValue] = useState(""); const [isInputFocused, setIsInputFocused] = useState(false); const [query, setQuery] = useState(""); useEffect(() => { if (DEFAULT_COLORS.includes(defaultColor.toLowerCase() ?? "")) setShowHexInput(false); else { setHexValue(defaultColor?.slice(1, 7) ?? ""); setShowHexInput(true); } }, [defaultColor]); return ( <>
{!searchDisabled && (
setIsInputFocused(true)} onBlur={() => setIsInputFocused(false)} > setQuery(e.target.value)} className="block rounded-md bg-transparent placeholder-custom-text-400 focus:outline-none px-3 py-2 border-[0.5px] border-custom-border-200 text-[1rem] border-none p-0 h-full w-full" />
)}
{showHexInput ? (
HEX # { const value = e.target.value; setHexValue(value); if (/^[0-9A-Fa-f]{6}$/.test(value)) setActiveColor(adjustColorForContrast(`#${value}`)); }} className="block placeholder-custom-text-400 focus:outline-none px-3 py-2 border-[0.5px] border-custom-border-200 flex-grow pl-0 text-xs text-custom-text-200 rounded border-none bg-transparent ring-0" autoFocus />
) : ( DEFAULT_COLORS.map((curCol) => ( )) )}

Colors will be adjusted to ensure sufficient contrast.

{iconType === "material" ? ( ) : ( )}
); };