import React, { useEffect, useState, useRef } from "react"; // headless ui import { Tab, Transition, Popover } from "@headlessui/react"; // react colors import { TwitterPicker } from "react-color"; // hooks import useDynamicDropdownPosition from "hooks/use-dynamic-dropdown"; import useOutsideClickDetector from "hooks/use-outside-click-detector"; // types import { Props } from "./types"; // emojis import emojis from "./emojis.json"; import icons from "./icons.json"; // helpers import { getRecentEmojis, saveRecentEmoji } from "./helpers"; import { getRandomEmoji, renderEmoji } from "helpers/emoji.helper"; const tabOptions = [ { key: "emoji", title: "Emoji", }, { key: "icon", title: "Icon", }, ]; const EmojiIconPicker: React.FC = (props) => { const { label, value, onChange, onIconColorChange, disabled = false } = props; // states const [isOpen, setIsOpen] = useState(false); const [openColorPicker, setOpenColorPicker] = useState(false); const [activeColor, setActiveColor] = useState("rgb(var(--color-text-200))"); const [recentEmojis, setRecentEmojis] = useState([]); const buttonRef = useRef(null); const emojiPickerRef = useRef(null); useEffect(() => { setRecentEmojis(getRecentEmojis()); }, []); useEffect(() => { if (!value || value?.length === 0) onChange(getRandomEmoji()); }, [value, onChange]); useOutsideClickDetector(emojiPickerRef, () => setIsOpen(false)); useDynamicDropdownPosition(isOpen, () => setIsOpen(false), buttonRef, emojiPickerRef); return ( setIsOpen((prev) => !prev)} className="outline-none" disabled={disabled} > {label}
{tabOptions.map((tab) => ( {({ selected }) => ( )} ))} {recentEmojis.length > 0 && (

Recent

{recentEmojis.map((emoji) => ( ))}
)}
{emojis.map((emoji) => ( ))}
{["#FF6B00", "#8CC1FF", "#FCBE1D", "#18904F", "#ADF672", "#05C3FF", "#000000"].map((curCol) => ( setActiveColor(curCol)} /> ))}
{ setActiveColor(color.hex); if (onIconColorChange) onIconColorChange(color.hex); }} triangle="hide" width="205px" />

{icons.material_rounded.map((icon, index) => ( ))}
); }; export default EmojiIconPicker;