From bed79e616dac06d6146517de8a774c5fc3b5df44 Mon Sep 17 00:00:00 2001 From: rajun Date: Tue, 27 Oct 2026 16:28:52 +0530 Subject: [PATCH] feat: add logo background field --- .../projects/form/logo-background-field.tsx | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 app/components/projects/form/logo-background-field.tsx diff --git a/app/components/projects/form/logo-background-field.tsx b/app/components/projects/form/logo-background-field.tsx new file mode 100644 index 0000000..ff3d7c3 --- /dev/null +++ b/app/components/projects/form/logo-background-field.tsx @@ -0,0 +1,38 @@ +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 ( + + + + ); +}