import { SyntheticEvent, useEffect, useRef, useState } from 'react'; import { FormLabel, Icon, Input, InputGroup, InputLeftElement } from '@chakra-ui/react'; import { Saturation, Hue, ColorWrap as CustomPicker } from 'react-color/lib/components/common'; type ColorPickerProps = { value: string; hex: string; hsl: string; hsv: string; onChange: (s: string, e: SyntheticEvent) => void; }; function ColorPicker({ hsv, hsl, onChange, value: color }: ColorPickerProps) { const [value, setValue] = useState(color); const input = useRef(null); useEffect(() => { if (color !== value && input.current !== document.activeElement) { setValue(color === 'currentColor' ? color : String(color).toUpperCase()); } }, [color]); const handleChange = (e) => { const value = e.target.value; setValue(value); onChange(value, e); }; return (
Color } />
); } export default CustomPicker(ColorPicker);