import type { HTMLAttributes } from 'react'; import React, { useState } from 'react'; import { HexColorInput, HexColorPicker } from 'react-colorful'; import { cn } from '../lib/utils'; import { Popover, PopoverContent, PopoverTrigger } from './popover'; export type ColorPickerProps = { disabled?: boolean; value: string; defaultValue?: string; onChange: (color: string) => void; } & HTMLAttributes; export const ColorPicker = ({ className, disabled = false, value, defaultValue = '#000000', onChange, ...props }: ColorPickerProps) => { const [color, setColor] = useState(value || defaultValue); const [inputColor, setInputColor] = useState(value || defaultValue); const onColorChange = (newColor: string) => { setColor(newColor); setInputColor(newColor); onChange(newColor); }; const onInputChange = (newColor: string) => { setInputColor(newColor); }; const onInputBlur = () => { setColor(inputColor); onChange(inputColor); }; return ( { if (e.key === 'Enter') { e.preventDefault(); onInputBlur(); } }} disabled={disabled} /> ); };