import styled from "@emotion/styled"; import Popover, { PopoverOrigin } from "@mui/material/Popover"; import React, { 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; 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); }; useEffect(() => { setColor(properties.color); }, [properties.color]); const presetColors = [ "#FFFFFF", "#1B717E", "#59B9BC", "#3BB68A", "#8CB354", "#F8CD3C", "#EC5753", "#A23C52", "#D03627", "#523E93", "#3358B7", ]; return ( closePicker(color)} anchorEl={properties.anchorEl.current} anchorOrigin={ properties.anchorOrigin || { vertical: "bottom", horizontal: "left" } } transformOrigin={ properties.transformOrigin || { vertical: "top", horizontal: "left" } } > { setColor(newColor); }} /> {"Hex"} {"#"} { setColor(newColor); }} /> { closePicker(color); }} /> {presetColors.map((presetColor) => (