import { useFormContext, useWatch } from 'react-hook-form'; import { Field } from '~/components/ui/field'; import { Input } from '~/components/ui/input'; import { SegmentedControl } from '~/components/ui/segmented-control'; import { ButtonCustomFields } from '~/components/projects/form/button-custom-fields'; import { ColorField } from '~/components/projects/form/color-field'; import { AR_BUTTON_LABEL } from '~/data/ar-viewer/constants'; import { BRAND_COLORS, BUTTON_LABEL_MAX, BUTTON_SIZE_OPTIONS, BUTTON_SIZES, BUTTON_TEXT_COLORS } from '~/data/projects/constants'; import type { ProjectFormValues } from '~/schemas/projects/project-form'; import type { ButtonSize } from '~/types/project'; // The client's "View in your space" button: colour, text colour, label and size export function ButtonStyleFields() { const { register, control, setValue, formState } = useFormContext(); const [size, custom] = useWatch({ control, name: ['arPage.buttonSize', 'arPage.buttonCustom'] }); // Custom starts from the preset that was selected, so the button doesn't jump const changeSize = (next: ButtonSize) => { if (next === 'custom' && size !== 'custom') { const preset = BUTTON_SIZES[size === 'full' ? 'md' : size]; setValue('arPage.buttonCustom', { ...custom, height: preset.height, paddingX: preset.paddingX, radius: preset.height / 2, width: null }, { shouldDirty: true }); } setValue('arPage.buttonSize', next, { shouldDirty: true }); }; return ( <> {size === 'custom' && } ); }