import styled from "@emotion/styled"; import Popover, { type PopoverOrigin } from "@mui/material/Popover"; import type React from "react"; import { useEffect, useRef, useState } from "react"; import { HexColorInput, HexColorPicker } from "react-colorful"; import { theme } from "../theme"; type ColorPickerProps = { className?: string; color: string; onChange: (color: string) => void; onClose: () => void; anchorEl: React.RefObject; anchorOrigin?: PopoverOrigin; transformOrigin?: PopoverOrigin; open: boolean; }; const colorPickerWidth = 240; const colorfulHeight = 185; // 150 + 15 + 20 const ColorPicker = (properties: ColorPickerProps) => { const [color, setColor] = useState(properties.color); const recentColors = useRef([]); const closePicker = (newColor: string): void => { const maxRecentColors = 14; properties.onChange(newColor); const colors = recentColors.current.filter((c) => c !== newColor); recentColors.current = [newColor, ...colors].slice(0, maxRecentColors); }; const handleClose = (): void => { properties.onClose(); }; useEffect(() => { setColor(properties.color); }, [properties.color]); const presetColors = [ "#FFFFFF", "#1B717E", "#59B9BC", "#3BB68A", "#8CB354", "#F8CD3C", "#EC5753", "#A23C52", "#D03627", "#523E93", "#3358B7", ]; return ( { setColor(newColor); }} /> {"Hex"} {"#"} { setColor(newColor); }} /> { closePicker(color); }} /> {presetColors.map((presetColor) => (