@hyphen/hyphen-components 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +70 -0
- package/package.json +138 -0
- package/src/components/Alert/Alert.constants.ts +19 -0
- package/src/components/Alert/Alert.mdx +29 -0
- package/src/components/Alert/Alert.module.scss +74 -0
- package/src/components/Alert/Alert.stories.tsx +102 -0
- package/src/components/Alert/Alert.test.tsx +187 -0
- package/src/components/Alert/Alert.tsx +157 -0
- package/src/components/Alert/Alert.types.ts +14 -0
- package/src/components/Badge/Badge.mdx +28 -0
- package/src/components/Badge/Badge.module.scss +155 -0
- package/src/components/Badge/Badge.stories.tsx +52 -0
- package/src/components/Badge/Badge.test.tsx +74 -0
- package/src/components/Badge/Badge.tsx +70 -0
- package/src/components/Box/Box.mdx +259 -0
- package/src/components/Box/Box.module.scss +16 -0
- package/src/components/Box/Box.stories.tsx +1679 -0
- package/src/components/Box/Box.test.tsx +478 -0
- package/src/components/Box/Box.tsx +636 -0
- package/src/components/Button/Button.constants.ts +10 -0
- package/src/components/Button/Button.mdx +71 -0
- package/src/components/Button/Button.module.scss +312 -0
- package/src/components/Button/Button.stories.tsx +117 -0
- package/src/components/Button/Button.test.tsx +460 -0
- package/src/components/Button/Button.tsx +241 -0
- package/src/components/Card/Card.mdx +46 -0
- package/src/components/Card/Card.module.scss +6 -0
- package/src/components/Card/Card.stories.tsx +101 -0
- package/src/components/Card/Card.test.tsx +11 -0
- package/src/components/Card/Card.tsx +61 -0
- package/src/components/Card/components/CardFooter/CardFooter.test.tsx +11 -0
- package/src/components/Card/components/CardFooter/CardFooter.tsx +35 -0
- package/src/components/Card/components/CardHeader/CardHeader.test.tsx +23 -0
- package/src/components/Card/components/CardHeader/CardHeader.tsx +54 -0
- package/src/components/Card/components/CardSection/CardSection.test.tsx +28 -0
- package/src/components/Card/components/CardSection/CardSection.tsx +102 -0
- package/src/components/Card/components/index.ts +3 -0
- package/src/components/CheckboxInput/CheckboxInput.mdx +98 -0
- package/src/components/CheckboxInput/CheckboxInput.stories.tsx +254 -0
- package/src/components/CheckboxInput/CheckboxInput.test.tsx +436 -0
- package/src/components/CheckboxInput/CheckboxInput.tsx +171 -0
- package/src/components/CheckboxInput/components/Checkbox.module.scss +174 -0
- package/src/components/CheckboxInput/components/Checkbox.test.tsx +201 -0
- package/src/components/CheckboxInput/components/Checkbox.tsx +176 -0
- package/src/components/CheckboxInput/components/CheckboxIcon.tsx +71 -0
- package/src/components/DateInput/DateInput.mdx +61 -0
- package/src/components/DateInput/DateInput.stories.tsx +168 -0
- package/src/components/DateInput/DateInput.test.tsx +258 -0
- package/src/components/DateInput/DateInput.tsx +189 -0
- package/src/components/DatePicker/DatePicker.mdx +52 -0
- package/src/components/DatePicker/DatePicker.module.scss +603 -0
- package/src/components/DatePicker/DatePicker.stories.tsx +199 -0
- package/src/components/DatePicker/DatePicker.test.tsx +26 -0
- package/src/components/DatePicker/DatePicker.tsx +138 -0
- package/src/components/Details/Details.mdx +30 -0
- package/src/components/Details/Details.module.scss +32 -0
- package/src/components/Details/Details.stories.tsx +38 -0
- package/src/components/Details/Details.test.tsx +189 -0
- package/src/components/Details/Details.tsx +51 -0
- package/src/components/Details/DetailsSummary.tsx +65 -0
- package/src/components/Drawer/Drawer.mdx +117 -0
- package/src/components/Drawer/Drawer.module.scss +96 -0
- package/src/components/Drawer/Drawer.stories.tsx +380 -0
- package/src/components/Drawer/Drawer.test.tsx +90 -0
- package/src/components/Drawer/Drawer.tsx +249 -0
- package/src/components/FormControl/FormControl.tsx +78 -0
- package/src/components/FormLabel/FormLabel.mdx +24 -0
- package/src/components/FormLabel/FormLabel.module.scss +19 -0
- package/src/components/FormLabel/FormLabel.stories.tsx +20 -0
- package/src/components/FormLabel/FormLabel.test.tsx +35 -0
- package/src/components/FormLabel/FormLabel.tsx +96 -0
- package/src/components/Formik/Formik.mdx +10 -0
- package/src/components/Formik/Formik.stories.tsx +307 -0
- package/src/components/Formik/FormikCheckboxInput/FormikCheckboxInput.test.tsx +172 -0
- package/src/components/Formik/FormikCheckboxInput/FormikCheckboxInput.tsx +41 -0
- package/src/components/Formik/FormikRadioGroup/FormikRadioGroup.test.tsx +205 -0
- package/src/components/Formik/FormikRadioGroup/FormikRadioGroup.tsx +37 -0
- package/src/components/Formik/FormikSelectInput/FormikSelectInput.test.tsx +210 -0
- package/src/components/Formik/FormikSelectInput/FormikSelectInput.tsx +41 -0
- package/src/components/Formik/FormikSelectInputInset/FormikSelectInputInset.test.tsx +153 -0
- package/src/components/Formik/FormikSelectInputInset/FormikSelectInputInset.tsx +44 -0
- package/src/components/Formik/FormikSelectInputNative/FormikSelectInputNative.test.tsx +161 -0
- package/src/components/Formik/FormikSelectInputNative/FormikSelectInputNative.tsx +46 -0
- package/src/components/Formik/FormikTextInput/FormikTextInput.test.tsx +176 -0
- package/src/components/Formik/FormikTextInput/FormikTextInput.tsx +38 -0
- package/src/components/Formik/FormikTextInputInset/FormikTextInputInset.test.tsx +170 -0
- package/src/components/Formik/FormikTextInputInset/FormikTextInputInset.tsx +42 -0
- package/src/components/Formik/FormikTextareaInput/FormikTextareaInput.test.tsx +186 -0
- package/src/components/Formik/FormikTextareaInput/FormikTextareaInput.tsx +42 -0
- package/src/components/Formik/FormikTextareaInputInset/FormikTextareaInputInset.test.tsx +179 -0
- package/src/components/Formik/FormikTextareaInputInset/FormikTextareaInputInset.tsx +42 -0
- package/src/components/Formik/FormikTimePicker/FormikTimePicker.test.tsx +224 -0
- package/src/components/Formik/FormikTimePicker/FormikTimePicker.tsx +37 -0
- package/src/components/Formik/FormikTimePickerNative/FormikTimePickerNative.test.tsx +175 -0
- package/src/components/Formik/FormikTimePickerNative/FormikTimePickerNative.tsx +38 -0
- package/src/components/Formik/FormikToggle/FormikToggle.test.tsx +172 -0
- package/src/components/Formik/FormikToggle/FormikToggle.tsx +38 -0
- package/src/components/Heading/Heading.constants.ts +19 -0
- package/src/components/Heading/Heading.mdx +35 -0
- package/src/components/Heading/Heading.module.scss +5 -0
- package/src/components/Heading/Heading.stories.tsx +90 -0
- package/src/components/Heading/Heading.test.tsx +67 -0
- package/src/components/Heading/Heading.tsx +67 -0
- package/src/components/HelpText/HelpText.module.scss +14 -0
- package/src/components/HelpText/HelpText.tsx +33 -0
- package/src/components/Icon/Icon.mdx +40 -0
- package/src/components/Icon/Icon.stories.tsx +72 -0
- package/src/components/Icon/Icon.test.tsx +30 -0
- package/src/components/Icon/Icon.tsx +61 -0
- package/src/components/InputValidationMessage/InputValidationMessage.module.scss +3 -0
- package/src/components/InputValidationMessage/InputValidationMessage.tsx +27 -0
- package/src/components/Modal/Modal.mdx +60 -0
- package/src/components/Modal/Modal.module.scss +135 -0
- package/src/components/Modal/Modal.stories.tsx +194 -0
- package/src/components/Modal/Modal.test.tsx +81 -0
- package/src/components/Modal/Modal.tsx +174 -0
- package/src/components/Modal/components/ModalBody/ModalBody.test.tsx +20 -0
- package/src/components/Modal/components/ModalBody/ModalBody.tsx +24 -0
- package/src/components/Modal/components/ModalFooter/ModalFooter.test.tsx +32 -0
- package/src/components/Modal/components/ModalFooter/ModalFooter.tsx +37 -0
- package/src/components/Modal/components/ModalHeader/ModalHeader.test.tsx +29 -0
- package/src/components/Modal/components/ModalHeader/ModalHeader.tsx +58 -0
- package/src/components/Modal/components/index.ts +5 -0
- package/src/components/Pagination/Pagination.mdx +26 -0
- package/src/components/Pagination/Pagination.stories.tsx +55 -0
- package/src/components/Pagination/Pagination.test.tsx +225 -0
- package/src/components/Pagination/Pagination.tsx +162 -0
- package/src/components/Pagination/Pagination.utilities.test.ts +133 -0
- package/src/components/Pagination/Pagination.utilities.ts +101 -0
- package/src/components/Popover/Popover.mdx +104 -0
- package/src/components/Popover/Popover.module.scss +74 -0
- package/src/components/Popover/Popover.stories.tsx +471 -0
- package/src/components/Popover/Popover.test.tsx +128 -0
- package/src/components/Popover/Popover.tsx +277 -0
- package/src/components/RadioGroup/RadioGroup.mdx +81 -0
- package/src/components/RadioGroup/RadioGroup.module.scss +23 -0
- package/src/components/RadioGroup/RadioGroup.stories.tsx +375 -0
- package/src/components/RadioGroup/RadioGroup.test.tsx +282 -0
- package/src/components/RadioGroup/RadioGroup.tsx +145 -0
- package/src/components/RadioGroup/RadioInput/RadioInput.module.scss +114 -0
- package/src/components/RadioGroup/RadioInput/RadioInput.test.tsx +156 -0
- package/src/components/RadioGroup/RadioInput/RadioInput.tsx +148 -0
- package/src/components/RadioGroup/RadioInput/RadioInputIcon.tsx +59 -0
- package/src/components/ResponsiveProvider/ResponsiveProvider.mdx +36 -0
- package/src/components/ResponsiveProvider/ResponsiveProvider.stories.tsx +54 -0
- package/src/components/ResponsiveProvider/ResponsiveProvider.test.tsx +70 -0
- package/src/components/ResponsiveProvider/ResponsiveProvider.tsx +73 -0
- package/src/components/SelectInput/SelectInput.mdx +115 -0
- package/src/components/SelectInput/SelectInput.module.scss +357 -0
- package/src/components/SelectInput/SelectInput.stories.tsx +373 -0
- package/src/components/SelectInput/SelectInput.test.tsx +403 -0
- package/src/components/SelectInput/SelectInput.tsx +245 -0
- package/src/components/SelectInputInset/SelectInputInset.mdx +56 -0
- package/src/components/SelectInputInset/SelectInputInset.module.scss +397 -0
- package/src/components/SelectInputInset/SelectInputInset.stories.tsx +189 -0
- package/src/components/SelectInputInset/SelectInputInset.test.tsx +305 -0
- package/src/components/SelectInputInset/SelectInputInset.tsx +235 -0
- package/src/components/SelectInputNative/SelectInputNative.mdx +87 -0
- package/src/components/SelectInputNative/SelectInputNative.module.scss +356 -0
- package/src/components/SelectInputNative/SelectInputNative.stories.tsx +282 -0
- package/src/components/SelectInputNative/SelectInputNative.test.tsx +341 -0
- package/src/components/SelectInputNative/SelectInputNative.tsx +121 -0
- package/src/components/Spinner/Spinner.mdx +29 -0
- package/src/components/Spinner/Spinner.module.scss +16 -0
- package/src/components/Spinner/Spinner.stories.tsx +48 -0
- package/src/components/Spinner/Spinner.test.tsx +47 -0
- package/src/components/Spinner/Spinner.tsx +116 -0
- package/src/components/Table/Table.mdx +216 -0
- package/src/components/Table/Table.module.scss +61 -0
- package/src/components/Table/Table.stories.tsx +884 -0
- package/src/components/Table/Table.test.tsx +437 -0
- package/src/components/Table/Table.tsx +171 -0
- package/src/components/Table/TableBody/TableBody.module.scss +19 -0
- package/src/components/Table/TableBody/TableBody.test.tsx +38 -0
- package/src/components/Table/TableBody/TableBody.tsx +96 -0
- package/src/components/Table/TableBody/TableBodyCell/TableBodyCell.module.scss +47 -0
- package/src/components/Table/TableBody/TableBodyCell/TableBodyCell.test.tsx +81 -0
- package/src/components/Table/TableBody/TableBodyCell/TableBodyCell.tsx +94 -0
- package/src/components/Table/TableHead/TableHead.test.tsx +20 -0
- package/src/components/Table/TableHead/TableHead.tsx +78 -0
- package/src/components/Table/TableHead/TableHeaderCell/TableHeaderCell.module.scss +72 -0
- package/src/components/Table/TableHead/TableHeaderCell/TableHeaderCell.test.tsx +187 -0
- package/src/components/Table/TableHead/TableHeaderCell/TableHeaderCell.tsx +192 -0
- package/src/components/Table/common/TableRow/TableRow.module.scss +5 -0
- package/src/components/Table/common/TableRow/TableRow.test.tsx +52 -0
- package/src/components/Table/common/TableRow/TableRow.tsx +155 -0
- package/src/components/TextInput/TextInput.mdx +96 -0
- package/src/components/TextInput/TextInput.module.scss +405 -0
- package/src/components/TextInput/TextInput.stories.tsx +268 -0
- package/src/components/TextInput/TextInput.test.tsx +231 -0
- package/src/components/TextInput/TextInput.tsx +263 -0
- package/src/components/TextInputInset/TextInputInset.mdx +62 -0
- package/src/components/TextInputInset/TextInputInset.module.scss +418 -0
- package/src/components/TextInputInset/TextInputInset.stories.tsx +213 -0
- package/src/components/TextInputInset/TextInputInset.test.tsx +222 -0
- package/src/components/TextInputInset/TextInputInset.tsx +261 -0
- package/src/components/TextareaInput/TextareaInput.mdx +117 -0
- package/src/components/TextareaInput/TextareaInput.module.scss +275 -0
- package/src/components/TextareaInput/TextareaInput.stories.tsx +293 -0
- package/src/components/TextareaInput/TextareaInput.test.tsx +195 -0
- package/src/components/TextareaInput/TextareaInput.tsx +182 -0
- package/src/components/TextareaInputInset/TextareaInputInset.mdx +55 -0
- package/src/components/TextareaInputInset/TextareaInputInset.module.scss +337 -0
- package/src/components/TextareaInputInset/TextareaInputInset.stories.tsx +160 -0
- package/src/components/TextareaInputInset/TextareaInputInset.test.tsx +199 -0
- package/src/components/TextareaInputInset/TextareaInputInset.tsx +213 -0
- package/src/components/ThemeProvider/ThemeProvider.mdx +11 -0
- package/src/components/ThemeProvider/ThemeProvider.stories.tsx +56 -0
- package/src/components/ThemeProvider/ThemeProvider.tsx +75 -0
- package/src/components/TimePicker/TimePicker.mdx +75 -0
- package/src/components/TimePicker/TimePicker.stories.tsx +149 -0
- package/src/components/TimePicker/TimePicker.test.tsx +97 -0
- package/src/components/TimePicker/TimePicker.tsx +83 -0
- package/src/components/TimePickerNative/TimePickerNative.mdx +67 -0
- package/src/components/TimePickerNative/TimePickerNative.stories.tsx +151 -0
- package/src/components/TimePickerNative/TimePickerNative.test.tsx +117 -0
- package/src/components/TimePickerNative/TimePickerNative.tsx +93 -0
- package/src/components/Toast/Toast.mdx +134 -0
- package/src/components/Toast/Toast.store.ts +280 -0
- package/src/components/Toast/Toast.stories.tsx +283 -0
- package/src/components/Toast/Toast.test.tsx +784 -0
- package/src/components/Toast/Toast.types.ts +98 -0
- package/src/components/Toast/ToastContainer.tsx +170 -0
- package/src/components/Toast/ToastNotification.module.scss +63 -0
- package/src/components/Toast/ToastNotification.tsx +176 -0
- package/src/components/Toast/index.ts +4 -0
- package/src/components/Toast/toast.ts +102 -0
- package/src/components/Toast/useToasts.ts +102 -0
- package/src/components/Toggle/Toggle.mdx +51 -0
- package/src/components/Toggle/Toggle.module.scss +294 -0
- package/src/components/Toggle/Toggle.stories.tsx +128 -0
- package/src/components/Toggle/Toggle.test.tsx +308 -0
- package/src/components/Toggle/Toggle.tsx +184 -0
- package/src/constants/keyCodes.ts +2 -0
- package/src/docs/Brands.mdx +153 -0
- package/src/docs/Colors.mdx +158 -0
- package/src/docs/DesignTokens.mdx +415 -0
- package/src/docs/GetStarted.mdx +47 -0
- package/src/docs/intro.mdx +12 -0
- package/src/fonts/AvenirBold.otf +0 -0
- package/src/fonts/AvenirBold.woff +0 -0
- package/src/fonts/AvenirBold.woff2 +0 -0
- package/src/fonts/AvenirLight.otf +0 -0
- package/src/fonts/AvenirLight.woff +0 -0
- package/src/fonts/AvenirLight.woff2 +0 -0
- package/src/fonts/AvenirRegular.otf +0 -0
- package/src/fonts/AvenirRegular.woff +0 -0
- package/src/fonts/AvenirRegular.woff2 +0 -0
- package/src/fonts/Geist-Bold.otf +0 -0
- package/src/fonts/Geist-Bold.woff +0 -0
- package/src/fonts/Geist-Bold.woff2 +0 -0
- package/src/fonts/Geist-Medium.otf +0 -0
- package/src/fonts/Geist-Medium.woff +0 -0
- package/src/fonts/Geist-Medium.woff2 +0 -0
- package/src/fonts/Geist-Regular.otf +0 -0
- package/src/fonts/Geist-Regular.woff +0 -0
- package/src/fonts/Geist-Regular.woff2 +0 -0
- package/src/fonts/Geist-SemiBold.otf +0 -0
- package/src/fonts/Geist-SemiBold.woff +0 -0
- package/src/fonts/Geist-SemiBold.woff2 +0 -0
- package/src/fonts/GeistMono-Regular.otf +0 -0
- package/src/fonts/GeistMono-Regular.woff +0 -0
- package/src/fonts/GeistMono-Regular.woff2 +0 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useBreakpoint/useBreakpoint.mdx +26 -0
- package/src/hooks/useBreakpoint/useBreakpoint.stories.tsx +30 -0
- package/src/hooks/useBreakpoint/useBreakpoint.test.tsx +19 -0
- package/src/hooks/useBreakpoint/useBreakpoint.ts +50 -0
- package/src/hooks/useIsomorphicLayoutEffect/useIsomorphicLayouEffect.ts +5 -0
- package/src/hooks/useOpenClose/useOpenClose.mdx +15 -0
- package/src/hooks/useOpenClose/useOpenClose.stories.tsx +41 -0
- package/src/hooks/useOpenClose/useOpenClose.test.tsx +119 -0
- package/src/hooks/useOpenClose/useOpenClose.tsx +95 -0
- package/src/hooks/useWindowSize/useWindowSize.mdx +25 -0
- package/src/hooks/useWindowSize/useWindowSize.stories.tsx +35 -0
- package/src/hooks/useWindowSize/useWindowSize.ts +24 -0
- package/src/index.ts +48 -0
- package/src/lib/cssShorthandToClasses.test.ts +149 -0
- package/src/lib/cssShorthandToClasses.ts +133 -0
- package/src/lib/doesStringIncludeCssUnit.ts +6 -0
- package/src/lib/generateResponsiveClasses.test.ts +24 -0
- package/src/lib/generateResponsiveClasses.ts +30 -0
- package/src/lib/getAutoCompleteValue.test.ts +27 -0
- package/src/lib/getAutoCompleteValue.ts +12 -0
- package/src/lib/getColumnKeys.ts +27 -0
- package/src/lib/getDimensionCss.test.ts +148 -0
- package/src/lib/getDimensionCss.ts +73 -0
- package/src/lib/getElementType.test.tsx +42 -0
- package/src/lib/getElementType.ts +42 -0
- package/src/lib/getFlexCss.test.ts +122 -0
- package/src/lib/getFlexCss.ts +67 -0
- package/src/lib/index.ts +15 -0
- package/src/lib/isFunction.ts +6 -0
- package/src/lib/mergeRefs.ts +15 -0
- package/src/lib/prefersReducedMotion.ts +12 -0
- package/src/lib/react-children-utilities/filter.ts +12 -0
- package/src/lib/react-children-utilities/index.ts +1 -0
- package/src/lib/reactRouterClickHandler.ts +37 -0
- package/src/lib/resolveValue.ts +7 -0
- package/src/lib/tokens.ts +139 -0
- package/src/modes.ts +8 -0
- package/src/styles/animation.scss +152 -0
- package/src/styles/cursor.scss +43 -0
- package/src/styles/display.scss +119 -0
- package/src/styles/flex.scss +453 -0
- package/src/styles/fonts.scss +44 -0
- package/src/styles/globals/utilities.scss +4 -0
- package/src/styles/mixins.scss +14 -0
- package/src/styles/overflow.scss +41 -0
- package/src/styles/position.scss +45 -0
- package/src/styles/reset.scss +108 -0
- package/src/styles/text-align.scss +21 -0
- package/src/styles/utilities.scss +9 -0
- package/src/styles/variables/forms.scss +71 -0
- package/src/styles/variables/index.scss +3 -0
- package/src/styles/white-space.scss +21 -0
- package/src/types/index.ts +201 -0
- package/src/types/lib.types.ts +3 -0
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import React, { ChangeEvent } from 'react';
|
|
2
|
+
import { Field, Form, Formik } from 'formik';
|
|
3
|
+
import { FormikTextInput } from './FormikTextInput/FormikTextInput';
|
|
4
|
+
import { FormikCheckboxInput } from './FormikCheckboxInput/FormikCheckboxInput';
|
|
5
|
+
import { FormikSelectInput } from './FormikSelectInput/FormikSelectInput';
|
|
6
|
+
import { FormikSelectInputNative } from './FormikSelectInputNative/FormikSelectInputNative';
|
|
7
|
+
import { FormikRadioGroup } from './FormikRadioGroup/FormikRadioGroup';
|
|
8
|
+
import { FormikTextareaInput } from './FormikTextareaInput/FormikTextareaInput';
|
|
9
|
+
import { DateInput } from '../DateInput/DateInput';
|
|
10
|
+
import { FormikToggle } from './FormikToggle/FormikToggle';
|
|
11
|
+
import { Button } from '../Button/Button';
|
|
12
|
+
import { Box } from '../Box/Box';
|
|
13
|
+
import { FormikTimePickerNative } from './FormikTimePickerNative/FormikTimePickerNative';
|
|
14
|
+
import { FormikSelectInputInset } from './FormikSelectInputInset/FormikSelectInputInset';
|
|
15
|
+
import { FormikTextareaInputInset } from './FormikTextareaInputInset/FormikTextareaInputInset';
|
|
16
|
+
import { FormikTextInputInset } from './FormikTextInputInset/FormikTextInputInset';
|
|
17
|
+
import { allModes } from '../../modes';
|
|
18
|
+
|
|
19
|
+
const meta = {
|
|
20
|
+
title: 'Patterns/Formik Form',
|
|
21
|
+
parameters: {
|
|
22
|
+
chromatic: {
|
|
23
|
+
modes: {
|
|
24
|
+
light: allModes['light'],
|
|
25
|
+
dark: allModes['dark'],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default meta;
|
|
32
|
+
|
|
33
|
+
export const FormikForm = () =>
|
|
34
|
+
(() => {
|
|
35
|
+
const flavorOptions = [
|
|
36
|
+
{ value: 'chocolate', label: 'Chocolate' },
|
|
37
|
+
{ value: 'strawberry', label: 'Strawberry' },
|
|
38
|
+
{ value: 'vanilla', label: 'Vanilla' },
|
|
39
|
+
];
|
|
40
|
+
const colorOptions = [
|
|
41
|
+
{ value: 'red', label: 'red' },
|
|
42
|
+
{ value: 'orange', label: 'orange' },
|
|
43
|
+
{ value: 'yellow', label: 'yellow' },
|
|
44
|
+
{ value: 'green', label: 'green' },
|
|
45
|
+
{ value: 'blue', label: 'blue' },
|
|
46
|
+
{ value: 'indigo', label: 'indigo' },
|
|
47
|
+
{ value: 'violet', label: 'violet' },
|
|
48
|
+
];
|
|
49
|
+
const sizeOptions = [
|
|
50
|
+
{ id: 'small', value: 'small', label: 'Small' },
|
|
51
|
+
{ id: 'medium', value: 'medium', label: 'Medium' },
|
|
52
|
+
{ id: 'large', value: 'large', label: 'Large' },
|
|
53
|
+
];
|
|
54
|
+
const handleValidation = (values: Record<string, any>) => {
|
|
55
|
+
const errors: Record<string, string> = {};
|
|
56
|
+
if (!values.firstName) {
|
|
57
|
+
errors.firstName = 'required';
|
|
58
|
+
}
|
|
59
|
+
if (!values.lastName) {
|
|
60
|
+
errors.lastName = 'required';
|
|
61
|
+
}
|
|
62
|
+
if (!values.areTermsChecked) {
|
|
63
|
+
errors.areTermsChecked = 'required';
|
|
64
|
+
}
|
|
65
|
+
if (!values.areTermsChecked2) {
|
|
66
|
+
errors.areTermsChecked2 = 'required';
|
|
67
|
+
}
|
|
68
|
+
if (!values.email) {
|
|
69
|
+
errors.email = 'required';
|
|
70
|
+
} else if (
|
|
71
|
+
!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(values.email)
|
|
72
|
+
) {
|
|
73
|
+
errors.email = 'Invalid email address';
|
|
74
|
+
}
|
|
75
|
+
if (!values.flavor) {
|
|
76
|
+
errors.flavor = 'required';
|
|
77
|
+
}
|
|
78
|
+
if (!values.sizes) {
|
|
79
|
+
errors.sizes = 'required';
|
|
80
|
+
}
|
|
81
|
+
if (!values.timePicker) {
|
|
82
|
+
errors.timePicker = 'required';
|
|
83
|
+
}
|
|
84
|
+
if (!values.dateInput) {
|
|
85
|
+
errors.dateInput = 'required';
|
|
86
|
+
}
|
|
87
|
+
if (!values.colors2) {
|
|
88
|
+
errors.colors2 = 'required';
|
|
89
|
+
}
|
|
90
|
+
if (!values.message) {
|
|
91
|
+
errors.message = 'required';
|
|
92
|
+
}
|
|
93
|
+
if (!values.country) {
|
|
94
|
+
errors.country = 'required';
|
|
95
|
+
}
|
|
96
|
+
return errors;
|
|
97
|
+
};
|
|
98
|
+
const handleSubmit = (
|
|
99
|
+
values: Record<string, any>,
|
|
100
|
+
{ setSubmitting }: any
|
|
101
|
+
) => {
|
|
102
|
+
// Make API calls here
|
|
103
|
+
setTimeout(() => {
|
|
104
|
+
setSubmitting(false);
|
|
105
|
+
alert(
|
|
106
|
+
// eslint-disable-line no-alert
|
|
107
|
+
`Submitted Successfully -> ${JSON.stringify(values, null, 2)}`
|
|
108
|
+
);
|
|
109
|
+
}, 2000);
|
|
110
|
+
};
|
|
111
|
+
const formatOutput = (
|
|
112
|
+
values: Record<string, any>,
|
|
113
|
+
isSubmitting?: boolean
|
|
114
|
+
) => {
|
|
115
|
+
return { ...values, isSubmitting };
|
|
116
|
+
};
|
|
117
|
+
return (
|
|
118
|
+
<Box maxWidth="500px" margin="lg auto" background="primary" padding="2xl">
|
|
119
|
+
<Formik
|
|
120
|
+
initialValues={{
|
|
121
|
+
firstName: '',
|
|
122
|
+
lastName: '',
|
|
123
|
+
email: '',
|
|
124
|
+
phone: '',
|
|
125
|
+
areTermsChecked: false,
|
|
126
|
+
areTermsChecked2: false,
|
|
127
|
+
flavor: null,
|
|
128
|
+
flavor2: null,
|
|
129
|
+
colors: [],
|
|
130
|
+
colors2: '',
|
|
131
|
+
sizes: null,
|
|
132
|
+
timePicker: null,
|
|
133
|
+
timePickerNative: null,
|
|
134
|
+
dateInput: '',
|
|
135
|
+
message: '',
|
|
136
|
+
country: '',
|
|
137
|
+
}}
|
|
138
|
+
validate={handleValidation}
|
|
139
|
+
validateOnChange={false}
|
|
140
|
+
onSubmit={handleSubmit}
|
|
141
|
+
>
|
|
142
|
+
{({ isSubmitting, values, setFieldValue, handleBlur, errors }) => (
|
|
143
|
+
<Form noValidate>
|
|
144
|
+
<Box gap="3xl">
|
|
145
|
+
<Field
|
|
146
|
+
type="text"
|
|
147
|
+
label="First Name"
|
|
148
|
+
name="firstName"
|
|
149
|
+
id="firstName"
|
|
150
|
+
component={FormikTextInput}
|
|
151
|
+
// With a custom onChange.
|
|
152
|
+
// We preserve Formik's convention and relegate state form management back to the user.
|
|
153
|
+
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
154
|
+
setFieldValue('firstName', event.target.value);
|
|
155
|
+
}}
|
|
156
|
+
isRequired
|
|
157
|
+
/>
|
|
158
|
+
<Field
|
|
159
|
+
type="text"
|
|
160
|
+
label="Last Name"
|
|
161
|
+
name="lastName"
|
|
162
|
+
id="lastName"
|
|
163
|
+
component={FormikTextInput}
|
|
164
|
+
isRequired
|
|
165
|
+
/>
|
|
166
|
+
<Field
|
|
167
|
+
label="Country"
|
|
168
|
+
name="country"
|
|
169
|
+
id="country"
|
|
170
|
+
component={FormikTextInputInset}
|
|
171
|
+
isRequired
|
|
172
|
+
/>
|
|
173
|
+
<Field
|
|
174
|
+
label="Email"
|
|
175
|
+
name="email"
|
|
176
|
+
id="email"
|
|
177
|
+
component={FormikTextInput}
|
|
178
|
+
isRequired
|
|
179
|
+
/>
|
|
180
|
+
<Field
|
|
181
|
+
label="Phone"
|
|
182
|
+
name="phone"
|
|
183
|
+
id="phone"
|
|
184
|
+
component={FormikTextInput}
|
|
185
|
+
type="tel"
|
|
186
|
+
/>
|
|
187
|
+
<Field
|
|
188
|
+
label="Flavor with Custom onChange"
|
|
189
|
+
name="flavor"
|
|
190
|
+
id="flavor"
|
|
191
|
+
options={flavorOptions}
|
|
192
|
+
component={FormikSelectInputNative}
|
|
193
|
+
// With a custom onChange.
|
|
194
|
+
// We preserve Formik's convention and relegate form state management back to the user.
|
|
195
|
+
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
196
|
+
setFieldValue('flavor', event.target.value);
|
|
197
|
+
}}
|
|
198
|
+
isRequired
|
|
199
|
+
/>
|
|
200
|
+
<Field
|
|
201
|
+
label="Flavor without custom onChange"
|
|
202
|
+
name="flavor2"
|
|
203
|
+
id="flavor2"
|
|
204
|
+
options={flavorOptions}
|
|
205
|
+
component={FormikSelectInputNative}
|
|
206
|
+
/>
|
|
207
|
+
<Field
|
|
208
|
+
label="Multi-select Colors"
|
|
209
|
+
name="colors"
|
|
210
|
+
id="colors"
|
|
211
|
+
isMulti
|
|
212
|
+
options={colorOptions}
|
|
213
|
+
component={FormikSelectInput}
|
|
214
|
+
/>
|
|
215
|
+
<Field
|
|
216
|
+
label="Describe your perfect meal"
|
|
217
|
+
name="meal"
|
|
218
|
+
id="meal"
|
|
219
|
+
component={FormikTextareaInput}
|
|
220
|
+
/>
|
|
221
|
+
<Field
|
|
222
|
+
title="Sizes"
|
|
223
|
+
name="sizes"
|
|
224
|
+
id="sizes"
|
|
225
|
+
options={sizeOptions}
|
|
226
|
+
component={FormikRadioGroup}
|
|
227
|
+
isRequired
|
|
228
|
+
/>
|
|
229
|
+
<Field
|
|
230
|
+
label="Select Time With Native Select"
|
|
231
|
+
name="timePicker"
|
|
232
|
+
id="timePicker"
|
|
233
|
+
component={FormikTimePickerNative}
|
|
234
|
+
isRequired
|
|
235
|
+
/>
|
|
236
|
+
<Field
|
|
237
|
+
label="Terms and Conditions"
|
|
238
|
+
name="areTermsChecked"
|
|
239
|
+
id="areTermsChecked"
|
|
240
|
+
component={FormikCheckboxInput}
|
|
241
|
+
isRequired
|
|
242
|
+
/>
|
|
243
|
+
<Field
|
|
244
|
+
label="Terms and Conditions Toggle"
|
|
245
|
+
name="areTermsChecked2"
|
|
246
|
+
id="areTermsChecked2"
|
|
247
|
+
component={FormikToggle}
|
|
248
|
+
isRequired
|
|
249
|
+
/>
|
|
250
|
+
<Field
|
|
251
|
+
label="Colors"
|
|
252
|
+
name="colors2"
|
|
253
|
+
id="colors2"
|
|
254
|
+
options={colorOptions}
|
|
255
|
+
component={FormikSelectInputInset}
|
|
256
|
+
isRequired
|
|
257
|
+
/>
|
|
258
|
+
<Field
|
|
259
|
+
label="Message"
|
|
260
|
+
name="message"
|
|
261
|
+
id="message"
|
|
262
|
+
component={FormikTextareaInputInset}
|
|
263
|
+
isRequired
|
|
264
|
+
/>
|
|
265
|
+
<DateInput
|
|
266
|
+
datePickerProps={{
|
|
267
|
+
onChange: (date) => {
|
|
268
|
+
setFieldValue('dateInput', date as Date);
|
|
269
|
+
},
|
|
270
|
+
selected: values.dateInput as unknown as Date,
|
|
271
|
+
}}
|
|
272
|
+
textInputProps={{
|
|
273
|
+
label: 'Date Input',
|
|
274
|
+
name: 'dateInput',
|
|
275
|
+
id: 'dateInput',
|
|
276
|
+
error: errors.dateInput,
|
|
277
|
+
isRequired: true,
|
|
278
|
+
onClear: () => {
|
|
279
|
+
setFieldValue('dateInput', null);
|
|
280
|
+
},
|
|
281
|
+
onBlur: handleBlur,
|
|
282
|
+
}}
|
|
283
|
+
/>
|
|
284
|
+
<Button type="submit" isLoading={isSubmitting}>
|
|
285
|
+
Submit
|
|
286
|
+
</Button>
|
|
287
|
+
<pre className="font-family-monospace">
|
|
288
|
+
{JSON.stringify(
|
|
289
|
+
formatOutput(values, isSubmitting),
|
|
290
|
+
undefined,
|
|
291
|
+
2
|
|
292
|
+
)}
|
|
293
|
+
</pre>
|
|
294
|
+
<pre className="font-family-monospace">
|
|
295
|
+
{JSON.stringify(
|
|
296
|
+
formatOutput(errors, undefined),
|
|
297
|
+
undefined,
|
|
298
|
+
2
|
|
299
|
+
)}
|
|
300
|
+
</pre>
|
|
301
|
+
</Box>
|
|
302
|
+
</Form>
|
|
303
|
+
)}
|
|
304
|
+
</Formik>
|
|
305
|
+
</Box>
|
|
306
|
+
);
|
|
307
|
+
})();
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
render,
|
|
4
|
+
fireEvent,
|
|
5
|
+
screen,
|
|
6
|
+
waitFor,
|
|
7
|
+
act,
|
|
8
|
+
} from '@testing-library/react';
|
|
9
|
+
import { Formik, Form, Field, getIn, setIn, FormikValues } from 'formik';
|
|
10
|
+
import { FormikCheckboxInput } from './FormikCheckboxInput';
|
|
11
|
+
|
|
12
|
+
const testLabelName = 'test checkbox';
|
|
13
|
+
|
|
14
|
+
const handleValidation = (testValueKey: string) => (values: FormikValues) =>
|
|
15
|
+
getIn(values, testValueKey)
|
|
16
|
+
? {}
|
|
17
|
+
: setIn({}, testValueKey, 'Checkbox is required');
|
|
18
|
+
|
|
19
|
+
const renderForm = (
|
|
20
|
+
initialValue: any,
|
|
21
|
+
props: any,
|
|
22
|
+
testValueKey = testLabelName
|
|
23
|
+
) => (
|
|
24
|
+
<Formik
|
|
25
|
+
initialValues={{
|
|
26
|
+
[testLabelName]: initialValue,
|
|
27
|
+
}}
|
|
28
|
+
onSubmit={props.handleSubmit} // eslint-disable-line
|
|
29
|
+
validate={props.isRequired ? handleValidation(testValueKey) : undefined} // eslint-disable-line
|
|
30
|
+
>
|
|
31
|
+
{() => (
|
|
32
|
+
<Form noValidate>
|
|
33
|
+
<Field
|
|
34
|
+
label={testValueKey}
|
|
35
|
+
name={testValueKey}
|
|
36
|
+
id={testValueKey}
|
|
37
|
+
component={FormikCheckboxInput}
|
|
38
|
+
{...props}
|
|
39
|
+
/>
|
|
40
|
+
<button type="submit">submit</button>
|
|
41
|
+
</Form>
|
|
42
|
+
)}
|
|
43
|
+
</Formik>
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
describe('FormikCheckboxInput', () => {
|
|
47
|
+
describe('States', () => {
|
|
48
|
+
describe('With default props', () => {
|
|
49
|
+
test('renders not disabled, checked, or invalid by default', () => {
|
|
50
|
+
const { getByLabelText } = render(renderForm(false, {}));
|
|
51
|
+
const checkbox = getByLabelText(testLabelName) as HTMLInputElement;
|
|
52
|
+
|
|
53
|
+
expect(checkbox.checked).toBe(false);
|
|
54
|
+
expect(checkbox.disabled).toBe(false);
|
|
55
|
+
expect(checkbox.getAttribute('aria-invalid')).toBe('false');
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('With initial value true', () => {
|
|
60
|
+
test('input is rendered checked when instantiated with isChecked true', () => {
|
|
61
|
+
const { getByLabelText } = render(renderForm(true, {}));
|
|
62
|
+
const checkbox = getByLabelText(testLabelName) as HTMLInputElement;
|
|
63
|
+
expect(checkbox.checked).toEqual(true);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('With initial value false', () => {
|
|
68
|
+
test('input is rendered unchecked when instantiated with isChecked false', () => {
|
|
69
|
+
const { getByLabelText } = render(renderForm(false, {}));
|
|
70
|
+
const checkbox = getByLabelText(testLabelName) as HTMLInputElement;
|
|
71
|
+
expect(checkbox.checked).toEqual(false);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('Disabled', () => {
|
|
76
|
+
test('input is rendered with the disabled attrbute when isDisabled is true', () => {
|
|
77
|
+
const { getByLabelText } = render(
|
|
78
|
+
renderForm(false, { isDisabled: true })
|
|
79
|
+
);
|
|
80
|
+
const checkbox = getByLabelText(testLabelName);
|
|
81
|
+
expect(checkbox).toBeDisabled();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('Correctly supplies aria-labelledby', () => {
|
|
86
|
+
test('assigns the "aria-labelledby" attribute and renders label with correct id, when label is provided', () => {
|
|
87
|
+
const { getByLabelText } = render(renderForm(false, {}));
|
|
88
|
+
expect(getByLabelText(testLabelName)).toHaveAttribute(
|
|
89
|
+
'aria-labelledby',
|
|
90
|
+
`${testLabelName}Label`
|
|
91
|
+
);
|
|
92
|
+
expect(
|
|
93
|
+
document.getElementById(`${testLabelName}Label`)
|
|
94
|
+
).toBeInTheDocument();
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('With Error', () => {
|
|
99
|
+
test('correctly renders the checkbox with an error message underneath', async () => {
|
|
100
|
+
const { getByText } = render(renderForm(false, { isRequired: true }));
|
|
101
|
+
const submitButton = getByText('submit');
|
|
102
|
+
|
|
103
|
+
fireEvent.click(submitButton);
|
|
104
|
+
await waitFor(() =>
|
|
105
|
+
expect(screen.getByText('Checkbox is required')).toBeInTheDocument()
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('correctly renders the checkbox with an error message in nested object', async () => {
|
|
110
|
+
const { getByText } = render(
|
|
111
|
+
renderForm(
|
|
112
|
+
{ outer: { nested: false } },
|
|
113
|
+
{ isRequired: true },
|
|
114
|
+
`${testLabelName}.outer.nested`
|
|
115
|
+
)
|
|
116
|
+
);
|
|
117
|
+
const submitButton = getByText('submit');
|
|
118
|
+
|
|
119
|
+
fireEvent.click(submitButton);
|
|
120
|
+
await waitFor(() =>
|
|
121
|
+
expect(screen.getByText('Checkbox is required')).toBeInTheDocument()
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('Callback Handling', () => {
|
|
128
|
+
describe('onChange', () => {
|
|
129
|
+
test("Custom onChange event fires callback function, overwriting Formik's onChange", () => {
|
|
130
|
+
let value = false;
|
|
131
|
+
const mockedHandleChange = jest.fn((event) => {
|
|
132
|
+
value = event.target.checked;
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const { getByLabelText } = render(
|
|
136
|
+
renderForm(value, { onChange: mockedHandleChange })
|
|
137
|
+
);
|
|
138
|
+
const checkbox = getByLabelText(testLabelName);
|
|
139
|
+
|
|
140
|
+
act(() => {
|
|
141
|
+
fireEvent.click(checkbox);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
expect(mockedHandleChange).toHaveBeenCalledTimes(1);
|
|
145
|
+
expect(value).toBe(true);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('Standard Formik onChange modifies the target value', async () => {
|
|
149
|
+
const { getByLabelText, getByText, queryByText } = render(
|
|
150
|
+
renderForm(false, { isRequired: true })
|
|
151
|
+
);
|
|
152
|
+
const submitButton = getByText('submit');
|
|
153
|
+
const checkbox = getByLabelText(testLabelName) as HTMLInputElement;
|
|
154
|
+
expect(checkbox.checked).toBe(false);
|
|
155
|
+
|
|
156
|
+
fireEvent.click(submitButton);
|
|
157
|
+
// expect(mockedHandleSubmit).toHaveBeenCalledTimes(0);
|
|
158
|
+
await waitFor(() =>
|
|
159
|
+
expect(getByText('Checkbox is required')).toBeInTheDocument()
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
act(() => {
|
|
163
|
+
fireEvent.click(checkbox);
|
|
164
|
+
});
|
|
165
|
+
expect(checkbox.checked).toBe(true);
|
|
166
|
+
await waitFor(() =>
|
|
167
|
+
expect(queryByText('Checkbox is required')).not.toBeInTheDocument()
|
|
168
|
+
);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
FormikTouched,
|
|
4
|
+
FormikErrors,
|
|
5
|
+
FieldAttributes,
|
|
6
|
+
FormikValues,
|
|
7
|
+
getIn,
|
|
8
|
+
} from 'formik';
|
|
9
|
+
import {
|
|
10
|
+
CheckboxInput,
|
|
11
|
+
CheckboxInputProps,
|
|
12
|
+
} from '../../CheckboxInput/CheckboxInput';
|
|
13
|
+
|
|
14
|
+
export interface FormikCheckboxInputProps
|
|
15
|
+
extends Omit<CheckboxInputProps, 'onChange'> {
|
|
16
|
+
field: FieldAttributes<HTMLInputElement>;
|
|
17
|
+
form: {
|
|
18
|
+
touched: FormikTouched<FormikValues>;
|
|
19
|
+
errors: FormikErrors<FormikValues>;
|
|
20
|
+
};
|
|
21
|
+
onChange?: CheckboxInputProps['onChange'];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const FormikCheckboxInput: React.FC<FormikCheckboxInputProps> = ({
|
|
25
|
+
field: { name, onBlur, onChange: formikOnChange, value },
|
|
26
|
+
form: { touched, errors },
|
|
27
|
+
onChange,
|
|
28
|
+
id,
|
|
29
|
+
label,
|
|
30
|
+
...props
|
|
31
|
+
}) => (
|
|
32
|
+
<CheckboxInput
|
|
33
|
+
{...props}
|
|
34
|
+
id={id}
|
|
35
|
+
label={label}
|
|
36
|
+
error={getIn(touched, name) && getIn(errors, name)}
|
|
37
|
+
isChecked={value}
|
|
38
|
+
onBlur={onBlur}
|
|
39
|
+
onChange={onChange ?? formikOnChange} // eslint-disable-line
|
|
40
|
+
/>
|
|
41
|
+
);
|