import { useRef, useState, useEffect } from 'react' import { useHue } from './hooks/useHue' import { useSaturationValue } from './hooks/useSaturationValue' import { useHex } from './hooks/useHex' import styles from './styles.module.css' import { Icon, Text } from '../../../atoms' import { getGlobalStyle } from '../../../../helpers' interface InputColorProps { label?: string value?: string position?: 'top' | 'bottom' onChange?: (hex: string) => void } export const InputColor: React.FC = ({ position = 'bottom', label = 'Color', value, onChange }) => { const pickerRef = useRef(null) const [open, setOpen] = useState(false) const { hue, update: updateHue, onKey: onHueKey } = useHue() const { sv, update: updateSV, onKey: onSVKey } = useSaturationValue() const { hex } = useHex(hue, sv, onChange, value) // cerrar por fuera useEffect(() => { const close = (e: MouseEvent) => { if (pickerRef.current && !pickerRef.current.contains(e.target as Node)) { setOpen(false) } } document.addEventListener('mousedown', close) return () => document.removeEventListener('mousedown', close) }, []) const positionStyles: Record<'top' | 'bottom', React.CSSProperties> = { top: { top: '-220px' }, bottom: { top: '65px' } } return (
{label && ( {label} )}
)} ) }