diff --git a/app/components/projects/form/button-custom-fields.tsx b/app/components/projects/form/button-custom-fields.tsx new file mode 100644 index 0000000..c7f2d2b --- /dev/null +++ b/app/components/projects/form/button-custom-fields.tsx @@ -0,0 +1,59 @@ +import { useFormContext, useWatch } from 'react-hook-form'; +import { ColorPicker } from '~/components/ui/color-picker'; +import { Field } from '~/components/ui/field'; +import { Input } from '~/components/ui/input'; +import { BUTTON_CUSTOM_LIMITS, BUTTON_TEXT_COLORS } from '~/data/projects/constants'; +import type { ProjectFormValues } from '~/schemas/projects/project-form'; + +type Measurement = keyof typeof BUTTON_CUSTOM_LIMITS; +const MEASUREMENTS = Object.keys(BUTTON_CUSTOM_LIMITS) as Measurement[]; + +// An empty box is "not set": no width means the button fits its label; anything else must be filled in. +// The form also passes stored values through here (a saved empty width is null), not only typed text. +const toNumber = (optional: boolean) => (value: unknown) => { + if (value === '' || value === null || value === undefined) return optional ? null : Number.NaN; + return Number(value); +}; + +// Exact button measurements for the "Custom" size +export function ButtonCustomFields() { + const { register, control, setValue, formState } = useFormContext(); + const [borderWidth, borderColor] = useWatch({ control, name: ['arPage.buttonCustom.borderWidth', 'arPage.buttonCustom.borderColor'] }); + const errors = formState.errors.arPage?.buttonCustom; + + return ( +
+
+ {MEASUREMENTS.map((key) => { + const { label, min, max } = BUTTON_CUSTOM_LIMITS[key]; + const optional = key === 'width'; + return ( + + + + ); + })} +
+ {borderWidth > 0 && ( + + setValue('arPage.buttonCustom.borderColor', hex, { shouldDirty: true })} + /> + + )} +
+ ); +}