import { SyntheticEvent, useEffect, useRef, useState } from 'react'; import { FormLabel, Icon, Input, InputGroup, InputLeftElement } from '@chakra-ui/core'; import { CustomPicker } from 'react-color'; const { Saturation, Hue } = require('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, hex, 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) => { let value = e.target.value; setValue(value); onChange(value, e); }; return (
Color } />
); } export default CustomPicker(ColorPicker);