@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.
Files changed (305) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/README.md +10 -10
  3. package/dist/components/Accordion/Accordion.d.ts +1 -1
  4. package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +1 -1
  5. package/dist/components/Button/Button.d.ts +2 -2
  6. package/dist/components/Card/Card.d.ts +11 -9
  7. package/dist/components/Checkbox/Checkbox.d.ts +2 -2
  8. package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +5 -4
  9. package/dist/components/ComponentWrapper/ComponentWrapper.d.ts +1 -1
  10. package/dist/components/DatePicker/DatePicker.d.ts +5 -6
  11. package/dist/components/Fieldset/Fieldset.d.ts +5 -6
  12. package/dist/components/Form/Form.d.ts +6 -6
  13. package/dist/components/Grid/GridTypes.d.ts +7 -7
  14. package/dist/components/Grid/SimpleGrid.d.ts +1 -1
  15. package/dist/components/Heading/Heading.d.ts +1 -1
  16. package/dist/components/HelperErrorText/HelperErrorText.d.ts +9 -8
  17. package/dist/components/Hero/Hero.d.ts +2 -1
  18. package/dist/components/HorizontalRule/HorizontalRule.d.ts +2 -10
  19. package/dist/components/Icons/Icon.d.ts +2 -1
  20. package/dist/components/Image/Image.d.ts +2 -2
  21. package/dist/components/Label/Label.d.ts +7 -4
  22. package/dist/components/Link/Link.d.ts +1 -1
  23. package/dist/components/List/List.d.ts +11 -11
  24. package/dist/components/List/ListTypes.d.ts +1 -1
  25. package/dist/components/Logo/Logo.d.ts +2 -1
  26. package/dist/components/Logo/LogoSvgs.d.ts +2 -0
  27. package/dist/components/Logo/LogoTypes.d.ts +2 -0
  28. package/dist/components/Modal/Modal.d.ts +28 -8
  29. package/dist/components/Notification/Notification.d.ts +4 -4
  30. package/dist/components/Pagination/Pagination.d.ts +2 -2
  31. package/dist/components/ProgressIndicator/ProgressIndicator.d.ts +3 -3
  32. package/dist/components/Radio/Radio.d.ts +4 -6
  33. package/dist/components/RadioGroup/RadioGroup.d.ts +12 -6
  34. package/dist/components/SearchBar/SearchBar.d.ts +4 -4
  35. package/dist/components/Select/Select.d.ts +10 -6
  36. package/dist/components/Select/SelectTypes.d.ts +4 -0
  37. package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +4 -3
  38. package/dist/components/Slider/Slider.d.ts +6 -4
  39. package/dist/components/StatusBadge/StatusBadge.d.ts +5 -1
  40. package/dist/components/StructuredContent/StructuredContent.d.ts +2 -2
  41. package/dist/components/Table/Table.d.ts +1 -1
  42. package/dist/components/Tabs/Tabs.d.ts +4 -3
  43. package/dist/components/Template/Template.d.ts +4 -3
  44. package/dist/components/Text/Text.d.ts +1 -1
  45. package/dist/components/TextInput/TextInput.d.ts +5 -5
  46. package/dist/components/Toggle/Toggle.d.ts +3 -4
  47. package/dist/components/VideoPlayer/VideoPlayer.d.ts +2 -1
  48. package/dist/design-system-react-components.cjs.development.js +1767 -1180
  49. package/dist/design-system-react-components.cjs.development.js.map +1 -1
  50. package/dist/design-system-react-components.cjs.production.min.js +1 -1
  51. package/dist/design-system-react-components.cjs.production.min.js.map +1 -1
  52. package/dist/design-system-react-components.esm.js +1774 -1188
  53. package/dist/design-system-react-components.esm.js.map +1 -1
  54. package/dist/hooks/useCarouselStyles.d.ts +3 -2
  55. package/dist/hooks/useNYPLTheme.d.ts +12 -0
  56. package/dist/index.d.ts +5 -2
  57. package/dist/styles.css +1 -1
  58. package/dist/theme/components/button.d.ts +10 -2
  59. package/dist/theme/components/card.d.ts +42 -22
  60. package/dist/theme/components/checkbox.d.ts +5 -4
  61. package/dist/theme/components/checkboxGroup.d.ts +1 -1
  62. package/dist/theme/components/componentWrapper.d.ts +2 -2
  63. package/dist/theme/components/customTable.d.ts +84 -1
  64. package/dist/theme/components/fieldset.d.ts +4 -14
  65. package/dist/theme/components/global.d.ts +23 -17
  66. package/dist/theme/components/heading.d.ts +53 -0
  67. package/dist/theme/components/helperErrorText.d.ts +1 -0
  68. package/dist/theme/components/hero.d.ts +20 -14
  69. package/dist/theme/components/label.d.ts +9 -10
  70. package/dist/theme/components/list.d.ts +99 -9
  71. package/dist/theme/components/radio.d.ts +6 -4
  72. package/dist/theme/components/radioGroup.d.ts +1 -1
  73. package/dist/theme/components/select.d.ts +28 -5
  74. package/dist/theme/components/skeletonLoader.d.ts +2 -2
  75. package/dist/theme/components/slider.d.ts +6 -3
  76. package/dist/theme/components/structuredContent.d.ts +197 -0
  77. package/dist/theme/components/textInput.d.ts +18 -6
  78. package/dist/theme/components/toggle.d.ts +7 -4
  79. package/dist/theme/foundations/global.d.ts +2 -0
  80. package/dist/theme/foundations/radii.d.ts +1 -0
  81. package/dist/theme/foundations/spacing.d.ts +46 -43
  82. package/package.json +17 -19
  83. package/src/components/Accordion/Accordion.stories.mdx +9 -9
  84. package/src/components/Accordion/Accordion.test.tsx +21 -0
  85. package/src/components/Accordion/Accordion.tsx +13 -9
  86. package/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap +276 -27
  87. package/src/components/Autosuggest/Autosuggest.stories.mdx +4 -3
  88. package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +21 -5
  89. package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +52 -31
  90. package/src/components/Breadcrumbs/Breadcrumbs.tsx +8 -7
  91. package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +211 -12
  92. package/src/components/Button/Button.stories.mdx +87 -23
  93. package/src/components/Button/Button.test.tsx +25 -0
  94. package/src/components/Button/Button.tsx +18 -7
  95. package/src/components/Button/__snapshots__/Button.test.tsx.snap +27 -7
  96. package/src/components/Card/Card.stories.mdx +287 -194
  97. package/src/components/Card/Card.test.tsx +102 -0
  98. package/src/components/Card/Card.tsx +73 -32
  99. package/src/components/Card/__snapshots__/Card.test.tsx.snap +196 -36
  100. package/src/components/Chakra/Grid.stories.mdx +4 -4
  101. package/src/components/Checkbox/Checkbox.stories.mdx +62 -10
  102. package/src/components/Checkbox/Checkbox.test.tsx +32 -9
  103. package/src/components/Checkbox/Checkbox.tsx +20 -15
  104. package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +134 -7
  105. package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +65 -17
  106. package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +137 -81
  107. package/src/components/CheckboxGroup/CheckboxGroup.tsx +31 -21
  108. package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +332 -97
  109. package/src/components/ComponentWrapper/ComponentWrapper.test.tsx +12 -0
  110. package/src/components/ComponentWrapper/ComponentWrapper.tsx +39 -41
  111. package/src/components/ComponentWrapper/__snapshots__/ComponentWrapper.test.tsx.snap +47 -34
  112. package/src/components/DatePicker/DatePicker.stories.mdx +63 -27
  113. package/src/components/DatePicker/DatePicker.test.tsx +89 -13
  114. package/src/components/DatePicker/DatePicker.tsx +62 -56
  115. package/src/components/DatePicker/_DatePicker.scss +71 -13
  116. package/src/components/DatePicker/__snapshots__/DatePicker.test.tsx.snap +250 -206
  117. package/src/components/Fieldset/Fieldset.stories.mdx +33 -3
  118. package/src/components/Fieldset/Fieldset.test.tsx +58 -28
  119. package/src/components/Fieldset/Fieldset.tsx +35 -30
  120. package/src/components/Fieldset/__snapshots__/Fieldset.test.tsx.snap +40 -19
  121. package/src/components/Form/Form.stories.mdx +72 -39
  122. package/src/components/Form/Form.test.tsx +58 -15
  123. package/src/components/Form/Form.tsx +89 -67
  124. package/src/components/Form/__snapshots__/Form.test.tsx.snap +83 -5
  125. package/src/components/Grid/GridTypes.tsx +7 -7
  126. package/src/components/Grid/SimpleGrid.stories.mdx +34 -6
  127. package/src/components/Grid/SimpleGrid.test.tsx +9 -0
  128. package/src/components/Grid/SimpleGrid.tsx +29 -20
  129. package/src/components/Grid/__snapshots__/SimpleGrid.test.tsx.snap +16 -1
  130. package/src/components/Heading/Heading.stories.mdx +36 -3
  131. package/src/components/Heading/Heading.test.tsx +10 -0
  132. package/src/components/Heading/Heading.tsx +56 -50
  133. package/src/components/Heading/__snapshots__/Heading.test.tsx.snap +26 -7
  134. package/src/components/HelperErrorText/HelperErrorText.stories.mdx +64 -42
  135. package/src/components/HelperErrorText/HelperErrorText.test.tsx +15 -0
  136. package/src/components/HelperErrorText/HelperErrorText.tsx +40 -35
  137. package/src/components/HelperErrorText/__snapshots__/HelperErrorText.test.tsx.snap +35 -4
  138. package/src/components/Hero/Hero.stories.mdx +125 -95
  139. package/src/components/Hero/Hero.test.tsx +33 -0
  140. package/src/components/Hero/Hero.tsx +135 -126
  141. package/src/components/Hero/__snapshots__/Hero.test.tsx.snap +89 -17
  142. package/src/components/HorizontalRule/HorizontalRule.stories.mdx +26 -4
  143. package/src/components/HorizontalRule/HorizontalRule.test.tsx +9 -19
  144. package/src/components/HorizontalRule/HorizontalRule.tsx +9 -26
  145. package/src/components/HorizontalRule/__snapshots__/HorizontalRule.test.tsx.snap +18 -5
  146. package/src/components/Icons/Icon.stories.mdx +31 -6
  147. package/src/components/Icons/Icon.test.tsx +38 -0
  148. package/src/components/Icons/Icon.tsx +93 -76
  149. package/src/components/Icons/__snapshots__/Icon.test.tsx.snap +129 -0
  150. package/src/components/Image/Image.stories.mdx +29 -5
  151. package/src/components/Image/Image.test.tsx +8 -0
  152. package/src/components/Image/Image.tsx +38 -26
  153. package/src/components/Image/__snapshots__/Image.test.tsx.snap +24 -8
  154. package/src/components/Label/Label.stories.mdx +42 -20
  155. package/src/components/Label/Label.test.tsx +42 -17
  156. package/src/components/Label/Label.tsx +22 -13
  157. package/src/components/Label/__snapshots__/Label.test.tsx.snap +19 -15
  158. package/src/components/Link/Link.stories.mdx +25 -15
  159. package/src/components/Link/Link.test.tsx +21 -22
  160. package/src/components/Link/Link.tsx +8 -8
  161. package/src/components/Link/__snapshots__/Link.test.tsx.snap +37 -11
  162. package/src/components/List/List.stories.mdx +75 -40
  163. package/src/components/List/List.test.tsx +67 -19
  164. package/src/components/List/List.tsx +38 -25
  165. package/src/components/List/ListTypes.tsx +1 -1
  166. package/src/components/List/__snapshots__/List.test.tsx.snap +110 -8
  167. package/src/components/Logo/Logo.stories.mdx +30 -6
  168. package/src/components/Logo/Logo.test.tsx +17 -0
  169. package/src/components/Logo/Logo.tsx +18 -6
  170. package/src/components/Logo/LogoSvgs.tsx +4 -0
  171. package/src/components/Logo/LogoTypes.tsx +2 -0
  172. package/src/components/Logo/__snapshots__/Logo.test.tsx.snap +73 -2
  173. package/src/components/Modal/Modal.stories.mdx +256 -136
  174. package/src/components/Modal/Modal.test.tsx +151 -9
  175. package/src/components/Modal/Modal.tsx +140 -20
  176. package/src/components/Modal/__snapshots__/Modal.test.tsx.snap +25 -0
  177. package/src/components/Notification/Notification.stories.mdx +25 -1
  178. package/src/components/Notification/Notification.test.tsx +23 -0
  179. package/src/components/Notification/Notification.tsx +46 -44
  180. package/src/components/Notification/__snapshots__/Notification.test.tsx.snap +158 -29
  181. package/src/components/Pagination/Pagination.stories.mdx +25 -6
  182. package/src/components/Pagination/Pagination.test.tsx +25 -0
  183. package/src/components/Pagination/Pagination.tsx +6 -6
  184. package/src/components/Pagination/__snapshots__/Pagination.test.tsx.snap +244 -27
  185. package/src/components/Placeholder/Placeholder.tsx +3 -1
  186. package/src/components/ProgressIndicator/ProgressIndicator.stories.mdx +76 -10
  187. package/src/components/ProgressIndicator/ProgressIndicator.test.tsx +81 -11
  188. package/src/components/ProgressIndicator/ProgressIndicator.tsx +17 -9
  189. package/src/components/ProgressIndicator/__snapshots__/ProgressIndicator.test.tsx.snap +101 -14
  190. package/src/components/Radio/Radio.stories.mdx +64 -12
  191. package/src/components/Radio/Radio.test.tsx +28 -8
  192. package/src/components/Radio/Radio.tsx +66 -63
  193. package/src/components/Radio/__snapshots__/Radio.test.tsx.snap +103 -6
  194. package/src/components/RadioGroup/RadioGroup.stories.mdx +224 -89
  195. package/src/components/RadioGroup/RadioGroup.test.tsx +122 -62
  196. package/src/components/RadioGroup/RadioGroup.tsx +106 -100
  197. package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +1236 -1020
  198. package/src/components/SearchBar/SearchBar.stories.mdx +101 -36
  199. package/src/components/SearchBar/{SearchBar.Test.tsx → SearchBar.test.tsx} +46 -4
  200. package/src/components/SearchBar/SearchBar.tsx +17 -8
  201. package/src/components/SearchBar/__snapshots__/SearchBar.test.tsx.snap +1039 -0
  202. package/src/components/Select/Select.stories.mdx +128 -49
  203. package/src/components/Select/Select.test.tsx +63 -16
  204. package/src/components/Select/Select.tsx +131 -92
  205. package/src/components/Select/SelectTypes.tsx +5 -0
  206. package/src/components/Select/__snapshots__/Select.test.tsx.snap +765 -425
  207. package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +42 -10
  208. package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +8 -0
  209. package/src/components/SkeletonLoader/SkeletonLoader.tsx +76 -72
  210. package/src/components/SkeletonLoader/__snapshots__/SkeletonLoader.test.tsx.snap +169 -10
  211. package/src/components/Slider/Slider.stories.mdx +91 -42
  212. package/src/components/Slider/Slider.test.tsx +65 -17
  213. package/src/components/Slider/Slider.tsx +26 -19
  214. package/src/components/Slider/__snapshots__/Slider.test.tsx.snap +403 -226
  215. package/src/components/StatusBadge/StatusBadge.stories.mdx +19 -1
  216. package/src/components/StatusBadge/StatusBadge.test.tsx +16 -0
  217. package/src/components/StatusBadge/StatusBadge.tsx +25 -20
  218. package/src/components/StatusBadge/__snapshots__/StatusBadge.test.tsx.snap +22 -3
  219. package/src/components/StructuredContent/StructuredContent.stories.mdx +131 -12
  220. package/src/components/StructuredContent/StructuredContent.test.tsx +34 -0
  221. package/src/components/StructuredContent/StructuredContent.tsx +80 -75
  222. package/src/components/StructuredContent/__snapshots__/StructuredContent.test.tsx.snap +102 -17
  223. package/src/components/StyleGuide/Bidirectionality.stories.mdx +5 -5
  224. package/src/components/StyleGuide/Breakpoints.stories.mdx +6 -6
  225. package/src/components/StyleGuide/Buttons.stories.mdx +2 -12
  226. package/src/components/StyleGuide/ColorCard.tsx +1 -1
  227. package/src/components/StyleGuide/Colors.stories.mdx +1 -2
  228. package/src/components/StyleGuide/DesignTokens.stories.mdx +56 -26
  229. package/src/components/StyleGuide/Forms.stories.mdx +27 -12
  230. package/src/components/StyleGuide/Iconography.stories.mdx +2 -12
  231. package/src/components/StyleGuide/Spacing.stories.mdx +80 -41
  232. package/src/components/StyleGuide/Typography.stories.mdx +30 -21
  233. package/src/components/Table/Table.stories.mdx +38 -11
  234. package/src/components/Table/Table.test.tsx +15 -0
  235. package/src/components/Table/Table.tsx +7 -7
  236. package/src/components/Table/__snapshots__/Table.test.tsx.snap +408 -5
  237. package/src/components/Tabs/Tabs.stories.mdx +52 -3
  238. package/src/components/Tabs/Tabs.test.tsx +16 -0
  239. package/src/components/Tabs/Tabs.tsx +10 -6
  240. package/src/components/Tabs/__snapshots__/Tabs.test.tsx.snap +394 -5
  241. package/src/components/Template/Template.stories.mdx +47 -43
  242. package/src/components/Template/Template.test.tsx +33 -0
  243. package/src/components/Template/Template.tsx +65 -60
  244. package/src/components/Template/__snapshots__/Template.test.tsx.snap +191 -20
  245. package/src/components/Text/Text.stories.mdx +20 -1
  246. package/src/components/Text/Text.test.tsx +12 -0
  247. package/src/components/Text/Text.tsx +6 -4
  248. package/src/components/Text/__snapshots__/Text.test.tsx.snap +21 -4
  249. package/src/components/TextInput/TextInput.stories.mdx +65 -19
  250. package/src/components/TextInput/TextInput.test.tsx +42 -28
  251. package/src/components/TextInput/TextInput.tsx +121 -113
  252. package/src/components/TextInput/__snapshots__/TextInput.test.tsx.snap +96 -73
  253. package/src/components/Toggle/Toggle.stories.mdx +80 -22
  254. package/src/components/Toggle/Toggle.test.tsx +27 -9
  255. package/src/components/Toggle/Toggle.tsx +22 -18
  256. package/src/components/Toggle/__snapshots__/Toggle.test.tsx.snap +128 -5
  257. package/src/components/VideoPlayer/VideoPlayer.stories.mdx +52 -4
  258. package/src/components/VideoPlayer/VideoPlayer.test.tsx +23 -0
  259. package/src/components/VideoPlayer/VideoPlayer.tsx +133 -126
  260. package/src/components/VideoPlayer/__snapshots__/VideoPlayer.test.tsx.snap +81 -39
  261. package/src/docs/Chakra.stories.mdx +50 -9
  262. package/src/docs/Welcome.stories.mdx +160 -41
  263. package/src/hooks/useCarouselStyles.stories.mdx +22 -2
  264. package/src/hooks/useCarouselStyles.ts +3 -2
  265. package/src/hooks/useNYPLTheme.stories.mdx +101 -0
  266. package/src/hooks/useNYPLTheme.ts +30 -6
  267. package/src/hooks/useWindowSize.stories.mdx +23 -0
  268. package/src/index.ts +5 -2
  269. package/src/styles/base/_place-holder.scss +1 -1
  270. package/src/styles.scss +0 -1
  271. package/src/theme/components/button.ts +15 -7
  272. package/src/theme/components/card.ts +30 -19
  273. package/src/theme/components/checkbox.ts +10 -8
  274. package/src/theme/components/checkboxGroup.ts +1 -1
  275. package/src/theme/components/componentWrapper.ts +2 -2
  276. package/src/theme/components/customTable.ts +39 -31
  277. package/src/theme/components/fieldset.ts +1 -2
  278. package/src/theme/components/global.ts +25 -20
  279. package/src/theme/components/heading.ts +1 -1
  280. package/src/theme/components/helperErrorText.ts +1 -0
  281. package/src/theme/components/hero.ts +13 -15
  282. package/src/theme/components/label.ts +4 -3
  283. package/src/theme/components/list.ts +73 -66
  284. package/src/theme/components/notification.ts +2 -2
  285. package/src/theme/components/radio.ts +9 -9
  286. package/src/theme/components/radioGroup.ts +1 -1
  287. package/src/theme/components/select.ts +31 -22
  288. package/src/theme/components/skeletonLoader.ts +3 -3
  289. package/src/theme/components/slider.ts +8 -7
  290. package/src/theme/components/statusBadge.ts +2 -2
  291. package/src/theme/components/structuredContent.ts +66 -1
  292. package/src/theme/components/tabs.ts +2 -2
  293. package/src/theme/components/template.ts +9 -9
  294. package/src/theme/components/textInput.ts +13 -12
  295. package/src/theme/components/toggle.ts +17 -10
  296. package/src/theme/components/videoPlayer.ts +1 -1
  297. package/src/theme/foundations/colors.ts +1 -1
  298. package/src/theme/foundations/radii.ts +1 -0
  299. package/src/theme/foundations/spacing.ts +70 -22
  300. package/src/theme/foundations/typography.ts +2 -2
  301. package/src/utils/componentCategories.ts +1 -2
  302. package/dist/components/SearchBar/SearchBar.Test.d.ts +0 -1
  303. package/dist/helpers/generateUUID.d.ts +0 -1
  304. package/src/components/Modal/_Modal.scss +0 -18
  305. 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.25.10` |
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 DS
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 you
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" optReqFlag={false}>
225
- <Radio labelText="Radio 1" showLabel />
226
- <Radio labelText="Radio 2" showLabel />
227
- <Radio labelText="Radio 3" showLabel />
228
- <Radio labelText="Radio 4" showLabel />
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
- <FormField>
246
- <Button>Submit</Button>
247
- </FormField>
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 FormGaps in FormGaps) {
308
- sizes.push(formRow(`FormGaps.${FormGaps}`, FormGaps[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?: string;
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 function FormRow(props: React.PropsWithChildren<FormChildProps>) {
31
- const { children, className, gap, id } = props;
32
- const count = React.Children.count(children);
33
- const alteredChildren = React.Children.map(
34
- children,
35
- (child: React.ReactElement, i) => {
36
- if (!child) return null;
37
- if (child.type === FormField || child.props.mdxType === "FormField") {
38
- return React.cloneElement(child, { id: `${id}-grandchild${i}` });
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
- console.warn(
41
- "NYPL Reservoir FormRow: Children must be `FormField` components."
42
- );
43
- return null;
44
- }
45
- );
46
- return (
47
- <SimpleGrid columns={count} className={className} gap={gap} id={id}>
48
- {alteredChildren}
49
- </SimpleGrid>
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 function FormField(props: React.PropsWithChildren<FormChildProps>) {
55
- const { children, className, gap, id } = props;
56
- return (
57
- <SimpleGrid columns={1} className={className} gap={gap} id={id}>
58
- {children}
59
- </SimpleGrid>
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 default function Form(props: React.PropsWithChildren<FormProps>) {
65
- const {
66
- action,
67
- children,
68
- className,
69
- gap = FormGaps.Large,
70
- id = generateUUID(),
71
- method,
72
- onSubmit,
73
- } = props;
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
- let attributes = {};
76
- action && (attributes["action"] = action);
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
- method &&
79
- (method === "get" || method === "post") &&
80
- (attributes["method"] = method);
95
+ method &&
96
+ (method === "get" || method === "post") &&
97
+ (attributes["method"] = method);
81
98
 
82
- const alteredChildren = React.Children.map(
83
- children,
84
- (child: React.ReactElement, i) => {
85
- return React.cloneElement(child, { gap, id: `${id}-child${i}` });
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
- return (
90
- <form
91
- aria-label="form"
92
- className={className}
93
- id={id}
94
- onSubmit={onSubmit}
95
- {...attributes}
96
- >
97
- <SimpleGrid columns={1} gap={gap} id={`${id}-parent`}>
98
- {alteredChildren}
99
- </SimpleGrid>
100
- </form>
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;