Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
NgocNhi123 committed Jun 26, 2024
1 parent 346c705 commit f9e572c
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 239 deletions.
2 changes: 1 addition & 1 deletion core/src/date-input/date-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <input type="date"/>
return <input type="date" />;
};

// import { ReactNode, useState } from "react";
Expand Down
7 changes: 6 additions & 1 deletion new-docs/pages/patterns/color/sample/sample.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion new-docs/pages/patterns/form/form.module.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.form {
display: "flex";
flex-direction: "column";
gap: 16,
gap: 16;
}
104 changes: 52 additions & 52 deletions new-docs/pages/patterns/form/formik.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FormikExample } from './formik'
import { FormikExample } from "./formik";

# Formik

Expand All @@ -7,75 +7,75 @@ Formik's [Field][1] component:

[1]: https://formik.org/docs/api/field

~~~tsx
```tsx
import { Field } from "formik";
import { Input } from "../../../core/src";

<label htmlFor="email">Email</label>
<Field id="email" type="email" name="email" as={Input} />
~~~
```

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";

<ErrorMessage name="email" component={FormError} />
~~~
<ErrorMessage name="email" component={FormError} />;
```

[2]: https://formik.org/docs/api/errormessage

Full example:

<FormikExample />

~~~tsx
```tsx
(): JSX.Element => {
/* import { Input, Button, FormError } from "../../../core/src" */

const title = (
<div>
<label htmlFor="fm-title">Title</label>
<Field id="fm-title" type="text" name="title" as={Input} />
<ErrorMessage name="title" component={FormError} />
</div>
);

const message = (
<div>
<label htmlFor="fm-message">Message</label>
<Field id="fm-message" name="message" as={TextArea} />
<ErrorMessage name="message" component={FormError} />
</div>
);

const validate = (values: FormValues): FormikErrors<FormValues> => {
const errors: FormikErrors<FormValues> = {};
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 (
<Formik<FormValues>
initialValues={{ title: "", message: "" }}
validate={validate}
onSubmit={async (values, { setSubmitting }) => {
await postToServer(values);
setSubmitting(false);
}}
>
{({ isSubmitting: busy }) => (
<Form className={s.form}>
{title}
{message}
<SubmitButton busy={busy} />
</Form>
)}
</Formik>
);
/* import { Input, Button, FormError } from "../../../core/src" */

const title = (
<div>
<label htmlFor="fm-title">Title</label>
<Field id="fm-title" type="text" name="title" as={Input} />
<ErrorMessage name="title" component={FormError} />
</div>
);

const message = (
<div>
<label htmlFor="fm-message">Message</label>
<Field id="fm-message" name="message" as={TextArea} />
<ErrorMessage name="message" component={FormError} />
</div>
);

const validate = (values: FormValues): FormikErrors<FormValues> => {
const errors: FormikErrors<FormValues> = {};
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 (
<Formik<FormValues>
initialValues={{ title: "", message: "" }}
validate={validate}
onSubmit={async (values, { setSubmitting }) => {
await postToServer(values);
setSubmitting(false);
}}
>
{({ isSubmitting: busy }) => (
<Form className={s.form}>
{title}
{message}
<SubmitButton busy={busy} />
</Form>
)}
</Formik>
);
};
~~~
```
82 changes: 41 additions & 41 deletions new-docs/pages/patterns/form/formik.tsx
Original file line number Diff line number Diff line change
@@ -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 = (
<div>
<label htmlFor="fm-title">Title</label>
<Field id="fm-title" type="text" name="title" as={Input} />
<ErrorMessage name="title" component={FormError} />
</div>
);
const title = (
<div>
<label htmlFor="fm-title">Title</label>
<Field id="fm-title" type="text" name="title" as={Input} />
<ErrorMessage name="title" component={FormError} />
</div>
);

const message = (
<div>
<label htmlFor="fm-message">Message</label>
<Field id="fm-message" name="message" as={TextArea} />
<ErrorMessage name="message" component={FormError} />
</div>
);
const message = (
<div>
<label htmlFor="fm-message">Message</label>
<Field id="fm-message" name="message" as={TextArea} />
<ErrorMessage name="message" component={FormError} />
</div>
);

const validate = (values: FormValues): FormikErrors<FormValues> => {
const errors: FormikErrors<FormValues> = {};
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<FormValues> => {
const errors: FormikErrors<FormValues> = {};
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 (
<Formik<FormValues>
initialValues={{ title: "", message: "" }}
validate={validate}
onSubmit={async (values, { setSubmitting }) => {
await postToServer(values);
setSubmitting(false);
}}
>
{({ isSubmitting: busy }) => (
<Form className={s.form}>
{title}
{message}
<SubmitButton busy={busy} />
</Form>
)}
</Formik>
);
return (
<Formik<FormValues>
initialValues={{ title: "", message: "" }}
validate={validate}
onSubmit={async (values, { setSubmitting }) => {
await postToServer(values);
setSubmitting(false);
}}
>
{({ isSubmitting: busy }) => (
<Form className={s.form}>
{title}
{message}
<SubmitButton busy={busy} />
</Form>
)}
</Formik>
);
};
Loading

0 comments on commit f9e572c

Please sign in to comment.