From c6d7f8e4c1b7ede0ef332a675ab288b8fbde262b Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Sat, 2 May 2026 12:32:41 +0330 Subject: [PATCH] color picker clickable --- src/components/ColorPicker.tsx | 71 +++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/src/components/ColorPicker.tsx b/src/components/ColorPicker.tsx index b869dc4..25ac9c1 100644 --- a/src/components/ColorPicker.tsx +++ b/src/components/ColorPicker.tsx @@ -1,7 +1,6 @@ import { type FC, type InputHTMLAttributes, useState, useRef, useEffect } from 'react' import { clx } from '../helpers/utils' import Error from './Error' -import ColorfilterIcon from '@/assets/icons/color.png' type Props = { label?: string @@ -15,6 +14,7 @@ type Props = { const ColorPicker: FC = (props: Props) => { const [color, setColor] = useState(props.value || '#000000') const colorInputRef = useRef(null) + const pickerOpenGuardRef = useRef(false) const inputClass = clx( 'w-full bg-white h-10 text-black block pl-10 pr-10 text-xs rounded-xl border border-border', @@ -37,10 +37,14 @@ const ColorPicker: FC = (props: Props) => { } } - const handleColorIconClick = () => { - if (!props.readOnly) { - colorInputRef.current?.click() - } + const openNativeColorPicker = () => { + if (props.readOnly) return + if (pickerOpenGuardRef.current) return + pickerOpenGuardRef.current = true + colorInputRef.current?.click() + window.setTimeout(() => { + pickerOpenGuardRef.current = false + }, 400) } useEffect(() => { @@ -55,32 +59,53 @@ const ColorPicker: FC = (props: Props) => { {props.label} -
+
- + {/* */} + -
+ + + = (props: Props) => { onChange={handleColorChange} className='absolute opacity-0 pointer-events-none w-0 h-0' /> - - {props.error_text && ( - - )}
+ + {props.error_text && ( + + )}
) }