diff --git a/src/shared/components/ColorPicker.client.js b/src/shared/components/ColorPicker.client.js index 832147e..d16a6d2 100644 --- a/src/shared/components/ColorPicker.client.js +++ b/src/shared/components/ColorPicker.client.js @@ -1,16 +1,19 @@ 'use client'; -import { useState, useRef } from 'react'; +import { useState, useRef, useEffect } from 'react'; -const PRESET_COLORS = [ - '#1abc9c', '#2ecc71', '#3498db', '#9b59b6', '#e91e63', - '#f1c40f', '#e67e22', '#e74c3c', '#95a5a6', '#607d8b', - '#11806a', '#1f8b4c', '#206694', '#71368a', '#ad1457', - '#c27c0e', '#a84300', '#992d22', '#979c9f', '#546e7a', -]; +const ROW1 = ['#1abc9c', '#2ecc71', '#3498db', '#9b59b6', '#e91e63', '#f1c40f', '#e67e22', '#e74c3c', '#95a5a6']; +const ROW2 = ['#11806a', '#1f8b4c', '#206694', '#71368a', '#ad1457', '#c27c0e', '#a84300', '#992d22', '#546e7a']; +const PRESET_COLORS = [...ROW1, ...ROW2]; const isValidHex = (hex) => /^#[0-9a-fA-F]{6}$/.test(hex); +const Checkmark = () => ( + + + +); + const ColorPicker = ({ value, onChange, @@ -19,10 +22,15 @@ const ColorPicker = ({ required = false, disabled = false, }) => { - const [hexInput, setHexInput] = useState(value || '#6b7280'); const nativeRef = useRef(null); - const selected = isValidHex(value) ? value.toLowerCase() : '#6b7280'; + const [hexInput, setHexInput] = useState(selected); + + useEffect(() => { + if (isValidHex(value)) setHexInput(value.toLowerCase()); + }, [value]); + + const isCustom = !PRESET_COLORS.map(c => c.toLowerCase()).includes(selected); const handleSwatchClick = (color) => { if (disabled) return; @@ -34,9 +42,7 @@ const ColorPicker = ({ const raw = e.target.value; setHexInput(raw); const normalized = raw.startsWith('#') ? raw : `#${raw}`; - if (isValidHex(normalized)) { - onChange?.(normalized.toLowerCase()); - } + if (isValidHex(normalized)) onChange?.(normalized.toLowerCase()); }; const handleHexBlur = () => { @@ -50,11 +56,6 @@ const ColorPicker = ({ } }; - const handleCustomClick = () => { - if (disabled) return; - nativeRef.current?.click(); - }; - const handleNativeChange = (e) => { const color = e.target.value.toLowerCase(); setHexInput(color); @@ -73,24 +74,18 @@ const ColorPicker = ({

{description}

)} -
-
- {/* Custom color swatch */} +
+ {/* Left: big custom swatch + hex input */} +
- - {/* Preset swatches */} - {PRESET_COLORS.map((color) => { - const isSelected = selected === color.toLowerCase(); - return ( - - ); - })} -
- - {/* Hex input */} -
-
+ + {/* Right: 9×2 preset grid */} +
+ {[ROW1, ROW2].map((row, rowIdx) => ( +
+ {row.map((color) => { + const isSelected = selected === color.toLowerCase(); + return ( + + ); + })} +
+ ))} +
);