'use client' import * as React from 'react' import { HexColorPicker } from 'react-colorful' import { cn } from '@/utils/cn' import { Input } from '@/components/ui/input' interface ColorPickerProps { color: string onChange: (color: string) => void presets?: string[] className?: string } const defaultPresets = [ '#171412', '#2E241C', '#8A6742', '#B79267', '#D0B08C', '#E8DFD1', '#FFFDF8', '#8F7CFF', '#45D4FF', '#FF78B8', '#48D7C2', '#FFB86B', ] export function ColorPicker({ color, onChange, presets = defaultPresets, className, }: ColorPickerProps) { const [inputValue, setInputValue] = React.useState(color) React.useEffect(() => { setInputValue(color) }, [color]) const handleInputChange = (e: React.ChangeEvent) => { const val = e.target.value setInputValue(val) if (/^#[0-9A-F]{3,6}$/i.test(val)) { onChange(val) } } return (
{presets.length > 0 && (
{presets.map((p) => (
)}
) }