From f9e572c1b557e93aa542e86e1bed419223e6b516 Mon Sep 17 00:00:00 2001 From: NgocNhi123 Date: Wed, 26 Jun 2024 23:03:11 +0700 Subject: [PATCH] fix lint --- core/src/date-input/date-input.tsx | 2 +- .../pages/patterns/color/sample/sample.tsx | 7 +- new-docs/pages/patterns/form/form.module.css | 2 +- .../pages/patterns/form/formik.stories.mdx | 104 +++++++-------- new-docs/pages/patterns/form/formik.tsx | 82 ++++++------ .../patterns/form/react-hook-form.stories.mdx | 122 +++++++++--------- .../pages/patterns/form/react-hook-form.tsx | 100 +++++++------- new-docs/pages/patterns/icon.stories.mdx | 58 ++++----- new-docs/sidebar.ts | 2 +- 9 files changed, 240 insertions(+), 239 deletions(-) diff --git a/core/src/date-input/date-input.tsx b/core/src/date-input/date-input.tsx index 18fe7c79..b2033911 100644 --- a/core/src/date-input/date-input.tsx +++ b/core/src/date-input/date-input.tsx @@ -2,7 +2,7 @@ import { ReactElement } from "react"; // TODO: Rewrite date input using the new DayPicker component from react-day-picker export const DateInput = (): ReactElement => { - return + return ; }; // import { ReactNode, useState } from "react"; diff --git a/new-docs/pages/patterns/color/sample/sample.tsx b/new-docs/pages/patterns/color/sample/sample.tsx index 35aa67e0..1d322aaa 100644 --- a/new-docs/pages/patterns/color/sample/sample.tsx +++ b/new-docs/pages/patterns/color/sample/sample.tsx @@ -1,7 +1,12 @@ import Color from "color"; import { useEffect, useRef, useState } from "react"; import { HiCheckCircle } from "react-icons/hi"; -import { CategoryColor, categoryColors, Icon, Tag } from "../../../../../core/src"; +import { + CategoryColor, + categoryColors, + Icon, + Tag, +} from "../../../../../core/src"; import s from "./sample.module.css"; export type ColorSampleUsage = "text" | "icon" | "both"; diff --git a/new-docs/pages/patterns/form/form.module.css b/new-docs/pages/patterns/form/form.module.css index c3beab8b..ac96462b 100644 --- a/new-docs/pages/patterns/form/form.module.css +++ b/new-docs/pages/patterns/form/form.module.css @@ -1,5 +1,5 @@ .form { display: "flex"; flex-direction: "column"; - gap: 16, + gap: 16; } diff --git a/new-docs/pages/patterns/form/formik.stories.mdx b/new-docs/pages/patterns/form/formik.stories.mdx index 6eac3ebf..11a41ddc 100644 --- a/new-docs/pages/patterns/form/formik.stories.mdx +++ b/new-docs/pages/patterns/form/formik.stories.mdx @@ -1,4 +1,4 @@ -import { FormikExample } from './formik' +import { FormikExample } from "./formik"; # Formik @@ -7,23 +7,23 @@ Formik's [Field][1] component: [1]: https://formik.org/docs/api/field -~~~tsx +```tsx import { Field } from "formik"; import { Input } from "../../../core/src"; -~~~ +``` To show errors, pass FormError to the "component" prop of Formik's [ErrorMessage][2] component: -~~~tsx +```tsx import { ErrorMessage } from "formik"; import { FormError } from "../../../core/src"; - -~~~ +; +``` [2]: https://formik.org/docs/api/errormessage @@ -31,51 +31,51 @@ Full example: -~~~tsx +```tsx (): JSX.Element => { - /* import { Input, Button, FormError } from "../../../core/src" */ - - const title = ( -
- - - -
- ); - - const message = ( -
- - - -
- ); - - const validate = (values: FormValues): FormikErrors => { - const errors: FormikErrors = {}; - if (!values.title) errors.title = ERRORS.titleRequired; - if (!values.message) errors.message = ERRORS.messageRequired; - if (values.message.length < 5) errors.message = ERRORS.messageLength; - return errors; - }; - - return ( - - initialValues={{ title: "", message: "" }} - validate={validate} - onSubmit={async (values, { setSubmitting }) => { - await postToServer(values); - setSubmitting(false); - }} - > - {({ isSubmitting: busy }) => ( -
- {title} - {message} - - - )} - - ); + /* import { Input, Button, FormError } from "../../../core/src" */ + + const title = ( +
+ + + +
+ ); + + const message = ( +
+ + + +
+ ); + + const validate = (values: FormValues): FormikErrors => { + const errors: FormikErrors = {}; + if (!values.title) errors.title = ERRORS.titleRequired; + if (!values.message) errors.message = ERRORS.messageRequired; + if (values.message.length < 5) errors.message = ERRORS.messageLength; + return errors; + }; + + return ( + + initialValues={{ title: "", message: "" }} + validate={validate} + onSubmit={async (values, { setSubmitting }) => { + await postToServer(values); + setSubmitting(false); + }} + > + {({ isSubmitting: busy }) => ( +
+ {title} + {message} + + + )} + + ); }; -~~~ +``` diff --git a/new-docs/pages/patterns/form/formik.tsx b/new-docs/pages/patterns/form/formik.tsx index 62518389..fd3d244d 100644 --- a/new-docs/pages/patterns/form/formik.tsx +++ b/new-docs/pages/patterns/form/formik.tsx @@ -1,51 +1,51 @@ import { ErrorMessage, Field, Form, Formik, FormikErrors } from "formik"; import { FormError, Input, TextArea } from "../../../../core/src"; import { ERRORS, FormValues, SubmitButton, postToServer } from "./utils"; -import s from './form.module.css'; +import s from "./form.module.css"; export const FormikExample = (): JSX.Element => { - /* import { Input, Button, FormError } from "../../../core/src" */ + /* import { Input, Button, FormError } from "../../../core/src" */ - const title = ( -
- - - -
- ); + const title = ( +
+ + + +
+ ); - const message = ( -
- - - -
- ); + const message = ( +
+ + + +
+ ); - const validate = (values: FormValues): FormikErrors => { - const errors: FormikErrors = {}; - if (!values.title) errors.title = ERRORS.titleRequired; - if (!values.message) errors.message = ERRORS.messageRequired; - if (values.message.length < 5) errors.message = ERRORS.messageLength; - return errors; - }; + const validate = (values: FormValues): FormikErrors => { + const errors: FormikErrors = {}; + if (!values.title) errors.title = ERRORS.titleRequired; + if (!values.message) errors.message = ERRORS.messageRequired; + if (values.message.length < 5) errors.message = ERRORS.messageLength; + return errors; + }; - return ( - - initialValues={{ title: "", message: "" }} - validate={validate} - onSubmit={async (values, { setSubmitting }) => { - await postToServer(values); - setSubmitting(false); - }} - > - {({ isSubmitting: busy }) => ( -
- {title} - {message} - - - )} - - ); + return ( + + initialValues={{ title: "", message: "" }} + validate={validate} + onSubmit={async (values, { setSubmitting }) => { + await postToServer(values); + setSubmitting(false); + }} + > + {({ isSubmitting: busy }) => ( +
+ {title} + {message} + + + )} + + ); }; diff --git a/new-docs/pages/patterns/form/react-hook-form.stories.mdx b/new-docs/pages/patterns/form/react-hook-form.stories.mdx index 45931b53..21d297a1 100644 --- a/new-docs/pages/patterns/form/react-hook-form.stories.mdx +++ b/new-docs/pages/patterns/form/react-hook-form.stories.mdx @@ -1,11 +1,11 @@ -import { ReactHookFormExample } from './react-hook-form' +import { ReactHookFormExample } from "./react-hook-form"; # React Hook Form To use Moai's input components with React Hook Form, [render][2] them in the "render" prop of RHF's [Controller][1] component: -~~~tsx +```tsx import { Controller } from "react-hook-form"; import { Input } from "../../../core/src"; @@ -18,7 +18,7 @@ import { Input } from "../../../core/src"; )} rules={{ required: "Email is required" }} /> -~~~ +``` [1]: https://react-hook-form.com/api#Controller [2]: https://react-hook-form.com/get-started#IntegratingwithUIlibraries @@ -26,11 +26,11 @@ import { Input } from "../../../core/src"; To show errors, pass RHF's [error messages][3] as children of Moai's FormError component: -~~~tsx +```tsx import { FormError } from "../../../core/src"; - -~~~ +; +``` [3]: https://react-hook-form.com/advanced-usage#ErrorMessages @@ -38,60 +38,60 @@ Full example: -~~~tsx +```tsx (): JSX.Element => { - /* import { Input, Button, FormError } from "../../../core/src" */ - - const { control, formState, handleSubmit } = useForm(); - const { errors } = formState; - const [busy, setBusy] = useState(false); - - const title = ( -
- - ( - - )} - rules={{ required: ERRORS.titleRequired }} - defaultValue="" - /> - -
- ); - - const message = ( -
- -