import { useFormContext, useWatch } from 'react-hook-form'; import { ColorPicker } from '~/components/ui/color-picker'; import { Field } from '~/components/ui/field'; import { LOGO_BACKGROUND_PRESETS } from '~/data/projects/constants'; import { isDarkColor } from '~/lib/color'; import type { ProjectFormValues } from '~/schemas/projects/project-form'; import type { LogoBackground } from '~/types/project'; const PRESET_KEYS = Object.keys(LOGO_BACKGROUND_PRESETS) as LogoBackground[]; const PRESETS = PRESET_KEYS.map((key) => LOGO_BACKGROUND_PRESETS[key]); // Light / Dark presets or any custom colour; a custom colour also decides light vs dark for contrast export function LogoBackgroundField() { const { control, setValue } = useFormContext(); const [logoBg, logoBgColor] = useWatch({ control, name: ['logoBg', 'logoBgColor'] }); const onChange = (hex: string) => { const preset = PRESET_KEYS.find((key) => LOGO_BACKGROUND_PRESETS[key].value === hex); setValue('logoBg', preset ?? (isDarkColor(hex) ? 'dark' : 'light'), { shouldDirty: true }); setValue('logoBgColor', preset ? '' : hex, { shouldDirty: true }); }; return ( ); }