From d0941ae0a7a17d12cc7004fd0609ea7c7eee3222 Mon Sep 17 00:00:00 2001 From: Romain Le Cellier Date: Wed, 26 Jul 2023 16:53:41 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D(react)=20react-hook-form=20forms?= =?UTF-8?q?=20Login=20examples?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Our forms needs to be usable with react-hook-form --- .../Examples/ReactHookForm/Login.stories.tsx | 85 +++++++++++++++++ .../Examples/ReactHookForm/Sports.stories.tsx | 91 +++++++++++++++++++ 2 files changed, 176 insertions(+) create mode 100644 packages/react/src/components/Forms/Examples/ReactHookForm/Login.stories.tsx create mode 100644 packages/react/src/components/Forms/Examples/ReactHookForm/Sports.stories.tsx diff --git a/packages/react/src/components/Forms/Examples/ReactHookForm/Login.stories.tsx b/packages/react/src/components/Forms/Examples/ReactHookForm/Login.stories.tsx new file mode 100644 index 0000000..8aae6e2 --- /dev/null +++ b/packages/react/src/components/Forms/Examples/ReactHookForm/Login.stories.tsx @@ -0,0 +1,85 @@ +import { yupResolver } from "@hookform/resolvers/yup"; +import { Meta } from "@storybook/react"; +import React from "react"; +import { useForm } from "react-hook-form"; +import * as Yup from "yup"; +import { Input } from ":/components/Forms/Input"; +import { Checkbox } from ":/components/Forms/Checkbox"; +import { Button } from ":/components/Button"; +import { + getFieldState, + getFieldErrorMessage, + onSubmit, +} from ":/tests/reactHookFormUtils"; + +export default { + title: "Components/Forms/Reac-Hook-Form", +} as Meta; + +interface LoginStoryFormValues { + email: string; + password: string; + rememberMe: boolean; +} + +const loginSchema = Yup.object().shape({ + email: Yup.string().email().required(), + password: Yup.string().min(8).required(), + rememberMe: Yup.bool().required().oneOf([true]), +}); + +export const Login = () => { + const { register, handleSubmit, formState } = useForm({ + defaultValues: { + email: "", + password: "", + rememberMe: false, + }, + mode: "onChange", + reValidateMode: "onChange", + resolver: yupResolver(loginSchema), + }); + + return ( +
+

+ Please log-in! +

+ + +
+ +
+ +
+ ); +}; diff --git a/packages/react/src/components/Forms/Examples/ReactHookForm/Sports.stories.tsx b/packages/react/src/components/Forms/Examples/ReactHookForm/Sports.stories.tsx new file mode 100644 index 0000000..5b47f37 --- /dev/null +++ b/packages/react/src/components/Forms/Examples/ReactHookForm/Sports.stories.tsx @@ -0,0 +1,91 @@ +import { Meta } from "@storybook/react"; +import React from "react"; +import { Input } from ":/components/Forms/Input"; +import { Checkbox } from ":/components/Forms/Checkbox"; +import { Button } from ":/components/Button"; +import { Select } from ":/components/Forms/Select"; +import { CunninghamProvider } from ":/components/Provider"; +import { FileUploader } from ":/components/Forms/FileUploader"; +import { Switch } from ":/components/Forms/Switch"; +import { Radio } from ":/components/Forms/Radio"; + +export default { + title: "Components/Forms/Examples", +} as Meta; + + +export const Sports = () => { + return ( + +
+

+ Register +

+
+ + +
+ +
+ + + +
+ + + +
+
+ ); +};