From 9fdd254d9ef010434eeea6dde90cae2c12fc6829 Mon Sep 17 00:00:00 2001 From: Robbert Broersma Date: Tue, 5 Nov 2024 22:35:09 +0100 Subject: [PATCH 01/13] refactor: use NL Design System form components --- .../add/components/questions/RadioInput.tsx | 22 ++-- .../components/IncidentContactForm.tsx | 107 ++++++++++++------ src/components/index.ts | 9 ++ src/components/ui/Form.tsx | 55 ++++----- translations/en.json | 9 +- translations/nl.json | 9 +- 6 files changed, 126 insertions(+), 85 deletions(-) diff --git a/src/app/[locale]/incident/add/components/questions/RadioInput.tsx b/src/app/[locale]/incident/add/components/questions/RadioInput.tsx index 30ba54d..68d9aac 100644 --- a/src/app/[locale]/incident/add/components/questions/RadioInput.tsx +++ b/src/app/[locale]/incident/add/components/questions/RadioInput.tsx @@ -3,7 +3,13 @@ import { useTranslations } from 'next-intl' import { QuestionField } from '@/types/form' import { getValidators } from '@/lib/utils/form-validator' import { useFormContext } from 'react-hook-form' -import { Paragraph } from '@/components/index' +import { + Fieldset, + FieldsetLegend, + FormLabel, + Paragraph, + RadioButton, +} from '@/components/index' interface RadioGroupProps extends QuestionField {} @@ -17,12 +23,12 @@ export const RadioInput = ({ field }: RadioGroupProps) => { const errorMessage = errors[field.key]?.message as string return ( -
- +
+ {field.meta.label}{' '} {field.required ? '' : `(${t('not_required_short')})`} {field.meta.subtitle && {field.meta.subtitle}} - + {errorMessage && ( { {Object.keys(field.meta.values).map((key: string) => (
- { value={key} aria-describedby={errorMessage ? `${field.key}-error` : undefined} /> - +
))} -
+
) } diff --git a/src/app/[locale]/incident/contact/components/IncidentContactForm.tsx b/src/app/[locale]/incident/contact/components/IncidentContactForm.tsx index 8da8d23..ada703d 100644 --- a/src/app/[locale]/incident/contact/components/IncidentContactForm.tsx +++ b/src/app/[locale]/incident/contact/components/IncidentContactForm.tsx @@ -20,10 +20,19 @@ import { Input } from '@/components/ui/Input' import { Checkbox } from '@/components/ui/Checkbox' import { useFormStore } from '@/store/form_store' import { useEffect } from 'react' -import { Paragraph, Heading } from '@/components/index' +import { + Fieldset, + FieldsetLegend, + FormFieldCheckbox, + FormFieldDescription, + FormFieldTextbox, + Heading, + Paragraph, +} from '@/components/index' const IncidentContactForm = () => { const t = useTranslations('describe-contact.form') + const tGeneral = useTranslations('general.describe_form') const { updateForm, formState } = useFormStore() const { addOneStep, setLastCompletedStep } = useStepperStore() const router = useRouter() @@ -65,17 +74,28 @@ const IncidentContactForm = () => { router.push('/incident/summary') } + const invalidTODO = false + const errorMessageTODO = '' + return (
+
+ {t('heading')} + {t('description')} +
-
- {t('heading')} - {t('description')} -
+ { )} /> + { )} /> -
- {t('send_to_other_instance_heading')} - {t('send_to_other_instance_description')} -
-
- ( - - - - - - {t('describe_checkbox_input_description')} - - - )} - /> -
+
+ + {t('send_to_other_instance_heading')} + +
+ + {t('send_to_other_instance_description')} + +
+ + ( + + + + + + {t('describe_checkbox_input_description')} + + + )} + /> +
+
+
diff --git a/src/components/index.ts b/src/components/index.ts index e6085be..f8fdb7b 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -5,9 +5,18 @@ export { Select, Container } export { Alert, + Fieldset, + FieldsetLegend, + FormField, + FormFieldCheckbox, + FormFieldDescription, + FormFieldErrorMessage, + FormFieldTextbox, + FormLabel, Heading, HeadingGroup, Link, Paragraph, PreHeading, + RadioButton, } from '@utrecht/component-library-react/dist/css-module' diff --git a/src/components/ui/Form.tsx b/src/components/ui/Form.tsx index b32a70b..27824f7 100644 --- a/src/components/ui/Form.tsx +++ b/src/components/ui/Form.tsx @@ -13,8 +13,13 @@ import { useFormContext, } from 'react-hook-form' -import { cn } from '@/lib/utils/style' -import { Label } from '@/components/ui/Label' +import { + FormField as UtrechtFormField, + FormFieldDescription, + FormFieldErrorMessage, + FormLabel as UtrechtFormLabel, + Paragraph, +} from '@/components/index' const Form = FormProvider @@ -78,21 +83,12 @@ type FormItemProps = { } & React.HTMLAttributes const FormItem = React.forwardRef( - ({ className, error, ...props }, ref) => { + ({ error, ...props }, ref) => { const id = React.useId() return ( -
+ ) } @@ -105,14 +101,7 @@ const FormLabel = React.forwardRef< >(({ className, ...props }, ref) => { const { error, formItemId } = useFormField() - return ( -