From 640a270e1de2cbdb70c847f994dfbecdcfd2fe07 Mon Sep 17 00:00:00 2001 From: Konstantin Schaper Date: Fri, 14 May 2021 09:08:57 +0200 Subject: [PATCH] refactor form fields to enable usage with react-hook-form (#1656) React Hook Form is a library that makes working with forms easier and reduces boilerplate. For it to be used in our project, some of the form fields had to be adjusted. --- gradle/changelog/react_hook_form.yaml | 2 + scm-ui/ui-components/package.json | 1 + .../src/__snapshots__/storyshots.test.ts.snap | 963 ++++++++++++++++-- .../src/forms/Checkbox.stories.tsx | 74 +- scm-ui/ui-components/src/forms/Checkbox.tsx | 109 +- scm-ui/ui-components/src/forms/DropDown.tsx | 3 + .../src/forms/FormFieldTypes.tsx | 81 ++ .../src/forms/InputField.stories.tsx | 124 +++ scm-ui/ui-components/src/forms/InputField.tsx | 148 +-- .../ui-components/src/forms/Radio.stories.tsx | 77 +- scm-ui/ui-components/src/forms/Radio.tsx | 82 +- .../src/forms/Select.stories.tsx | 130 +++ scm-ui/ui-components/src/forms/Select.tsx | 121 ++- .../src/forms/Textarea.stories.tsx | 100 +- scm-ui/ui-components/src/forms/Textarea.tsx | 111 +- .../ui-components/src/forms/useAutofocus.ts | 50 + scm-ui/ui-components/src/forms/useInnerRef.ts | 43 + scm-ui/ui-plugins/package.json | 1 + scm-ui/ui-webapp/package.json | 1 + scm-ui/ui-webapp/src/containers/loadBundle.ts | 6 +- yarn.lock | 5 + 21 files changed, 1926 insertions(+), 306 deletions(-) create mode 100644 gradle/changelog/react_hook_form.yaml create mode 100644 scm-ui/ui-components/src/forms/FormFieldTypes.tsx create mode 100644 scm-ui/ui-components/src/forms/InputField.stories.tsx create mode 100644 scm-ui/ui-components/src/forms/Select.stories.tsx create mode 100644 scm-ui/ui-components/src/forms/useAutofocus.ts create mode 100644 scm-ui/ui-components/src/forms/useInnerRef.ts diff --git a/gradle/changelog/react_hook_form.yaml b/gradle/changelog/react_hook_form.yaml new file mode 100644 index 0000000000..a0165ffe22 --- /dev/null +++ b/gradle/changelog/react_hook_form.yaml @@ -0,0 +1,2 @@ +- type: added + description: Add support for react-hook-form ([#1656](https://github.com/scm-manager/scm-manager/pull/1656)) diff --git a/scm-ui/ui-components/package.json b/scm-ui/ui-components/package.json index 1b1546a772..a3eef7c72e 100644 --- a/scm-ui/ui-components/package.json +++ b/scm-ui/ui-components/package.json @@ -72,6 +72,7 @@ "react": "^17.0.1", "react-diff-view": "^2.4.1", "react-dom": "^17.0.1", + "react-hook-form": "^7.5.1", "react-i18next": "^10.13.1", "react-router-dom": "^5.1.2", "react-select": "^2.1.2", diff --git a/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap b/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap index 4ff705e8e8..0d04539dc4 100644 --- a/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap +++ b/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap @@ -46421,8 +46421,6 @@ exports[`Storyshots Forms|AddKeyValueEntryToTableField Default 1`] = ` onBlur={[Function]} onChange={[Function]} onKeyPress={[Function]} - placeholder="" - type="text" value="" /> @@ -46444,8 +46442,6 @@ exports[`Storyshots Forms|AddKeyValueEntryToTableField Default 1`] = ` onBlur={[Function]} onChange={[Function]} onKeyPress={[Function]} - placeholder="" - type="text" value="" /> @@ -46497,8 +46493,6 @@ exports[`Storyshots Forms|AddKeyValueEntryToTableField Disabled 1`] = ` onBlur={[Function]} onChange={[Function]} onKeyPress={[Function]} - placeholder="" - type="text" value="" /> @@ -46521,8 +46515,6 @@ exports[`Storyshots Forms|AddKeyValueEntryToTableField Disabled 1`] = ` onBlur={[Function]} onChange={[Function]} onKeyPress={[Function]} - placeholder="" - type="text" value="" /> @@ -46558,21 +46550,18 @@ exports[`Storyshots Forms|Checkbox Default 1`] = ` >
@@ -46582,21 +46571,18 @@ exports[`Storyshots Forms|Checkbox Default 1`] = ` >
@@ -46606,21 +46592,18 @@ exports[`Storyshots Forms|Checkbox Default 1`] = ` >
@@ -46637,22 +46620,20 @@ exports[`Storyshots Forms|Checkbox Disabled 1`] = ` >
@@ -46660,6 +46641,132 @@ exports[`Storyshots Forms|Checkbox Disabled 1`] = ` `; +exports[`Storyshots Forms|Checkbox Legacy Events 1`] = ` +Array [ +
+
+ +
+
, +
+ false +
, +] +`; + +exports[`Storyshots Forms|Checkbox ReactHookForm 1`] = ` +
+
+
+ +
+
+
+
+ +
+
+
+ +
+
+`; + +exports[`Storyshots Forms|Checkbox Ref 1`] = ` +Array [ +
+
+ +
+
, + , +] +`; + exports[`Storyshots Forms|Checkbox With HelpText 1`] = `