@nypl/design-system-react-components 0.25.12 → 0.26.1
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/CHANGELOG.md +131 -1
- package/README.md +10 -10
- package/dist/components/Accordion/Accordion.d.ts +6 -4
- package/dist/components/Accordion/AccordionTypes.d.ts +5 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +4 -4
- package/dist/components/Breadcrumbs/BreadcrumbsTypes.d.ts +1 -1
- package/dist/components/Button/Button.d.ts +2 -2
- package/dist/components/Card/Card.d.ts +22 -29
- package/dist/components/Checkbox/Checkbox.d.ts +3 -3
- package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +9 -6
- package/dist/components/ComponentWrapper/ComponentWrapper.d.ts +1 -1
- package/dist/components/DatePicker/DatePicker.d.ts +5 -6
- package/dist/components/Fieldset/Fieldset.d.ts +5 -6
- package/dist/components/Form/Form.d.ts +6 -6
- package/dist/components/Grid/GridTypes.d.ts +7 -7
- package/dist/components/Grid/SimpleGrid.d.ts +1 -1
- package/dist/components/Heading/Heading.d.ts +5 -5
- package/dist/components/Heading/HeadingTypes.d.ts +1 -1
- package/dist/components/HelperErrorText/HelperErrorText.d.ts +9 -8
- package/dist/components/Hero/Hero.d.ts +9 -5
- package/dist/components/HorizontalRule/HorizontalRule.d.ts +2 -10
- package/dist/components/Icons/Icon.d.ts +2 -1
- package/dist/components/Icons/IconTypes.d.ts +1 -0
- package/dist/components/Image/Image.d.ts +27 -9
- package/dist/components/Image/ImageTypes.d.ts +4 -4
- package/dist/components/Label/Label.d.ts +7 -4
- package/dist/components/Link/Link.d.ts +1 -1
- package/dist/components/List/List.d.ts +11 -11
- package/dist/components/List/ListTypes.d.ts +1 -1
- package/dist/components/Logo/Logo.d.ts +2 -1
- package/dist/components/Logo/LogoSvgs.d.ts +2 -0
- package/dist/components/Logo/LogoTypes.d.ts +4 -2
- package/dist/components/Notification/Notification.d.ts +7 -7
- package/dist/components/Pagination/Pagination.d.ts +2 -2
- package/dist/components/ProgressIndicator/ProgressIndicator.d.ts +3 -3
- package/dist/components/Radio/Radio.d.ts +5 -7
- package/dist/components/RadioGroup/RadioGroup.d.ts +16 -8
- package/dist/components/SearchBar/SearchBar.d.ts +4 -4
- package/dist/components/Select/Select.d.ts +12 -8
- package/dist/components/Select/SelectTypes.d.ts +4 -0
- package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +8 -6
- package/dist/components/SkeletonLoader/SkeletonLoaderTypes.d.ts +0 -4
- package/dist/components/Slider/Slider.d.ts +6 -4
- package/dist/components/StatusBadge/StatusBadge.d.ts +5 -1
- package/dist/components/StructuredContent/StructuredContent.d.ts +10 -23
- package/dist/components/Table/Table.d.ts +1 -1
- package/dist/components/Tabs/Tabs.d.ts +7 -6
- package/dist/components/Template/Template.d.ts +17 -8
- package/dist/components/Text/Text.d.ts +4 -4
- package/dist/components/Text/TextTypes.d.ts +1 -1
- package/dist/components/TextInput/TextInput.d.ts +7 -7
- package/dist/components/Toggle/Toggle.d.ts +8 -10
- package/dist/components/Toggle/{ToggleSizes.d.ts → ToggleTypes.d.ts} +1 -1
- package/dist/components/VideoPlayer/VideoPlayer.d.ts +2 -1
- package/dist/design-system-react-components.cjs.development.js +2075 -1468
- package/dist/design-system-react-components.cjs.development.js.map +1 -1
- package/dist/design-system-react-components.cjs.production.min.js +1 -1
- package/dist/design-system-react-components.cjs.production.min.js.map +1 -1
- package/dist/design-system-react-components.esm.js +2086 -1483
- package/dist/design-system-react-components.esm.js.map +1 -1
- package/dist/helpers/enums.d.ts +4 -0
- package/dist/hooks/useCarouselStyles.d.ts +3 -2
- package/dist/hooks/useNYPLTheme.d.ts +12 -0
- package/dist/index.d.ts +11 -9
- package/dist/styles.css +1 -1
- package/dist/theme/components/accordion.d.ts +7 -12
- package/dist/theme/components/breadcrumb.d.ts +3 -0
- package/dist/theme/components/button.d.ts +10 -2
- package/dist/theme/components/card.d.ts +44 -24
- package/dist/theme/components/checkbox.d.ts +6 -4
- package/dist/theme/components/checkboxGroup.d.ts +4 -2
- package/dist/theme/components/componentWrapper.d.ts +2 -2
- package/dist/theme/components/customTable.d.ts +84 -1
- package/dist/theme/components/fieldset.d.ts +4 -14
- package/dist/theme/components/global.d.ts +25 -18
- package/dist/theme/components/heading.d.ts +53 -0
- package/dist/theme/components/helperErrorText.d.ts +1 -0
- package/dist/theme/components/hero.d.ts +21 -15
- package/dist/theme/components/image.d.ts +1 -1
- package/dist/theme/components/label.d.ts +9 -10
- package/dist/theme/components/list.d.ts +99 -9
- package/dist/theme/components/notification.d.ts +4 -4
- package/dist/theme/components/pagination.d.ts +2 -5
- package/dist/theme/components/radio.d.ts +7 -4
- package/dist/theme/components/radioGroup.d.ts +4 -2
- package/dist/theme/components/select.d.ts +37 -5
- package/dist/theme/components/skeletonLoader.d.ts +2 -2
- package/dist/theme/components/slider.d.ts +6 -3
- package/dist/theme/components/structuredContent.d.ts +197 -0
- package/dist/theme/components/textInput.d.ts +18 -6
- package/dist/theme/components/toggle.d.ts +20 -5
- package/dist/theme/foundations/global.d.ts +2 -0
- package/dist/theme/foundations/radii.d.ts +1 -0
- package/dist/theme/foundations/spacing.d.ts +46 -43
- package/package.json +5 -6
- package/src/components/AccessibilityGuide/SkipNavigation.stories.mdx +34 -0
- package/src/components/Accordion/Accordion.stories.mdx +150 -66
- package/src/components/Accordion/Accordion.test.tsx +65 -17
- package/src/components/Accordion/Accordion.tsx +61 -27
- package/src/components/Accordion/AccordionTypes.tsx +5 -0
- package/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap +505 -14
- package/src/components/Autosuggest/Autosuggest.stories.mdx +4 -3
- package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +37 -19
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +57 -36
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +14 -13
- package/src/components/Breadcrumbs/BreadcrumbsTypes.tsx +1 -1
- package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +211 -12
- package/src/components/Button/Button.stories.mdx +87 -23
- package/src/components/Button/Button.test.tsx +25 -0
- package/src/components/Button/Button.tsx +18 -7
- package/src/components/Button/__snapshots__/Button.test.tsx.snap +27 -7
- package/src/components/Card/Card.stories.mdx +493 -329
- package/src/components/Card/Card.test.tsx +138 -18
- package/src/components/Card/Card.tsx +151 -85
- package/src/components/Card/__snapshots__/Card.test.tsx.snap +221 -101
- package/src/components/Chakra/Center.stories.mdx +2 -2
- package/src/components/Chakra/Grid.stories.mdx +4 -4
- package/src/components/Checkbox/Checkbox.stories.mdx +73 -9
- package/src/components/Checkbox/Checkbox.test.tsx +89 -10
- package/src/components/Checkbox/Checkbox.tsx +26 -16
- package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +209 -6
- package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +135 -23
- package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +216 -90
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +39 -26
- package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +493 -89
- package/src/components/ComponentWrapper/ComponentWrapper.test.tsx +12 -0
- package/src/components/ComponentWrapper/ComponentWrapper.tsx +39 -41
- package/src/components/ComponentWrapper/__snapshots__/ComponentWrapper.test.tsx.snap +47 -34
- package/src/components/DatePicker/DatePicker.stories.mdx +63 -27
- package/src/components/DatePicker/DatePicker.test.tsx +94 -15
- package/src/components/DatePicker/DatePicker.tsx +67 -58
- package/src/components/DatePicker/_DatePicker.scss +71 -13
- package/src/components/DatePicker/__snapshots__/DatePicker.test.tsx.snap +250 -206
- package/src/components/Fieldset/Fieldset.stories.mdx +33 -3
- package/src/components/Fieldset/Fieldset.test.tsx +58 -28
- package/src/components/Fieldset/Fieldset.tsx +35 -30
- package/src/components/Fieldset/__snapshots__/Fieldset.test.tsx.snap +40 -19
- package/src/components/Form/Form.stories.mdx +118 -47
- package/src/components/Form/Form.test.tsx +59 -16
- package/src/components/Form/Form.tsx +89 -65
- package/src/components/Form/__snapshots__/Form.test.tsx.snap +83 -5
- package/src/components/Grid/GridTypes.tsx +7 -7
- package/src/components/Grid/SimpleGrid.stories.mdx +87 -41
- package/src/components/Grid/SimpleGrid.test.tsx +24 -9
- package/src/components/Grid/SimpleGrid.tsx +29 -20
- package/src/components/Grid/__snapshots__/SimpleGrid.test.tsx.snap +16 -1
- package/src/components/Heading/Heading.stories.mdx +56 -25
- package/src/components/Heading/Heading.test.tsx +17 -7
- package/src/components/Heading/Heading.tsx +60 -58
- package/src/components/Heading/HeadingTypes.tsx +1 -1
- package/src/components/Heading/__snapshots__/Heading.test.tsx.snap +27 -8
- package/src/components/HelperErrorText/HelperErrorText.stories.mdx +64 -42
- package/src/components/HelperErrorText/HelperErrorText.test.tsx +15 -0
- package/src/components/HelperErrorText/HelperErrorText.tsx +40 -35
- package/src/components/HelperErrorText/__snapshots__/HelperErrorText.test.tsx.snap +35 -4
- package/src/components/Hero/Hero.stories.mdx +143 -113
- package/src/components/Hero/Hero.test.tsx +146 -58
- package/src/components/Hero/Hero.tsx +144 -112
- package/src/components/Hero/__snapshots__/Hero.test.tsx.snap +89 -17
- package/src/components/HorizontalRule/HorizontalRule.stories.mdx +26 -4
- package/src/components/HorizontalRule/HorizontalRule.test.tsx +9 -17
- package/src/components/HorizontalRule/HorizontalRule.tsx +9 -25
- package/src/components/HorizontalRule/__snapshots__/HorizontalRule.test.tsx.snap +18 -5
- package/src/components/Icons/Icon.stories.mdx +80 -23
- package/src/components/Icons/Icon.test.tsx +51 -2
- package/src/components/Icons/Icon.tsx +93 -71
- package/src/components/Icons/IconTypes.tsx +1 -0
- package/src/components/Icons/__snapshots__/Icon.test.tsx.snap +129 -0
- package/src/components/Image/Image.stories.mdx +160 -71
- package/src/components/Image/Image.test.tsx +40 -48
- package/src/components/Image/Image.tsx +80 -48
- package/src/components/Image/ImageTypes.ts +4 -4
- package/src/components/Image/__snapshots__/Image.test.tsx.snap +84 -21
- package/src/components/Label/Label.stories.mdx +42 -20
- package/src/components/Label/Label.test.tsx +42 -17
- package/src/components/Label/Label.tsx +22 -13
- package/src/components/Label/__snapshots__/Label.test.tsx.snap +19 -15
- package/src/components/Link/Link.stories.mdx +25 -1
- package/src/components/Link/Link.test.tsx +21 -0
- package/src/components/Link/Link.tsx +16 -9
- package/src/components/Link/__snapshots__/Link.test.tsx.snap +37 -11
- package/src/components/List/List.stories.mdx +75 -40
- package/src/components/List/List.test.tsx +73 -22
- package/src/components/List/List.tsx +44 -28
- package/src/components/List/ListTypes.tsx +1 -1
- package/src/components/List/__snapshots__/List.test.tsx.snap +110 -8
- package/src/components/Logo/Logo.stories.mdx +40 -16
- package/src/components/Logo/Logo.test.tsx +29 -2
- package/src/components/Logo/Logo.tsx +28 -11
- package/src/components/Logo/LogoSvgs.tsx +4 -0
- package/src/components/Logo/LogoTypes.tsx +3 -1
- package/src/components/Logo/__snapshots__/Logo.test.tsx.snap +73 -2
- package/src/components/Modal/Modal.stories.mdx +13 -0
- package/src/components/Notification/Notification.stories.mdx +29 -5
- package/src/components/Notification/Notification.test.tsx +23 -0
- package/src/components/Notification/Notification.tsx +53 -51
- package/src/components/Notification/__snapshots__/Notification.test.tsx.snap +158 -29
- package/src/components/Pagination/Pagination.stories.mdx +27 -6
- package/src/components/Pagination/Pagination.test.tsx +55 -2
- package/src/components/Pagination/Pagination.tsx +12 -9
- package/src/components/Pagination/__snapshots__/Pagination.test.tsx.snap +244 -27
- package/src/components/Placeholder/Placeholder.tsx +3 -1
- package/src/components/ProgressIndicator/ProgressIndicator.stories.mdx +76 -10
- package/src/components/ProgressIndicator/ProgressIndicator.test.tsx +87 -13
- package/src/components/ProgressIndicator/ProgressIndicator.tsx +20 -10
- package/src/components/ProgressIndicator/__snapshots__/ProgressIndicator.test.tsx.snap +101 -14
- package/src/components/Radio/Radio.stories.mdx +75 -11
- package/src/components/Radio/Radio.test.tsx +83 -9
- package/src/components/Radio/Radio.tsx +70 -62
- package/src/components/Radio/__snapshots__/Radio.test.tsx.snap +163 -5
- package/src/components/RadioGroup/RadioGroup.stories.mdx +293 -94
- package/src/components/RadioGroup/RadioGroup.test.tsx +193 -68
- package/src/components/RadioGroup/RadioGroup.tsx +110 -101
- package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +1258 -902
- package/src/components/SearchBar/SearchBar.stories.mdx +101 -36
- package/src/components/SearchBar/{SearchBar.Test.tsx → SearchBar.test.tsx} +46 -4
- package/src/components/SearchBar/SearchBar.tsx +20 -11
- package/src/components/SearchBar/__snapshots__/SearchBar.test.tsx.snap +1039 -0
- package/src/components/Select/Select.stories.mdx +151 -62
- package/src/components/Select/Select.test.tsx +56 -44
- package/src/components/Select/Select.tsx +125 -104
- package/src/components/Select/SelectTypes.tsx +5 -0
- package/src/components/Select/__snapshots__/Select.test.tsx.snap +749 -409
- package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +53 -23
- package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +14 -8
- package/src/components/SkeletonLoader/SkeletonLoader.tsx +80 -78
- package/src/components/SkeletonLoader/SkeletonLoaderTypes.tsx +0 -5
- package/src/components/SkeletonLoader/__snapshots__/SkeletonLoader.test.tsx.snap +169 -10
- package/src/components/Slider/Slider.stories.mdx +123 -41
- package/src/components/Slider/Slider.test.tsx +65 -17
- package/src/components/Slider/Slider.tsx +30 -23
- package/src/components/Slider/__snapshots__/Slider.test.tsx.snap +403 -226
- package/src/components/StatusBadge/StatusBadge.stories.mdx +19 -1
- package/src/components/StatusBadge/StatusBadge.test.tsx +19 -1
- package/src/components/StatusBadge/StatusBadge.tsx +25 -20
- package/src/components/StatusBadge/__snapshots__/StatusBadge.test.tsx.snap +22 -3
- package/src/components/StructuredContent/StructuredContent.stories.mdx +229 -61
- package/src/components/StructuredContent/StructuredContent.test.tsx +162 -101
- package/src/components/StructuredContent/StructuredContent.tsx +98 -103
- package/src/components/StructuredContent/__snapshots__/StructuredContent.test.tsx.snap +102 -17
- package/src/components/StyleGuide/Bidirectionality.stories.mdx +5 -5
- package/src/components/StyleGuide/Breakpoints.stories.mdx +6 -6
- package/src/components/StyleGuide/Buttons.stories.mdx +2 -12
- package/src/components/StyleGuide/ColorCard.tsx +4 -4
- package/src/components/StyleGuide/Colors.stories.mdx +1 -2
- package/src/components/StyleGuide/DesignTokens.stories.mdx +56 -26
- package/src/components/StyleGuide/Forms.stories.mdx +27 -12
- package/src/components/StyleGuide/Iconography.stories.mdx +2 -12
- package/src/components/StyleGuide/Spacing.stories.mdx +80 -41
- package/src/components/StyleGuide/Typography.stories.mdx +47 -33
- package/src/components/Table/Table.stories.mdx +38 -11
- package/src/components/Table/Table.test.tsx +16 -1
- package/src/components/Table/Table.tsx +10 -8
- package/src/components/Table/__snapshots__/Table.test.tsx.snap +408 -5
- package/src/components/Tabs/Tabs.stories.mdx +59 -10
- package/src/components/Tabs/Tabs.test.tsx +29 -11
- package/src/components/Tabs/Tabs.tsx +28 -21
- package/src/components/Tabs/__snapshots__/Tabs.test.tsx.snap +394 -5
- package/src/components/Template/Template.stories.mdx +73 -32
- package/src/components/Template/Template.test.tsx +68 -5
- package/src/components/Template/Template.tsx +89 -71
- package/src/components/Template/__snapshots__/Template.test.tsx.snap +195 -22
- package/src/components/Text/Text.stories.mdx +32 -15
- package/src/components/Text/Text.test.tsx +14 -11
- package/src/components/Text/Text.tsx +13 -16
- package/src/components/Text/TextTypes.tsx +1 -1
- package/src/components/Text/__snapshots__/Text.test.tsx.snap +21 -4
- package/src/components/TextInput/TextInput.stories.mdx +73 -27
- package/src/components/TextInput/TextInput.test.tsx +65 -50
- package/src/components/TextInput/TextInput.tsx +123 -115
- package/src/components/TextInput/__snapshots__/TextInput.test.tsx.snap +96 -73
- package/src/components/Toggle/Toggle.stories.mdx +74 -26
- package/src/components/Toggle/Toggle.test.tsx +41 -10
- package/src/components/Toggle/Toggle.tsx +29 -26
- package/src/components/Toggle/{ToggleSizes.tsx → ToggleTypes.tsx} +1 -1
- package/src/components/Toggle/__snapshots__/Toggle.test.tsx.snap +191 -4
- package/src/components/VideoPlayer/VideoPlayer.stories.mdx +52 -4
- package/src/components/VideoPlayer/VideoPlayer.test.tsx +41 -6
- package/src/components/VideoPlayer/VideoPlayer.tsx +134 -120
- package/src/components/VideoPlayer/__snapshots__/VideoPlayer.test.tsx.snap +81 -39
- package/src/docs/Chakra.stories.mdx +50 -9
- package/src/docs/Welcome.stories.mdx +168 -0
- package/src/{components/Card/CardTypes.tsx → helpers/enums.ts} +2 -2
- package/src/hooks/tests/useNYPLTheme.test.tsx +1 -1
- package/src/hooks/useCarouselStyles.stories.mdx +30 -0
- package/src/hooks/useCarouselStyles.ts +3 -2
- package/src/hooks/useNYPLTheme.stories.mdx +101 -0
- package/src/hooks/useNYPLTheme.ts +31 -7
- package/src/hooks/useWindowSize.stories.mdx +23 -0
- package/src/index.ts +11 -15
- package/src/styles/base/_place-holder.scss +1 -1
- package/src/theme/components/accordion.ts +7 -12
- package/src/theme/components/breadcrumb.ts +3 -0
- package/src/theme/components/button.ts +15 -7
- package/src/theme/components/card.ts +56 -36
- package/src/theme/components/checkbox.ts +10 -8
- package/src/theme/components/checkboxGroup.ts +4 -2
- package/src/theme/components/componentWrapper.ts +2 -2
- package/src/theme/components/customTable.ts +39 -31
- package/src/theme/components/fieldset.ts +1 -2
- package/src/theme/components/global.ts +29 -23
- package/src/theme/components/heading.ts +1 -1
- package/src/theme/components/helperErrorText.ts +1 -0
- package/src/theme/components/hero.ts +14 -16
- package/src/theme/components/icon.ts +5 -2
- package/src/theme/components/image.ts +1 -1
- package/src/theme/components/label.ts +4 -3
- package/src/theme/components/list.ts +73 -66
- package/src/theme/components/notification.ts +7 -7
- package/src/theme/components/pagination.ts +2 -5
- package/src/theme/components/progressIndicator.ts +3 -3
- package/src/theme/components/radio.ts +9 -9
- package/src/theme/components/radioGroup.ts +4 -2
- package/src/theme/components/select.ts +35 -16
- package/src/theme/components/skeletonLoader.ts +3 -3
- package/src/theme/components/slider.ts +8 -7
- package/src/theme/components/statusBadge.ts +2 -2
- package/src/theme/components/structuredContent.ts +66 -1
- package/src/theme/components/tabs.ts +2 -2
- package/src/theme/components/template.ts +9 -9
- package/src/theme/components/textInput.ts +13 -12
- package/src/theme/components/toggle.ts +43 -13
- package/src/theme/components/videoPlayer.ts +1 -1
- package/src/theme/foundations/colors.ts +1 -1
- package/src/theme/foundations/radii.ts +1 -0
- package/src/theme/foundations/spacing.ts +70 -22
- package/src/theme/foundations/typography.ts +2 -2
- package/src/utils/componentCategories.ts +28 -21
- package/dist/components/Card/CardTypes.d.ts +0 -4
- package/dist/components/CheckboxGroup/CheckboxGroupLayoutTypes.d.ts +0 -4
- package/dist/components/RadioGroup/RadioGroupLayoutTypes.d.ts +0 -4
- package/dist/components/SearchBar/SearchBar.Test.d.ts +0 -1
- package/dist/helpers/generateUUID.d.ts +0 -1
- package/src/components/CheckboxGroup/CheckboxGroupLayoutTypes.tsx +0 -4
- package/src/components/RadioGroup/RadioGroupLayoutTypes.tsx +0 -4
- package/src/docs/Intro.stories.mdx +0 -53
- package/src/helpers/generateUUID.tsx +0 -5
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ButtonGroup, Flex, Spacer } from "@chakra-ui/react";
|
|
1
2
|
import { action } from "@storybook/addon-actions";
|
|
2
3
|
import {
|
|
3
4
|
ArgsTable,
|
|
@@ -60,7 +61,17 @@ export const enumValues = getStorybookEnumValues(FormGaps, "FormGaps");
|
|
|
60
61
|
| Component Version | DS Version |
|
|
61
62
|
| ----------------- | ---------- |
|
|
62
63
|
| Added | `0.23.2` |
|
|
63
|
-
| Latest | `0.
|
|
64
|
+
| Latest | `0.26.0` |
|
|
65
|
+
|
|
66
|
+
## Table of Contents
|
|
67
|
+
|
|
68
|
+
- [Overview](#overview)
|
|
69
|
+
- [Component Props](#component-props)
|
|
70
|
+
- [Accessibility](#accessibility)
|
|
71
|
+
- [Spacing Variants](#spacing-variants)
|
|
72
|
+
- [Example Code](#example-code)
|
|
73
|
+
|
|
74
|
+
## Overview
|
|
64
75
|
|
|
65
76
|
<Description of={Form} />
|
|
66
77
|
|
|
@@ -70,7 +81,7 @@ components should be used to build the `<form>` structure and to arrange input
|
|
|
70
81
|
fields as needed.
|
|
71
82
|
|
|
72
83
|
```jsx
|
|
73
|
-
<Form>
|
|
84
|
+
<Form id="form-id">
|
|
74
85
|
<FormRow>
|
|
75
86
|
<FormField>{/* ... */}</FormField>
|
|
76
87
|
</FormRow>
|
|
@@ -80,11 +91,13 @@ fields as needed.
|
|
|
80
91
|
</Form>
|
|
81
92
|
```
|
|
82
93
|
|
|
83
|
-
`FormField` should be used as a parent for all input components from the
|
|
84
|
-
(`Button`, `Select`, `TextInput`, etc.).
|
|
94
|
+
`FormField` should be used as a parent for all input components from the
|
|
95
|
+
Reservoir Design System (DS) (`Button`, `Select`, `TextInput`, etc.).
|
|
85
96
|
|
|
86
|
-
`FormRow` should be used as a parent of multiple `FormField` components when
|
|
87
|
-
need to render multiple input components in a horizontal row.
|
|
97
|
+
`FormRow` should be used as a parent of multiple `FormField` components when
|
|
98
|
+
you need to render multiple input components in a horizontal row.
|
|
99
|
+
|
|
100
|
+
## Component Props
|
|
88
101
|
|
|
89
102
|
<Canvas withToolbar>
|
|
90
103
|
<Story
|
|
@@ -98,30 +111,32 @@ need to render multiple input components in a horizontal row.
|
|
|
98
111
|
}}
|
|
99
112
|
>
|
|
100
113
|
{(args) => (
|
|
101
|
-
<Form {...args} gap={enumValues.getValue(args.gap)}>
|
|
114
|
+
<Form {...args} gap={enumValues.getValue(args.gap)} id="form-id">
|
|
102
115
|
<FormRow>
|
|
103
116
|
<FormField>
|
|
104
117
|
<TextInput
|
|
105
|
-
labelText="First Name"
|
|
106
118
|
helperText="Make sure to complete this field."
|
|
119
|
+
id="first-name"
|
|
107
120
|
isRequired
|
|
121
|
+
labelText="First Name"
|
|
108
122
|
/>
|
|
109
123
|
</FormField>
|
|
110
124
|
<FormField>
|
|
111
125
|
<TextInput
|
|
112
|
-
labelText="Last Name"
|
|
113
126
|
helperText="Make sure to complete this field."
|
|
127
|
+
id="last-name"
|
|
114
128
|
isRequired
|
|
129
|
+
labelText="Last Name"
|
|
115
130
|
/>
|
|
116
131
|
</FormField>
|
|
117
132
|
<FormField>
|
|
118
133
|
<DatePicker
|
|
119
|
-
id="date-range"
|
|
120
134
|
dateType={DatePickerTypes.Full}
|
|
121
135
|
dateFormat="yyyy-MM-dd"
|
|
122
136
|
helperTextFrom="From this date."
|
|
123
137
|
helperTextTo="To this date."
|
|
124
138
|
helperText="Select a valid date range."
|
|
139
|
+
id="date-range"
|
|
125
140
|
invalidText="Please select a valid date range."
|
|
126
141
|
isDateRange
|
|
127
142
|
labelText="Select the date range you want to visit NYPL"
|
|
@@ -134,37 +149,42 @@ need to render multiple input components in a horizontal row.
|
|
|
134
149
|
</FormRow>
|
|
135
150
|
<FormField>
|
|
136
151
|
<TextInput
|
|
137
|
-
labelText="Username"
|
|
138
152
|
helperText="Make sure to complete this field."
|
|
153
|
+
id="username"
|
|
139
154
|
isRequired
|
|
155
|
+
labelText="Username"
|
|
140
156
|
/>
|
|
141
157
|
</FormField>
|
|
142
158
|
<FormField>
|
|
143
159
|
<TextInput
|
|
144
|
-
labelText="Password"
|
|
145
160
|
helperText="Make sure to complete this field."
|
|
161
|
+
id="password"
|
|
146
162
|
isRequired
|
|
163
|
+
labelText="Password"
|
|
147
164
|
/>
|
|
148
165
|
</FormField>
|
|
149
166
|
<FormRow>
|
|
150
167
|
<FormField>
|
|
151
168
|
<TextInput
|
|
152
|
-
labelText="Phone Field"
|
|
153
169
|
helperText="This one is up to you."
|
|
170
|
+
id="phone"
|
|
171
|
+
labelText="Phone Field"
|
|
154
172
|
type="tel"
|
|
155
173
|
/>
|
|
156
174
|
</FormField>
|
|
157
175
|
<FormField>
|
|
158
176
|
<TextInput
|
|
159
|
-
labelText="URL Field"
|
|
160
177
|
helperText="This one is up to you."
|
|
178
|
+
id="url"
|
|
179
|
+
labelText="URL Field"
|
|
161
180
|
type="url"
|
|
162
181
|
/>
|
|
163
182
|
</FormField>
|
|
164
183
|
<FormField>
|
|
165
184
|
<TextInput
|
|
166
|
-
labelText="Age"
|
|
167
185
|
helperText="This one is up to you."
|
|
186
|
+
id="age"
|
|
187
|
+
labelText="Age"
|
|
168
188
|
type="number"
|
|
169
189
|
/>
|
|
170
190
|
</FormField>
|
|
@@ -172,29 +192,71 @@ need to render multiple input components in a horizontal row.
|
|
|
172
192
|
<FormRow>
|
|
173
193
|
<FormField>
|
|
174
194
|
<CheckboxGroup
|
|
195
|
+
id="checkbox-group"
|
|
196
|
+
isFullWidth
|
|
175
197
|
labelText="Checkbox Group"
|
|
176
|
-
name="
|
|
177
|
-
optReqFlag={false}
|
|
198
|
+
name="checkbox-example"
|
|
178
199
|
>
|
|
179
|
-
<Checkbox
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
200
|
+
<Checkbox
|
|
201
|
+
id="arts"
|
|
202
|
+
labelText={
|
|
203
|
+
<Flex>
|
|
204
|
+
<span>Arts</span>
|
|
205
|
+
<Spacer />
|
|
206
|
+
<span>4</span>
|
|
207
|
+
</Flex>
|
|
208
|
+
}
|
|
209
|
+
value="arts"
|
|
210
|
+
/>
|
|
211
|
+
<Checkbox
|
|
212
|
+
id="english"
|
|
213
|
+
labelText={
|
|
214
|
+
<Flex>
|
|
215
|
+
<span>English</span>
|
|
216
|
+
<Spacer />
|
|
217
|
+
<span>23</span>
|
|
218
|
+
</Flex>
|
|
219
|
+
}
|
|
220
|
+
value="English"
|
|
221
|
+
/>
|
|
222
|
+
<Checkbox
|
|
223
|
+
id="science"
|
|
224
|
+
labelText={
|
|
225
|
+
<Flex>
|
|
226
|
+
<span>Science</span>
|
|
227
|
+
<Spacer />
|
|
228
|
+
<span>10</span>
|
|
229
|
+
</Flex>
|
|
230
|
+
}
|
|
231
|
+
value="Science"
|
|
232
|
+
/>
|
|
233
|
+
<Checkbox
|
|
234
|
+
id="math"
|
|
235
|
+
labelText={
|
|
236
|
+
<Flex>
|
|
237
|
+
<span>Math</span>
|
|
238
|
+
<Spacer />
|
|
239
|
+
<span>3</span>
|
|
240
|
+
</Flex>
|
|
241
|
+
}
|
|
242
|
+
value="Math"
|
|
243
|
+
/>
|
|
183
244
|
</CheckboxGroup>
|
|
184
245
|
</FormField>
|
|
185
246
|
<FormField>
|
|
186
|
-
<RadioGroup labelText="Radio Group" name="rg1"
|
|
187
|
-
<Radio labelText="Radio 1"
|
|
188
|
-
<Radio labelText="Radio 2"
|
|
189
|
-
<Radio labelText="Radio 3"
|
|
190
|
-
<Radio labelText="Radio 4"
|
|
247
|
+
<RadioGroup id="radio-group" labelText="Radio Group" name="rg1">
|
|
248
|
+
<Radio id="radio1" labelText="Radio 1" value="radio1" />
|
|
249
|
+
<Radio id="radio2" labelText="Radio 2" value="radio2" />
|
|
250
|
+
<Radio id="radio3" labelText="Radio 3" value="radio3" />
|
|
251
|
+
<Radio id="radio4" labelText="Radio 4" value="radio4" />
|
|
191
252
|
</RadioGroup>
|
|
192
253
|
</FormField>
|
|
193
254
|
<FormField>
|
|
194
255
|
<Select
|
|
256
|
+
helperText="The select field helper text."
|
|
257
|
+
id="select"
|
|
195
258
|
labelText="Select Field"
|
|
196
259
|
showLabel={true}
|
|
197
|
-
helperText="The select field helper text."
|
|
198
260
|
>
|
|
199
261
|
<option>Option 1</option>
|
|
200
262
|
<option>Option 2</option>
|
|
@@ -204,9 +266,13 @@ need to render multiple input components in a horizontal row.
|
|
|
204
266
|
</Select>
|
|
205
267
|
</FormField>
|
|
206
268
|
</FormRow>
|
|
207
|
-
<
|
|
208
|
-
<
|
|
209
|
-
|
|
269
|
+
<FormRow>
|
|
270
|
+
<FormField>
|
|
271
|
+
<ButtonGroup>
|
|
272
|
+
<Button id="submit">Submit</Button>
|
|
273
|
+
</ButtonGroup>
|
|
274
|
+
</FormField>
|
|
275
|
+
</FormRow>
|
|
210
276
|
</Form>
|
|
211
277
|
)}
|
|
212
278
|
</Story>
|
|
@@ -214,6 +280,17 @@ need to render multiple input components in a horizontal row.
|
|
|
214
280
|
|
|
215
281
|
<ArgsTable story="Form with Controls" />
|
|
216
282
|
|
|
283
|
+
## Accessibility
|
|
284
|
+
|
|
285
|
+
The `Form` component renders a standard `<form>` element and should be used to
|
|
286
|
+
wrap all form elements. A `Form` should have a `Button` component with a `type`
|
|
287
|
+
of `submit` to submit the form to a server through the `Form`'s `action` prop.
|
|
288
|
+
|
|
289
|
+
Resources:
|
|
290
|
+
|
|
291
|
+
- [WebAIM Creating Accessible Forms](https://webaim.org/techniques/forms/)
|
|
292
|
+
- [Deque The Anatomy of Accessible Forms: Best Practices](https://www.deque.com/blog/anatomy-of-accessible-forms-best-practices/)
|
|
293
|
+
|
|
217
294
|
## Spacing Variants
|
|
218
295
|
|
|
219
296
|
export const formRow = (nameString, size) => {
|
|
@@ -221,13 +298,14 @@ export const formRow = (nameString, size) => {
|
|
|
221
298
|
return (
|
|
222
299
|
<li key={size}>
|
|
223
300
|
<Heading level={HeadingLevels.Three}>{labelText}</Heading>
|
|
224
|
-
<Form gap={size}>
|
|
301
|
+
<Form gap={size} id={`form-spacing-${size}`}>
|
|
225
302
|
<FormRow>
|
|
226
303
|
<FormField>
|
|
227
304
|
<Select
|
|
305
|
+
helperText="The select field helper text."
|
|
306
|
+
id={`select-spacing-${size}-1`}
|
|
228
307
|
labelText="Select Field"
|
|
229
308
|
showLabel={true}
|
|
230
|
-
helperText="The select field helper text."
|
|
231
309
|
>
|
|
232
310
|
<option>Option 1</option>
|
|
233
311
|
<option>Option 2</option>
|
|
@@ -237,9 +315,10 @@ export const formRow = (nameString, size) => {
|
|
|
237
315
|
</FormField>
|
|
238
316
|
<FormField>
|
|
239
317
|
<Select
|
|
318
|
+
helperText="The select field helper text."
|
|
319
|
+
id={`select-spacing-${size}-2`}
|
|
240
320
|
labelText="Select Field"
|
|
241
321
|
showLabel={true}
|
|
242
|
-
helperText="The select field helper text."
|
|
243
322
|
>
|
|
244
323
|
<option>Option 1</option>
|
|
245
324
|
<option>Option 2</option>
|
|
@@ -249,9 +328,10 @@ export const formRow = (nameString, size) => {
|
|
|
249
328
|
</FormField>
|
|
250
329
|
<FormField>
|
|
251
330
|
<Select
|
|
331
|
+
helperText="The select field helper text."
|
|
332
|
+
id={`select-spacing-${size}-3`}
|
|
252
333
|
labelText="Select Field"
|
|
253
334
|
showLabel={true}
|
|
254
|
-
helperText="The select field helper text."
|
|
255
335
|
>
|
|
256
336
|
<option>Option 1</option>
|
|
257
337
|
<option>Option 2</option>
|
|
@@ -266,8 +346,8 @@ export const formRow = (nameString, size) => {
|
|
|
266
346
|
);
|
|
267
347
|
};
|
|
268
348
|
export const sizes = [];
|
|
269
|
-
for (const
|
|
270
|
-
sizes.push(formRow(`FormGaps.${
|
|
349
|
+
for (const formGap in FormGaps) {
|
|
350
|
+
sizes.push(formRow(`FormGaps.${formGap}`, FormGaps[formGap]));
|
|
271
351
|
}
|
|
272
352
|
export const getForms = (list) => <ul style={{ listStyle: "none" }}>{list}</ul>;
|
|
273
353
|
|
|
@@ -280,22 +360,13 @@ variable `--nypl-space-l` (2rem / 32px).
|
|
|
280
360
|
Below are the spacing variants available with the `FormGaps` enum.
|
|
281
361
|
|
|
282
362
|
<Canvas>
|
|
283
|
-
<Story
|
|
284
|
-
name="Spacing Variants"
|
|
285
|
-
args={{
|
|
286
|
-
id: "spacing-form-id",
|
|
287
|
-
}}
|
|
288
|
-
>
|
|
289
|
-
{getForms(sizes)}
|
|
290
|
-
</Story>
|
|
363
|
+
<Story name="Spacing Variants">{getForms(sizes)}</Story>
|
|
291
364
|
</Canvas>
|
|
292
365
|
|
|
293
366
|
## Example Code
|
|
294
367
|
|
|
295
|
-
<Story name="Example Code" />
|
|
296
|
-
|
|
297
368
|
```jsx
|
|
298
|
-
<Form action="/end/point" method="get" gap={FormGaps.Large}>
|
|
369
|
+
<Form action="/end/point" method="get" gap={FormGaps.Large} id="example-form">
|
|
299
370
|
<FormField>
|
|
300
371
|
<TextInput
|
|
301
372
|
labelText="Username"
|
|
@@ -9,13 +9,13 @@ import TextInput from "../TextInput/TextInput";
|
|
|
9
9
|
|
|
10
10
|
describe("Form Accessibility", () => {
|
|
11
11
|
it("passes axe accessibility test", async () => {
|
|
12
|
-
const { container } = render(<Form />);
|
|
12
|
+
const { container } = render(<Form id="form" />);
|
|
13
13
|
expect(await axe(container)).toHaveNoViolations();
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
it("passes axe accessibility test for the full hierachy", async () => {
|
|
17
17
|
const { container } = render(
|
|
18
|
-
<Form>
|
|
18
|
+
<Form id="form">
|
|
19
19
|
<FormRow>
|
|
20
20
|
<FormField>Form Field 1</FormField>
|
|
21
21
|
<FormField>Form Field 2</FormField>
|
|
@@ -40,19 +40,44 @@ describe("Form Snapshot", () => {
|
|
|
40
40
|
</Form>
|
|
41
41
|
)
|
|
42
42
|
.toJSON();
|
|
43
|
+
const withChakraProps = renderer
|
|
44
|
+
.create(
|
|
45
|
+
<Form id="chakra" p="20px" color="ui.error.primary">
|
|
46
|
+
<FormRow>
|
|
47
|
+
<FormField>Form Field 1</FormField>
|
|
48
|
+
<FormField>Form Field 2</FormField>
|
|
49
|
+
<FormField>Form Field 3</FormField>
|
|
50
|
+
</FormRow>
|
|
51
|
+
</Form>
|
|
52
|
+
)
|
|
53
|
+
.toJSON();
|
|
54
|
+
const withOtherProps = renderer
|
|
55
|
+
.create(
|
|
56
|
+
<Form id="props" data-testid="props">
|
|
57
|
+
<FormRow>
|
|
58
|
+
<FormField>Form Field 1</FormField>
|
|
59
|
+
<FormField>Form Field 2</FormField>
|
|
60
|
+
<FormField>Form Field 3</FormField>
|
|
61
|
+
</FormRow>
|
|
62
|
+
</Form>
|
|
63
|
+
)
|
|
64
|
+
.toJSON();
|
|
65
|
+
|
|
43
66
|
expect(tree).toMatchSnapshot();
|
|
67
|
+
expect(withChakraProps).toMatchSnapshot();
|
|
68
|
+
expect(withOtherProps).toMatchSnapshot();
|
|
44
69
|
});
|
|
45
70
|
});
|
|
46
71
|
|
|
47
72
|
describe("Form", () => {
|
|
48
73
|
it("Renders a <form> element", () => {
|
|
49
|
-
render(<Form />);
|
|
74
|
+
render(<Form id="form" />);
|
|
50
75
|
expect(screen.getByRole("form")).toBeInTheDocument();
|
|
51
76
|
});
|
|
52
77
|
|
|
53
78
|
it("Renders a <form> element with child FormRow element", () => {
|
|
54
79
|
render(
|
|
55
|
-
<Form>
|
|
80
|
+
<Form id="form">
|
|
56
81
|
<FormRow />
|
|
57
82
|
</Form>
|
|
58
83
|
);
|
|
@@ -67,7 +92,7 @@ describe("Form", () => {
|
|
|
67
92
|
|
|
68
93
|
it("Renders a <form> element with child FormField element", () => {
|
|
69
94
|
render(
|
|
70
|
-
<Form>
|
|
95
|
+
<Form id="form">
|
|
71
96
|
<FormField />
|
|
72
97
|
</Form>
|
|
73
98
|
);
|
|
@@ -82,10 +107,10 @@ describe("Form", () => {
|
|
|
82
107
|
|
|
83
108
|
it("Renders a <form> element with FormRow, FormField and input elements properly nested", () => {
|
|
84
109
|
render(
|
|
85
|
-
<Form>
|
|
110
|
+
<Form id="form">
|
|
86
111
|
<FormRow>
|
|
87
112
|
<FormField>
|
|
88
|
-
<TextInput labelText="Input Field" />
|
|
113
|
+
<TextInput id="textInput" labelText="Input Field" />
|
|
89
114
|
</FormField>
|
|
90
115
|
</FormRow>
|
|
91
116
|
</Form>
|
|
@@ -107,7 +132,7 @@ describe("Form", () => {
|
|
|
107
132
|
});
|
|
108
133
|
|
|
109
134
|
it("Renders a <form> element with custom `action` and `method` attributes", () => {
|
|
110
|
-
render(<Form action="/end/point" method="get" />);
|
|
135
|
+
render(<Form id="form" action="/end/point" method="get" />);
|
|
111
136
|
const form = screen.getByRole("form");
|
|
112
137
|
expect(form).toBeInTheDocument();
|
|
113
138
|
expect(form).toHaveAttribute("action", "/end/point");
|
|
@@ -119,18 +144,18 @@ describe("Form", () => {
|
|
|
119
144
|
<Form id="formId">
|
|
120
145
|
<FormRow>
|
|
121
146
|
<FormField>
|
|
122
|
-
<TextInput labelText="Input Field" />
|
|
147
|
+
<TextInput id="textInput" labelText="Input Field" />
|
|
123
148
|
</FormField>
|
|
124
149
|
<FormField>
|
|
125
|
-
<TextInput labelText="Input Field" />
|
|
150
|
+
<TextInput id="textInput" labelText="Input Field" />
|
|
126
151
|
</FormField>
|
|
127
152
|
</FormRow>
|
|
128
153
|
<FormRow>
|
|
129
154
|
<FormField>
|
|
130
|
-
<TextInput labelText="Input Field" />
|
|
155
|
+
<TextInput id="textInput" labelText="Input Field" />
|
|
131
156
|
</FormField>
|
|
132
157
|
<FormField>
|
|
133
|
-
<TextInput labelText="Input Field" />
|
|
158
|
+
<TextInput id="textInput" labelText="Input Field" />
|
|
134
159
|
</FormField>
|
|
135
160
|
</FormRow>
|
|
136
161
|
</Form>
|
|
@@ -162,24 +187,24 @@ describe("Form", () => {
|
|
|
162
187
|
it("logs a warning if a child of `FormRow` is not a `FormField`", () => {
|
|
163
188
|
const warn = jest.spyOn(console, "warn");
|
|
164
189
|
render(
|
|
165
|
-
<Form>
|
|
190
|
+
<Form id="form">
|
|
166
191
|
<FormRow>
|
|
167
192
|
<div>Not a FormField</div>
|
|
168
193
|
</FormRow>
|
|
169
194
|
</Form>
|
|
170
195
|
);
|
|
171
196
|
expect(warn).toHaveBeenCalledWith(
|
|
172
|
-
"FormRow
|
|
197
|
+
"NYPL Reservoir FormRow: Children must be `FormField` components."
|
|
173
198
|
);
|
|
174
199
|
});
|
|
175
200
|
|
|
176
201
|
it("calls the onSubmit function", () => {
|
|
177
202
|
const onSubmit = jest.fn();
|
|
178
203
|
render(
|
|
179
|
-
<Form onSubmit={onSubmit}>
|
|
204
|
+
<Form id="form" onSubmit={onSubmit}>
|
|
180
205
|
<FormRow>
|
|
181
206
|
<FormField>
|
|
182
|
-
<TextInput labelText="Input Field" />
|
|
207
|
+
<TextInput id="textInput" labelText="Input Field" />
|
|
183
208
|
</FormField>
|
|
184
209
|
</FormRow>
|
|
185
210
|
</Form>
|
|
@@ -190,6 +215,24 @@ describe("Form", () => {
|
|
|
190
215
|
expect(onSubmit).toHaveBeenCalledTimes(1);
|
|
191
216
|
});
|
|
192
217
|
|
|
218
|
+
it("Logs a warning when there is no `id` passed", () => {
|
|
219
|
+
const warn = jest.spyOn(console, "warn");
|
|
220
|
+
render(
|
|
221
|
+
// @ts-ignore: Typescript complains when a required prop is not passed, but
|
|
222
|
+
// here we don't want to pass the required prop to make sure the warning appears.
|
|
223
|
+
<Form>
|
|
224
|
+
<FormRow>
|
|
225
|
+
<FormField>
|
|
226
|
+
<TextInput id="textInput" labelText="Input Field" />
|
|
227
|
+
</FormField>
|
|
228
|
+
</FormRow>
|
|
229
|
+
</Form>
|
|
230
|
+
);
|
|
231
|
+
expect(warn).toHaveBeenCalledWith(
|
|
232
|
+
"NYPL Reservoir Form: This component's required `id` prop was not passed."
|
|
233
|
+
);
|
|
234
|
+
});
|
|
235
|
+
|
|
193
236
|
// TO DO: There's somethign weird about checking for the "grid-gap" style.
|
|
194
237
|
// Other styles can be validated, but "grid-gap" is being ellusive.
|
|
195
238
|
// it("Renders a <form> element with spacing variant applied", () => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { chakra } from "@chakra-ui/react";
|
|
1
2
|
import * as React from "react";
|
|
2
3
|
|
|
3
4
|
import { FormGaps } from "./FormTypes";
|
|
4
5
|
import SimpleGrid from "../Grid/SimpleGrid";
|
|
5
|
-
import generateUUID from "../../helpers/generateUUID";
|
|
6
6
|
|
|
7
7
|
interface FormBaseProps {
|
|
8
8
|
/** className to be applied to FormRow, FormField, and Form */
|
|
@@ -12,10 +12,10 @@ interface FormBaseProps {
|
|
|
12
12
|
* should not be used``` */
|
|
13
13
|
gap?: FormGaps;
|
|
14
14
|
/** ID that other components can cross reference (internal use) */
|
|
15
|
-
id
|
|
15
|
+
id: string;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export interface FormChildProps extends FormBaseProps {}
|
|
18
|
+
export interface FormChildProps extends Partial<FormBaseProps> {}
|
|
19
19
|
|
|
20
20
|
export interface FormProps extends FormBaseProps {
|
|
21
21
|
/** Optional form `action` attribute */
|
|
@@ -27,74 +27,98 @@ export interface FormProps extends FormBaseProps {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/** FormRow child-component */
|
|
30
|
-
export
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
export const FormRow = chakra(
|
|
31
|
+
(props: React.PropsWithChildren<FormChildProps>) => {
|
|
32
|
+
const { children, className, gap, id, ...rest } = props;
|
|
33
|
+
const count = React.Children.count(children);
|
|
34
|
+
const alteredChildren = React.Children.map(
|
|
35
|
+
children,
|
|
36
|
+
(child: React.ReactElement, i) => {
|
|
37
|
+
if (!child) return null;
|
|
38
|
+
if (child.type === FormField || child.props.mdxType === "FormField") {
|
|
39
|
+
return React.cloneElement(child, { id: `${id}-grandchild${i}` });
|
|
40
|
+
}
|
|
41
|
+
console.warn(
|
|
42
|
+
"NYPL Reservoir FormRow: Children must be `FormField` components."
|
|
43
|
+
);
|
|
44
|
+
return null;
|
|
39
45
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
46
|
+
);
|
|
47
|
+
return (
|
|
48
|
+
<SimpleGrid
|
|
49
|
+
columns={count}
|
|
50
|
+
className={className}
|
|
51
|
+
gap={gap}
|
|
52
|
+
id={id}
|
|
53
|
+
{...rest}
|
|
54
|
+
>
|
|
55
|
+
{alteredChildren}
|
|
56
|
+
</SimpleGrid>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
);
|
|
50
60
|
|
|
51
61
|
/** FormField child-component */
|
|
52
|
-
export
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
{
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
export const FormField = chakra(
|
|
63
|
+
(props: React.PropsWithChildren<FormChildProps>) => {
|
|
64
|
+
const { children, className, gap, id, ...rest } = props;
|
|
65
|
+
return (
|
|
66
|
+
<SimpleGrid columns={1} className={className} gap={gap} id={id} {...rest}>
|
|
67
|
+
{children}
|
|
68
|
+
</SimpleGrid>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
);
|
|
60
72
|
|
|
61
73
|
/** Main Form component */
|
|
62
|
-
export
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
export const Form = chakra(
|
|
75
|
+
(props: React.PropsWithChildren<FormProps>) => {
|
|
76
|
+
const {
|
|
77
|
+
action,
|
|
78
|
+
children,
|
|
79
|
+
className,
|
|
80
|
+
gap = FormGaps.Large,
|
|
81
|
+
id,
|
|
82
|
+
method,
|
|
83
|
+
onSubmit,
|
|
84
|
+
...rest
|
|
85
|
+
} = props;
|
|
72
86
|
|
|
73
|
-
|
|
74
|
-
|
|
87
|
+
if (!id) {
|
|
88
|
+
console.warn(
|
|
89
|
+
"NYPL Reservoir Form: This component's required `id` prop was not passed."
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
let attributes = {};
|
|
93
|
+
action && (attributes["action"] = action);
|
|
75
94
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
95
|
+
method &&
|
|
96
|
+
(method === "get" || method === "post") &&
|
|
97
|
+
(attributes["method"] = method);
|
|
79
98
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
99
|
+
const alteredChildren = React.Children.map(
|
|
100
|
+
children,
|
|
101
|
+
(child: React.ReactElement, i) => {
|
|
102
|
+
return React.cloneElement(child, { gap, id: `${id}-child${i}` });
|
|
103
|
+
}
|
|
104
|
+
);
|
|
86
105
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
{
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
106
|
+
return (
|
|
107
|
+
<form
|
|
108
|
+
aria-label="form"
|
|
109
|
+
className={className}
|
|
110
|
+
id={id}
|
|
111
|
+
onSubmit={onSubmit}
|
|
112
|
+
{...attributes}
|
|
113
|
+
{...rest}
|
|
114
|
+
>
|
|
115
|
+
<SimpleGrid columns={1} gap={gap} id={`${id}-parent`}>
|
|
116
|
+
{alteredChildren}
|
|
117
|
+
</SimpleGrid>
|
|
118
|
+
</form>
|
|
119
|
+
);
|
|
120
|
+
},
|
|
121
|
+
{ shouldForwardProp: () => true }
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
export default Form;
|