import { useDebouncedCallback } from '@mantine/hooks'; import { ViewSettings } from 'ontime-types'; import { UseControllerProps, useController } from 'react-hook-form'; import { IoEyedrop } from 'react-icons/io5'; import { cx, getAccessibleColour } from '../../../utils/styleUtils'; import PopoverPicker from '../popover-picker/PopoverPicker'; import style from './SwatchSelect.module.scss'; interface SwatchPickerProps { color: string; isSelected?: boolean; onChange: (name: string) => void; alwaysDisplayColor?: boolean; } export default function SwatchPicker(props: SwatchPickerProps) { const { color, onChange, isSelected, alwaysDisplayColor } = props; const debouncedOnChange = useDebouncedCallback((newValue: string) => { onChange(newValue); }, 100); const displayColor = alwaysDisplayColor || isSelected ? color : ''; const { color: iconColor } = getAccessibleColour(displayColor); return (
); } export function SwatchPickerRHF(props: UseControllerProps) { const { name, control } = props; const { field: { onChange, value }, } = useController({ control, name }); const displayColor = typeof value === 'string' ? value : ''; const { color: iconColor } = getAccessibleColour(displayColor); return (
); }