import React, { useEffect, useState } from "react"; // components import { Input } from "../form-fields"; // helpers import { cn } from "../../helpers"; // constants import { MATERIAL_ICONS_LIST } from "./icons"; type TIconsListProps = { defaultColor: string; onChange: (val: { name: string; color: string }) => void; }; const DEFAULT_COLORS = ["#ff6b00", "#8cc1ff", "#fcbe1d", "#18904f", "#adf672", "#05c3ff", "#5f5f5f"]; export const IconsList: React.FC = (props) => { const { defaultColor, onChange } = props; // states const [activeColor, setActiveColor] = useState(defaultColor); const [showHexInput, setShowHexInput] = useState(false); const [hexValue, setHexValue] = useState(""); useEffect(() => { if (DEFAULT_COLORS.includes(defaultColor.toLowerCase())) setShowHexInput(false); else { setHexValue(defaultColor.slice(1, 7)); setShowHexInput(true); } }, [defaultColor]); return ( <>
{showHexInput ? (
HEX # { const value = e.target.value; setHexValue(value); if (/^[0-9A-Fa-f]{6}$/.test(value)) setActiveColor(`#${value}`); }} className="flex-grow pl-0 text-xs text-custom-text-200" mode="true-transparent" autoFocus />
) : ( DEFAULT_COLORS.map((curCol) => ( )) )}
{MATERIAL_ICONS_LIST.map((icon) => ( ))}
); };