feat: add project colour field

This commit is contained in:
rajun 2026-10-27 16:28:52 +05:30
parent e3eb3384ed
commit 46ba48402e

View File

@ -0,0 +1,24 @@
import { useFormContext, useWatch } from 'react-hook-form';
import { ColorPicker } from '~/components/ui/color-picker';
import { Field } from '~/components/ui/field';
import type { ProjectFormValues } from '~/schemas/projects/project-form';
import type { ColorPreset } from '~/types/project';
interface ColorFieldProps {
name: 'brandColor' | 'buttonTextColor';
label: string;
presets: ColorPreset[];
}
// A project form colour bound straight to one form value
export function ColorField({ name, label, presets }: ColorFieldProps) {
const { control, setValue, formState } = useFormContext<ProjectFormValues>();
const value = useWatch({ control, name });
const id = `project-${name}`;
return (
<Field label={label} htmlFor={id} error={formState.errors[name]?.message}>
<ColorPicker id={id} label={label} value={value} presets={presets} onChange={(hex) => setValue(name, hex, { shouldDirty: true })} />
</Field>
);
}