import { isEqual, isNil } from 'lodash-es'; import { useCallback, useEffect, useState } from 'react'; import { ActionIcon } from './ActionIcon'; import { ColorPicker } from './ColorPicker'; import styles from './FloatColorPicker.module.css'; type FloatColorPickerProps = { name?: string; color?: string | null; onPick?: (color: string | null | undefined) => void; }; export function FloatColorPicker({ name, color, onPick }: FloatColorPickerProps) { const [pickedColor, setPicked] = useState(color ?? null); const [showPicker, setPickerShow] = useState(false); const handlePickAction = useCallback( (value: string) => { setPicked(value); onPick?.(value); }, [onPick], ); useEffect(() => { if (!isEqual(pickedColor, color)) { setPicked(color); } }, [color]); return (
setPickerShow(true)} style={{ backgroundColor: isNil(pickedColor) ? 'rgba(0, 0, 0, 0)' : `#${pickedColor}`, }}> {isNil(pickedColor) && N/A}
handlePickAction(null)} />
{showPicker && (
)} {!isNil(name) && }
); }