From fbdbd133562b6d8203a0f434abd40f6d3c39baa7 Mon Sep 17 00:00:00 2001 From: Christiaan Scheermeijer Date: Tue, 13 Feb 2024 13:43:28 +0100 Subject: [PATCH 1/3] refactor(project): form fields and control elements --- packages/common/types/form.d.ts | 4 +- .../src/components/Account/Account.tsx | 7 +- .../__snapshots__/Account.test.tsx.snap | 32 +- .../src/components/Checkbox/Checkbox.test.tsx | 18 - .../src/components/Checkbox/Checkbox.tsx | 61 -- .../__snapshots__/CheckoutForm.test.tsx.snap | 56 +- .../CustomRegisterField.tsx | 26 +- .../CustomRegisterField.test.tsx.snap | 136 ++--- .../DateField/DateField.module.scss | 105 ---- .../DeleteAccountModal/DeleteAccountModal.tsx | 2 +- .../DevConfigSelector/DevConfigSelector.tsx | 4 +- .../src/components/Dropdown/Dropdown.tsx | 97 ---- .../EditCardPaymentForm.tsx | 8 +- .../EditPasswordForm/EditPasswordForm.tsx | 5 +- .../EditPasswordForm.test.tsx.snap | 38 +- .../ui-react/src/components/Filter/Filter.tsx | 5 +- .../FinalizePayment/FinalizePayment.tsx | 2 +- .../ForgotPasswordForm/ForgotPasswordForm.tsx | 4 +- .../ForgotPasswordForm.test.tsx.snap | 14 +- .../FormField/FormField.module.scss | 22 + .../src/components/FormField/FormField.tsx | 41 ++ .../Input.module.scss} | 64 +- .../ui-react/src/components/Input/Input.tsx | 98 ++++ .../components/LoginForm/LoginForm.test.tsx | 8 +- .../src/components/LoginForm/LoginForm.tsx | 2 +- .../__snapshots__/LoginForm.test.tsx.snap | 30 +- .../components/OfferSwitch/OfferSwitch.tsx | 2 +- .../src/components/Payment/Payment.tsx | 2 +- .../__snapshots__/Payment.test.tsx.snap | 21 +- .../components/PaymentForm/PaymentForm.tsx | 8 +- .../PersonalDetailsForm.tsx | 20 +- .../PersonalDetailsForm.test.tsx.snap | 548 +++++++++++------- .../ui-react/src/components/Radio/Radio.tsx | 54 -- .../RegistrationForm/RegistrationForm.tsx | 25 +- .../RegistrationForm.test.tsx.snap | 36 +- .../Select.module.scss} | 103 ++-- .../ui-react/src/components/Select/Select.tsx | 93 +++ .../Checkbox/Checkbox.module.scss | 27 +- .../form-fields/Checkbox/Checkbox.test.tsx | 24 + .../form-fields/Checkbox/Checkbox.tsx | 71 +++ .../__snapshots__/Checkbox.test.tsx.snap | 11 +- .../CreditCardCVCField.test.tsx | 0 .../CreditCardCVCField/CreditCardCVCField.tsx | 0 .../CreditCardCVCField.test.tsx.snap | 14 +- .../CreditCardExpiryField.test.tsx | 0 .../CreditCardExpiryField.tsx | 0 .../CreditCardExpiryField.test.tsx.snap | 14 +- .../CreditCardNumberField.module.scss | 0 .../CreditCardNumberField.test.tsx | 0 .../CreditCardNumberField.tsx | 0 .../CreditCardNumberField.test.tsx.snap | 14 +- .../DateField/DateField.module.scss | 64 ++ .../{ => form-fields}/DateField/DateField.tsx | 205 ++++--- .../Dropdown/Dropdown.test.tsx | 0 .../form-fields/Dropdown/Dropdown.tsx | 46 ++ .../PasswordField/PasswordField.test.tsx | 0 .../PasswordField/PasswordField.tsx | 25 +- .../__snapshots__/PasswordField.test.tsx.snap | 16 +- .../{ => form-fields}/Radio/Radio.module.scss | 33 +- .../{ => form-fields}/Radio/Radio.test.tsx | 2 +- .../components/form-fields/Radio/Radio.tsx | 56 ++ .../Radio/__snapshots__/Radio.test.tsx.snap | 75 +++ .../TextField/TextField.module.scss | 7 + .../TextField/TextField.test.tsx | 0 .../form-fields/TextField/TextField.tsx | 35 ++ .../__snapshots__/TextField.test.tsx.snap | 48 +- .../ui-react/src/containers/Profiles/Form.tsx | 6 +- packages/ui-react/src/pages/Home/Home.tsx | 2 - .../User/__snapshots__/User.test.tsx.snap | 42 +- packages/ui-react/src/types/form.ts | 15 + .../DemoConfigDialog/DemoConfigDialog.tsx | 2 +- .../DemoConfigDialog.test.tsx.snap | 11 +- 72 files changed, 1526 insertions(+), 1140 deletions(-) delete mode 100644 packages/ui-react/src/components/Checkbox/Checkbox.test.tsx delete mode 100644 packages/ui-react/src/components/Checkbox/Checkbox.tsx delete mode 100644 packages/ui-react/src/components/DateField/DateField.module.scss delete mode 100644 packages/ui-react/src/components/Dropdown/Dropdown.tsx create mode 100644 packages/ui-react/src/components/FormField/FormField.module.scss create mode 100644 packages/ui-react/src/components/FormField/FormField.tsx rename packages/ui-react/src/components/{TextField/TextField.module.scss => Input/Input.module.scss} (64%) create mode 100644 packages/ui-react/src/components/Input/Input.tsx delete mode 100644 packages/ui-react/src/components/Radio/Radio.tsx rename packages/ui-react/src/components/{Dropdown/Dropdown.module.scss => Select/Select.module.scss} (55%) create mode 100644 packages/ui-react/src/components/Select/Select.tsx rename packages/ui-react/src/components/{ => form-fields}/Checkbox/Checkbox.module.scss (81%) create mode 100644 packages/ui-react/src/components/form-fields/Checkbox/Checkbox.test.tsx create mode 100644 packages/ui-react/src/components/form-fields/Checkbox/Checkbox.tsx rename packages/ui-react/src/components/{ => form-fields}/Checkbox/__snapshots__/Checkbox.test.tsx.snap (67%) rename packages/ui-react/src/components/{ => form-fields}/CreditCardCVCField/CreditCardCVCField.test.tsx (100%) rename packages/ui-react/src/components/{ => form-fields}/CreditCardCVCField/CreditCardCVCField.tsx (100%) rename packages/ui-react/src/components/{ => form-fields}/CreditCardCVCField/__snapshots__/CreditCardCVCField.test.tsx.snap (70%) rename packages/ui-react/src/components/{ => form-fields}/CreditCardExpiryField/CreditCardExpiryField.test.tsx (100%) rename packages/ui-react/src/components/{ => form-fields}/CreditCardExpiryField/CreditCardExpiryField.tsx (100%) rename packages/ui-react/src/components/{ => form-fields}/CreditCardExpiryField/__snapshots__/CreditCardExpiryField.test.tsx.snap (69%) rename packages/ui-react/src/components/{ => form-fields}/CreditCardNumberField/CreditCardNumberField.module.scss (100%) rename packages/ui-react/src/components/{ => form-fields}/CreditCardNumberField/CreditCardNumberField.test.tsx (100%) rename packages/ui-react/src/components/{ => form-fields}/CreditCardNumberField/CreditCardNumberField.tsx (100%) rename packages/ui-react/src/components/{ => form-fields}/CreditCardNumberField/__snapshots__/CreditCardNumberField.test.tsx.snap (69%) create mode 100644 packages/ui-react/src/components/form-fields/DateField/DateField.module.scss rename packages/ui-react/src/components/{ => form-fields}/DateField/DateField.tsx (50%) rename packages/ui-react/src/components/{ => form-fields}/Dropdown/Dropdown.test.tsx (100%) create mode 100644 packages/ui-react/src/components/form-fields/Dropdown/Dropdown.tsx rename packages/ui-react/src/components/{ => form-fields}/PasswordField/PasswordField.test.tsx (100%) rename packages/ui-react/src/components/{ => form-fields}/PasswordField/PasswordField.tsx (70%) rename packages/ui-react/src/components/{ => form-fields}/PasswordField/__snapshots__/PasswordField.test.tsx.snap (85%) rename packages/ui-react/src/components/{ => form-fields}/Radio/Radio.module.scss (77%) rename packages/ui-react/src/components/{ => form-fields}/Radio/Radio.test.tsx (94%) create mode 100644 packages/ui-react/src/components/form-fields/Radio/Radio.tsx create mode 100644 packages/ui-react/src/components/form-fields/Radio/__snapshots__/Radio.test.tsx.snap create mode 100644 packages/ui-react/src/components/form-fields/TextField/TextField.module.scss rename packages/ui-react/src/components/{ => form-fields}/TextField/TextField.test.tsx (100%) create mode 100644 packages/ui-react/src/components/form-fields/TextField/TextField.tsx rename packages/ui-react/src/components/{ => form-fields}/TextField/__snapshots__/TextField.test.tsx.snap (72%) create mode 100644 packages/ui-react/src/types/form.ts diff --git a/packages/common/types/form.d.ts b/packages/common/types/form.d.ts index f4616910b..336d1270f 100644 --- a/packages/common/types/form.d.ts +++ b/packages/common/types/form.d.ts @@ -1,5 +1,5 @@ -export type UseFormChangeHandler = React.ChangeEventHandler; -export type UseFormBlurHandler = React.FocusEventHandler; +export type UseFormChangeHandler = React.ChangeEventHandler; +export type UseFormBlurHandler = React.FocusEventHandler; export type UseFormSubmitHandler = React.FormEventHandler; export type GenericFormErrors = { form: string }; diff --git a/packages/ui-react/src/components/Account/Account.tsx b/packages/ui-react/src/components/Account/Account.tsx index 94b61e2c7..9752b12f9 100644 --- a/packages/ui-react/src/components/Account/Account.tsx +++ b/packages/ui-react/src/components/Account/Account.tsx @@ -20,9 +20,9 @@ import Alert from '../Alert/Alert'; import Button from '../Button/Button'; import Form from '../Form/Form'; import IconButton from '../IconButton/IconButton'; -import TextField from '../TextField/TextField'; -import Checkbox from '../Checkbox/Checkbox'; import FormFeedback from '../FormFeedback/FormFeedback'; +import TextField from '../form-fields/TextField/TextField'; +import Checkbox from '../form-fields/Checkbox/Checkbox'; import CustomRegisterField from '../CustomRegisterField/CustomRegisterField'; import Icon from '../Icon/Icon'; import { modalURLFromLocation } from '../../utils/location'; @@ -351,8 +351,9 @@ const Account = ({ panelClassName, panelHeaderClassName, canUpdateEmail = true } name={`consentsValues.${consent.name}`} checked={isTruthyCustomParamValue(section.values.consentsValues?.[consent.name])} onChange={section.onChange} - label={formatConsentLabel(consent.label)} + checkboxLabel={formatConsentLabel(consent.label)} disabled={consent.required || section.isBusy} + required={consent.required} lang={htmlLang} /> ))} diff --git a/packages/ui-react/src/components/Account/__snapshots__/Account.test.tsx.snap b/packages/ui-react/src/components/Account/__snapshots__/Account.test.tsx.snap index 624a6df72..25c330d33 100644 --- a/packages/ui-react/src/components/Account/__snapshots__/Account.test.tsx.snap +++ b/packages/ui-react/src/components/Account/__snapshots__/Account.test.tsx.snap @@ -25,10 +25,10 @@ exports[` > renders and matches snapshot 1`] = ` novalidate="" >