feat: add project colour field
This commit is contained in:
parent
e3eb3384ed
commit
46ba48402e
24
app/components/projects/form/color-field.tsx
Normal file
24
app/components/projects/form/color-field.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user