@nypl/design-system-react-components 0.25.13 → 0.27.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/CHANGELOG.md +85 -0
- package/README.md +10 -10
- package/dist/components/Accordion/Accordion.d.ts +1 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +1 -1
- package/dist/components/Button/Button.d.ts +2 -2
- package/dist/components/Card/Card.d.ts +11 -9
- package/dist/components/Checkbox/Checkbox.d.ts +2 -2
- package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +5 -4
- 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 +1 -1
- package/dist/components/HelperErrorText/HelperErrorText.d.ts +9 -8
- package/dist/components/Hero/Hero.d.ts +2 -1
- package/dist/components/HorizontalRule/HorizontalRule.d.ts +2 -10
- package/dist/components/Icons/Icon.d.ts +2 -1
- package/dist/components/Image/Image.d.ts +2 -2
- 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 +2 -0
- package/dist/components/Modal/Modal.d.ts +28 -8
- package/dist/components/Notification/Notification.d.ts +4 -4
- 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 +4 -6
- package/dist/components/RadioGroup/RadioGroup.d.ts +12 -6
- package/dist/components/SearchBar/SearchBar.d.ts +4 -4
- package/dist/components/Select/Select.d.ts +10 -6
- package/dist/components/Select/SelectTypes.d.ts +4 -0
- package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +4 -3
- 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 +2 -2
- package/dist/components/Table/Table.d.ts +1 -1
- package/dist/components/Tabs/Tabs.d.ts +4 -3
- package/dist/components/Template/Template.d.ts +4 -3
- package/dist/components/Text/Text.d.ts +1 -1
- package/dist/components/TextInput/TextInput.d.ts +5 -5
- package/dist/components/Toggle/Toggle.d.ts +3 -4
- package/dist/components/VideoPlayer/VideoPlayer.d.ts +2 -1
- package/dist/design-system-react-components.cjs.development.js +1767 -1180
- 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 +1774 -1188
- package/dist/design-system-react-components.esm.js.map +1 -1
- package/dist/hooks/useCarouselStyles.d.ts +3 -2
- package/dist/hooks/useNYPLTheme.d.ts +12 -0
- package/dist/index.d.ts +5 -2
- package/dist/styles.css +1 -1
- package/dist/theme/components/button.d.ts +10 -2
- package/dist/theme/components/card.d.ts +42 -22
- package/dist/theme/components/checkbox.d.ts +5 -4
- package/dist/theme/components/checkboxGroup.d.ts +1 -1
- 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 +23 -17
- 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 +20 -14
- package/dist/theme/components/label.d.ts +9 -10
- package/dist/theme/components/list.d.ts +99 -9
- package/dist/theme/components/radio.d.ts +6 -4
- package/dist/theme/components/radioGroup.d.ts +1 -1
- package/dist/theme/components/select.d.ts +28 -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 +7 -4
- 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 +17 -19
- package/src/components/Accordion/Accordion.stories.mdx +9 -9
- package/src/components/Accordion/Accordion.test.tsx +21 -0
- package/src/components/Accordion/Accordion.tsx +13 -9
- package/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap +276 -27
- package/src/components/Autosuggest/Autosuggest.stories.mdx +4 -3
- package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +21 -5
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +52 -31
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +8 -7
- 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 +287 -194
- package/src/components/Card/Card.test.tsx +102 -0
- package/src/components/Card/Card.tsx +73 -32
- package/src/components/Card/__snapshots__/Card.test.tsx.snap +196 -36
- package/src/components/Chakra/Grid.stories.mdx +4 -4
- package/src/components/Checkbox/Checkbox.stories.mdx +62 -10
- package/src/components/Checkbox/Checkbox.test.tsx +32 -9
- package/src/components/Checkbox/Checkbox.tsx +20 -15
- package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +134 -7
- package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +65 -17
- package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +137 -81
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +31 -21
- package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +332 -97
- 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 +89 -13
- package/src/components/DatePicker/DatePicker.tsx +62 -56
- 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 +72 -39
- package/src/components/Form/Form.test.tsx +58 -15
- package/src/components/Form/Form.tsx +89 -67
- 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 +34 -6
- package/src/components/Grid/SimpleGrid.test.tsx +9 -0
- 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 +36 -3
- package/src/components/Heading/Heading.test.tsx +10 -0
- package/src/components/Heading/Heading.tsx +56 -50
- package/src/components/Heading/__snapshots__/Heading.test.tsx.snap +26 -7
- 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 +125 -95
- package/src/components/Hero/Hero.test.tsx +33 -0
- package/src/components/Hero/Hero.tsx +135 -126
- 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 -19
- package/src/components/HorizontalRule/HorizontalRule.tsx +9 -26
- package/src/components/HorizontalRule/__snapshots__/HorizontalRule.test.tsx.snap +18 -5
- package/src/components/Icons/Icon.stories.mdx +31 -6
- package/src/components/Icons/Icon.test.tsx +38 -0
- package/src/components/Icons/Icon.tsx +93 -76
- package/src/components/Icons/__snapshots__/Icon.test.tsx.snap +129 -0
- package/src/components/Image/Image.stories.mdx +29 -5
- package/src/components/Image/Image.test.tsx +8 -0
- package/src/components/Image/Image.tsx +38 -26
- package/src/components/Image/__snapshots__/Image.test.tsx.snap +24 -8
- 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 -15
- package/src/components/Link/Link.test.tsx +21 -22
- package/src/components/Link/Link.tsx +8 -8
- 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 +67 -19
- package/src/components/List/List.tsx +38 -25
- 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 +30 -6
- package/src/components/Logo/Logo.test.tsx +17 -0
- package/src/components/Logo/Logo.tsx +18 -6
- package/src/components/Logo/LogoSvgs.tsx +4 -0
- package/src/components/Logo/LogoTypes.tsx +2 -0
- package/src/components/Logo/__snapshots__/Logo.test.tsx.snap +73 -2
- package/src/components/Modal/Modal.stories.mdx +256 -136
- package/src/components/Modal/Modal.test.tsx +151 -9
- package/src/components/Modal/Modal.tsx +140 -20
- package/src/components/Modal/__snapshots__/Modal.test.tsx.snap +25 -0
- package/src/components/Notification/Notification.stories.mdx +25 -1
- package/src/components/Notification/Notification.test.tsx +23 -0
- package/src/components/Notification/Notification.tsx +46 -44
- package/src/components/Notification/__snapshots__/Notification.test.tsx.snap +158 -29
- package/src/components/Pagination/Pagination.stories.mdx +25 -6
- package/src/components/Pagination/Pagination.test.tsx +25 -0
- package/src/components/Pagination/Pagination.tsx +6 -6
- 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 +81 -11
- package/src/components/ProgressIndicator/ProgressIndicator.tsx +17 -9
- package/src/components/ProgressIndicator/__snapshots__/ProgressIndicator.test.tsx.snap +101 -14
- package/src/components/Radio/Radio.stories.mdx +64 -12
- package/src/components/Radio/Radio.test.tsx +28 -8
- package/src/components/Radio/Radio.tsx +66 -63
- package/src/components/Radio/__snapshots__/Radio.test.tsx.snap +103 -6
- package/src/components/RadioGroup/RadioGroup.stories.mdx +224 -89
- package/src/components/RadioGroup/RadioGroup.test.tsx +122 -62
- package/src/components/RadioGroup/RadioGroup.tsx +106 -100
- package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +1236 -1020
- 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 +17 -8
- package/src/components/SearchBar/__snapshots__/SearchBar.test.tsx.snap +1039 -0
- package/src/components/Select/Select.stories.mdx +128 -49
- package/src/components/Select/Select.test.tsx +63 -16
- package/src/components/Select/Select.tsx +131 -92
- package/src/components/Select/SelectTypes.tsx +5 -0
- package/src/components/Select/__snapshots__/Select.test.tsx.snap +765 -425
- package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +42 -10
- package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +8 -0
- package/src/components/SkeletonLoader/SkeletonLoader.tsx +76 -72
- package/src/components/SkeletonLoader/__snapshots__/SkeletonLoader.test.tsx.snap +169 -10
- package/src/components/Slider/Slider.stories.mdx +91 -42
- package/src/components/Slider/Slider.test.tsx +65 -17
- package/src/components/Slider/Slider.tsx +26 -19
- 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 +16 -0
- 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 +131 -12
- package/src/components/StructuredContent/StructuredContent.test.tsx +34 -0
- package/src/components/StructuredContent/StructuredContent.tsx +80 -75
- 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 +1 -1
- 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 +30 -21
- package/src/components/Table/Table.stories.mdx +38 -11
- package/src/components/Table/Table.test.tsx +15 -0
- package/src/components/Table/Table.tsx +7 -7
- package/src/components/Table/__snapshots__/Table.test.tsx.snap +408 -5
- package/src/components/Tabs/Tabs.stories.mdx +52 -3
- package/src/components/Tabs/Tabs.test.tsx +16 -0
- package/src/components/Tabs/Tabs.tsx +10 -6
- package/src/components/Tabs/__snapshots__/Tabs.test.tsx.snap +394 -5
- package/src/components/Template/Template.stories.mdx +47 -43
- package/src/components/Template/Template.test.tsx +33 -0
- package/src/components/Template/Template.tsx +65 -60
- package/src/components/Template/__snapshots__/Template.test.tsx.snap +191 -20
- package/src/components/Text/Text.stories.mdx +20 -1
- package/src/components/Text/Text.test.tsx +12 -0
- package/src/components/Text/Text.tsx +6 -4
- package/src/components/Text/__snapshots__/Text.test.tsx.snap +21 -4
- package/src/components/TextInput/TextInput.stories.mdx +65 -19
- package/src/components/TextInput/TextInput.test.tsx +42 -28
- package/src/components/TextInput/TextInput.tsx +121 -113
- package/src/components/TextInput/__snapshots__/TextInput.test.tsx.snap +96 -73
- package/src/components/Toggle/Toggle.stories.mdx +80 -22
- package/src/components/Toggle/Toggle.test.tsx +27 -9
- package/src/components/Toggle/Toggle.tsx +22 -18
- package/src/components/Toggle/__snapshots__/Toggle.test.tsx.snap +128 -5
- package/src/components/VideoPlayer/VideoPlayer.stories.mdx +52 -4
- package/src/components/VideoPlayer/VideoPlayer.test.tsx +23 -0
- package/src/components/VideoPlayer/VideoPlayer.tsx +133 -126
- 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 +160 -41
- package/src/hooks/useCarouselStyles.stories.mdx +22 -2
- package/src/hooks/useCarouselStyles.ts +3 -2
- package/src/hooks/useNYPLTheme.stories.mdx +101 -0
- package/src/hooks/useNYPLTheme.ts +30 -6
- package/src/hooks/useWindowSize.stories.mdx +23 -0
- package/src/index.ts +5 -2
- package/src/styles/base/_place-holder.scss +1 -1
- package/src/styles.scss +0 -1
- package/src/theme/components/button.ts +15 -7
- package/src/theme/components/card.ts +30 -19
- package/src/theme/components/checkbox.ts +10 -8
- package/src/theme/components/checkboxGroup.ts +1 -1
- 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 +25 -20
- package/src/theme/components/heading.ts +1 -1
- package/src/theme/components/helperErrorText.ts +1 -0
- package/src/theme/components/hero.ts +13 -15
- package/src/theme/components/label.ts +4 -3
- package/src/theme/components/list.ts +73 -66
- package/src/theme/components/notification.ts +2 -2
- package/src/theme/components/radio.ts +9 -9
- package/src/theme/components/radioGroup.ts +1 -1
- package/src/theme/components/select.ts +31 -22
- 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 +17 -10
- 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 +1 -2
- package/dist/components/SearchBar/SearchBar.Test.d.ts +0 -1
- package/dist/helpers/generateUUID.d.ts +0 -1
- package/src/components/Modal/_Modal.scss +0 -18
- package/src/helpers/generateUUID.tsx +0 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Flex, Spacer } from "@chakra-ui/react";
|
|
1
|
+
import { ButtonGroup, Flex, Spacer } from "@chakra-ui/react";
|
|
2
2
|
import { action } from "@storybook/addon-actions";
|
|
3
3
|
import {
|
|
4
4
|
ArgsTable,
|
|
@@ -61,7 +61,17 @@ export const enumValues = getStorybookEnumValues(FormGaps, "FormGaps");
|
|
|
61
61
|
| Component Version | DS Version |
|
|
62
62
|
| ----------------- | ---------- |
|
|
63
63
|
| Added | `0.23.2` |
|
|
64
|
-
| 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
|
|
65
75
|
|
|
66
76
|
<Description of={Form} />
|
|
67
77
|
|
|
@@ -71,7 +81,7 @@ components should be used to build the `<form>` structure and to arrange input
|
|
|
71
81
|
fields as needed.
|
|
72
82
|
|
|
73
83
|
```jsx
|
|
74
|
-
<Form>
|
|
84
|
+
<Form id="form-id">
|
|
75
85
|
<FormRow>
|
|
76
86
|
<FormField>{/* ... */}</FormField>
|
|
77
87
|
</FormRow>
|
|
@@ -81,11 +91,13 @@ fields as needed.
|
|
|
81
91
|
</Form>
|
|
82
92
|
```
|
|
83
93
|
|
|
84
|
-
`FormField` should be used as a parent for all input components from the
|
|
85
|
-
(`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.).
|
|
86
96
|
|
|
87
|
-
`FormRow` should be used as a parent of multiple `FormField` components when
|
|
88
|
-
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
|
|
89
101
|
|
|
90
102
|
<Canvas withToolbar>
|
|
91
103
|
<Story
|
|
@@ -99,30 +111,32 @@ need to render multiple input components in a horizontal row.
|
|
|
99
111
|
}}
|
|
100
112
|
>
|
|
101
113
|
{(args) => (
|
|
102
|
-
<Form {...args} gap={enumValues.getValue(args.gap)}>
|
|
114
|
+
<Form {...args} gap={enumValues.getValue(args.gap)} id="form-id">
|
|
103
115
|
<FormRow>
|
|
104
116
|
<FormField>
|
|
105
117
|
<TextInput
|
|
106
|
-
labelText="First Name"
|
|
107
118
|
helperText="Make sure to complete this field."
|
|
119
|
+
id="first-name"
|
|
108
120
|
isRequired
|
|
121
|
+
labelText="First Name"
|
|
109
122
|
/>
|
|
110
123
|
</FormField>
|
|
111
124
|
<FormField>
|
|
112
125
|
<TextInput
|
|
113
|
-
labelText="Last Name"
|
|
114
126
|
helperText="Make sure to complete this field."
|
|
127
|
+
id="last-name"
|
|
115
128
|
isRequired
|
|
129
|
+
labelText="Last Name"
|
|
116
130
|
/>
|
|
117
131
|
</FormField>
|
|
118
132
|
<FormField>
|
|
119
133
|
<DatePicker
|
|
120
|
-
id="date-range"
|
|
121
134
|
dateType={DatePickerTypes.Full}
|
|
122
135
|
dateFormat="yyyy-MM-dd"
|
|
123
136
|
helperTextFrom="From this date."
|
|
124
137
|
helperTextTo="To this date."
|
|
125
138
|
helperText="Select a valid date range."
|
|
139
|
+
id="date-range"
|
|
126
140
|
invalidText="Please select a valid date range."
|
|
127
141
|
isDateRange
|
|
128
142
|
labelText="Select the date range you want to visit NYPL"
|
|
@@ -135,37 +149,42 @@ need to render multiple input components in a horizontal row.
|
|
|
135
149
|
</FormRow>
|
|
136
150
|
<FormField>
|
|
137
151
|
<TextInput
|
|
138
|
-
labelText="Username"
|
|
139
152
|
helperText="Make sure to complete this field."
|
|
153
|
+
id="username"
|
|
140
154
|
isRequired
|
|
155
|
+
labelText="Username"
|
|
141
156
|
/>
|
|
142
157
|
</FormField>
|
|
143
158
|
<FormField>
|
|
144
159
|
<TextInput
|
|
145
|
-
labelText="Password"
|
|
146
160
|
helperText="Make sure to complete this field."
|
|
161
|
+
id="password"
|
|
147
162
|
isRequired
|
|
163
|
+
labelText="Password"
|
|
148
164
|
/>
|
|
149
165
|
</FormField>
|
|
150
166
|
<FormRow>
|
|
151
167
|
<FormField>
|
|
152
168
|
<TextInput
|
|
153
|
-
labelText="Phone Field"
|
|
154
169
|
helperText="This one is up to you."
|
|
170
|
+
id="phone"
|
|
171
|
+
labelText="Phone Field"
|
|
155
172
|
type="tel"
|
|
156
173
|
/>
|
|
157
174
|
</FormField>
|
|
158
175
|
<FormField>
|
|
159
176
|
<TextInput
|
|
160
|
-
labelText="URL Field"
|
|
161
177
|
helperText="This one is up to you."
|
|
178
|
+
id="url"
|
|
179
|
+
labelText="URL Field"
|
|
162
180
|
type="url"
|
|
163
181
|
/>
|
|
164
182
|
</FormField>
|
|
165
183
|
<FormField>
|
|
166
184
|
<TextInput
|
|
167
|
-
labelText="Age"
|
|
168
185
|
helperText="This one is up to you."
|
|
186
|
+
id="age"
|
|
187
|
+
labelText="Age"
|
|
169
188
|
type="number"
|
|
170
189
|
/>
|
|
171
190
|
</FormField>
|
|
@@ -173,12 +192,13 @@ need to render multiple input components in a horizontal row.
|
|
|
173
192
|
<FormRow>
|
|
174
193
|
<FormField>
|
|
175
194
|
<CheckboxGroup
|
|
195
|
+
id="checkbox-group"
|
|
176
196
|
isFullWidth
|
|
177
197
|
labelText="Checkbox Group"
|
|
178
198
|
name="checkbox-example"
|
|
179
|
-
optReqFlag={false}
|
|
180
199
|
>
|
|
181
200
|
<Checkbox
|
|
201
|
+
id="arts"
|
|
182
202
|
labelText={
|
|
183
203
|
<Flex>
|
|
184
204
|
<span>Arts</span>
|
|
@@ -189,6 +209,7 @@ need to render multiple input components in a horizontal row.
|
|
|
189
209
|
value="arts"
|
|
190
210
|
/>
|
|
191
211
|
<Checkbox
|
|
212
|
+
id="english"
|
|
192
213
|
labelText={
|
|
193
214
|
<Flex>
|
|
194
215
|
<span>English</span>
|
|
@@ -199,6 +220,7 @@ need to render multiple input components in a horizontal row.
|
|
|
199
220
|
value="English"
|
|
200
221
|
/>
|
|
201
222
|
<Checkbox
|
|
223
|
+
id="science"
|
|
202
224
|
labelText={
|
|
203
225
|
<Flex>
|
|
204
226
|
<span>Science</span>
|
|
@@ -209,6 +231,7 @@ need to render multiple input components in a horizontal row.
|
|
|
209
231
|
value="Science"
|
|
210
232
|
/>
|
|
211
233
|
<Checkbox
|
|
234
|
+
id="math"
|
|
212
235
|
labelText={
|
|
213
236
|
<Flex>
|
|
214
237
|
<span>Math</span>
|
|
@@ -221,16 +244,17 @@ need to render multiple input components in a horizontal row.
|
|
|
221
244
|
</CheckboxGroup>
|
|
222
245
|
</FormField>
|
|
223
246
|
<FormField>
|
|
224
|
-
<RadioGroup labelText="Radio Group" name="rg1"
|
|
225
|
-
<Radio labelText="Radio 1"
|
|
226
|
-
<Radio labelText="Radio 2"
|
|
227
|
-
<Radio labelText="Radio 3"
|
|
228
|
-
<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" />
|
|
229
252
|
</RadioGroup>
|
|
230
253
|
</FormField>
|
|
231
254
|
<FormField>
|
|
232
255
|
<Select
|
|
233
256
|
helperText="The select field helper text."
|
|
257
|
+
id="select"
|
|
234
258
|
labelText="Select Field"
|
|
235
259
|
showLabel={true}
|
|
236
260
|
>
|
|
@@ -242,9 +266,13 @@ need to render multiple input components in a horizontal row.
|
|
|
242
266
|
</Select>
|
|
243
267
|
</FormField>
|
|
244
268
|
</FormRow>
|
|
245
|
-
<
|
|
246
|
-
<
|
|
247
|
-
|
|
269
|
+
<FormRow>
|
|
270
|
+
<FormField>
|
|
271
|
+
<ButtonGroup>
|
|
272
|
+
<Button id="submit">Submit</Button>
|
|
273
|
+
</ButtonGroup>
|
|
274
|
+
</FormField>
|
|
275
|
+
</FormRow>
|
|
248
276
|
</Form>
|
|
249
277
|
)}
|
|
250
278
|
</Story>
|
|
@@ -252,6 +280,17 @@ need to render multiple input components in a horizontal row.
|
|
|
252
280
|
|
|
253
281
|
<ArgsTable story="Form with Controls" />
|
|
254
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
|
+
|
|
255
294
|
## Spacing Variants
|
|
256
295
|
|
|
257
296
|
export const formRow = (nameString, size) => {
|
|
@@ -259,11 +298,12 @@ export const formRow = (nameString, size) => {
|
|
|
259
298
|
return (
|
|
260
299
|
<li key={size}>
|
|
261
300
|
<Heading level={HeadingLevels.Three}>{labelText}</Heading>
|
|
262
|
-
<Form gap={size}>
|
|
301
|
+
<Form gap={size} id={`form-spacing-${size}`}>
|
|
263
302
|
<FormRow>
|
|
264
303
|
<FormField>
|
|
265
304
|
<Select
|
|
266
305
|
helperText="The select field helper text."
|
|
306
|
+
id={`select-spacing-${size}-1`}
|
|
267
307
|
labelText="Select Field"
|
|
268
308
|
showLabel={true}
|
|
269
309
|
>
|
|
@@ -276,6 +316,7 @@ export const formRow = (nameString, size) => {
|
|
|
276
316
|
<FormField>
|
|
277
317
|
<Select
|
|
278
318
|
helperText="The select field helper text."
|
|
319
|
+
id={`select-spacing-${size}-2`}
|
|
279
320
|
labelText="Select Field"
|
|
280
321
|
showLabel={true}
|
|
281
322
|
>
|
|
@@ -288,6 +329,7 @@ export const formRow = (nameString, size) => {
|
|
|
288
329
|
<FormField>
|
|
289
330
|
<Select
|
|
290
331
|
helperText="The select field helper text."
|
|
332
|
+
id={`select-spacing-${size}-3`}
|
|
291
333
|
labelText="Select Field"
|
|
292
334
|
showLabel={true}
|
|
293
335
|
>
|
|
@@ -304,8 +346,8 @@ export const formRow = (nameString, size) => {
|
|
|
304
346
|
);
|
|
305
347
|
};
|
|
306
348
|
export const sizes = [];
|
|
307
|
-
for (const
|
|
308
|
-
sizes.push(formRow(`FormGaps.${
|
|
349
|
+
for (const formGap in FormGaps) {
|
|
350
|
+
sizes.push(formRow(`FormGaps.${formGap}`, FormGaps[formGap]));
|
|
309
351
|
}
|
|
310
352
|
export const getForms = (list) => <ul style={{ listStyle: "none" }}>{list}</ul>;
|
|
311
353
|
|
|
@@ -318,22 +360,13 @@ variable `--nypl-space-l` (2rem / 32px).
|
|
|
318
360
|
Below are the spacing variants available with the `FormGaps` enum.
|
|
319
361
|
|
|
320
362
|
<Canvas>
|
|
321
|
-
<Story
|
|
322
|
-
name="Spacing Variants"
|
|
323
|
-
args={{
|
|
324
|
-
id: "spacing-form-id",
|
|
325
|
-
}}
|
|
326
|
-
>
|
|
327
|
-
{getForms(sizes)}
|
|
328
|
-
</Story>
|
|
363
|
+
<Story name="Spacing Variants">{getForms(sizes)}</Story>
|
|
329
364
|
</Canvas>
|
|
330
365
|
|
|
331
366
|
## Example Code
|
|
332
367
|
|
|
333
|
-
<Story name="Example Code" />
|
|
334
|
-
|
|
335
368
|
```jsx
|
|
336
|
-
<Form action="/end/point" method="get" gap={FormGaps.Large}>
|
|
369
|
+
<Form action="/end/point" method="get" gap={FormGaps.Large} id="example-form">
|
|
337
370
|
<FormField>
|
|
338
371
|
<TextInput
|
|
339
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,7 +187,7 @@ 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>
|
|
@@ -176,10 +201,10 @@ describe("Form", () => {
|
|
|
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,76 +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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
+
);
|
|
52
60
|
|
|
53
61
|
/** FormField child-component */
|
|
54
|
-
export
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
{
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
);
|
|
62
72
|
|
|
63
73
|
/** Main Form component */
|
|
64
|
-
export
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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;
|
|
74
86
|
|
|
75
|
-
|
|
76
|
-
|
|
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);
|
|
77
94
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
95
|
+
method &&
|
|
96
|
+
(method === "get" || method === "post") &&
|
|
97
|
+
(attributes["method"] = method);
|
|
81
98
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
+
);
|
|
88
105
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
{
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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;
|