@nypl/design-system-react-components 0.25.13 → 0.26.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 (299) hide show
  1. package/CHANGELOG.md +58 -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/Notification/Notification.d.ts +4 -4
  29. package/dist/components/Pagination/Pagination.d.ts +2 -2
  30. package/dist/components/ProgressIndicator/ProgressIndicator.d.ts +3 -3
  31. package/dist/components/Radio/Radio.d.ts +4 -6
  32. package/dist/components/RadioGroup/RadioGroup.d.ts +12 -6
  33. package/dist/components/SearchBar/SearchBar.d.ts +4 -4
  34. package/dist/components/Select/Select.d.ts +10 -6
  35. package/dist/components/Select/SelectTypes.d.ts +4 -0
  36. package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +4 -3
  37. package/dist/components/Slider/Slider.d.ts +6 -4
  38. package/dist/components/StatusBadge/StatusBadge.d.ts +5 -1
  39. package/dist/components/StructuredContent/StructuredContent.d.ts +2 -2
  40. package/dist/components/Table/Table.d.ts +1 -1
  41. package/dist/components/Tabs/Tabs.d.ts +4 -3
  42. package/dist/components/Template/Template.d.ts +4 -3
  43. package/dist/components/Text/Text.d.ts +1 -1
  44. package/dist/components/TextInput/TextInput.d.ts +5 -5
  45. package/dist/components/Toggle/Toggle.d.ts +3 -4
  46. package/dist/components/VideoPlayer/VideoPlayer.d.ts +2 -1
  47. package/dist/design-system-react-components.cjs.development.js +1663 -1139
  48. package/dist/design-system-react-components.cjs.development.js.map +1 -1
  49. package/dist/design-system-react-components.cjs.production.min.js +1 -1
  50. package/dist/design-system-react-components.cjs.production.min.js.map +1 -1
  51. package/dist/design-system-react-components.esm.js +1667 -1143
  52. package/dist/design-system-react-components.esm.js.map +1 -1
  53. package/dist/hooks/useCarouselStyles.d.ts +3 -2
  54. package/dist/hooks/useNYPLTheme.d.ts +12 -0
  55. package/dist/index.d.ts +4 -1
  56. package/dist/styles.css +1 -1
  57. package/dist/theme/components/button.d.ts +10 -2
  58. package/dist/theme/components/card.d.ts +42 -22
  59. package/dist/theme/components/checkbox.d.ts +5 -4
  60. package/dist/theme/components/checkboxGroup.d.ts +1 -1
  61. package/dist/theme/components/componentWrapper.d.ts +2 -2
  62. package/dist/theme/components/customTable.d.ts +84 -1
  63. package/dist/theme/components/fieldset.d.ts +4 -14
  64. package/dist/theme/components/global.d.ts +23 -17
  65. package/dist/theme/components/heading.d.ts +53 -0
  66. package/dist/theme/components/helperErrorText.d.ts +1 -0
  67. package/dist/theme/components/hero.d.ts +20 -14
  68. package/dist/theme/components/label.d.ts +9 -10
  69. package/dist/theme/components/list.d.ts +99 -9
  70. package/dist/theme/components/radio.d.ts +6 -4
  71. package/dist/theme/components/radioGroup.d.ts +1 -1
  72. package/dist/theme/components/select.d.ts +34 -5
  73. package/dist/theme/components/skeletonLoader.d.ts +2 -2
  74. package/dist/theme/components/slider.d.ts +6 -3
  75. package/dist/theme/components/structuredContent.d.ts +197 -0
  76. package/dist/theme/components/textInput.d.ts +18 -6
  77. package/dist/theme/components/toggle.d.ts +7 -4
  78. package/dist/theme/foundations/global.d.ts +2 -0
  79. package/dist/theme/foundations/radii.d.ts +1 -0
  80. package/dist/theme/foundations/spacing.d.ts +46 -43
  81. package/package.json +5 -6
  82. package/src/components/Accordion/Accordion.stories.mdx +9 -9
  83. package/src/components/Accordion/Accordion.test.tsx +21 -0
  84. package/src/components/Accordion/Accordion.tsx +13 -9
  85. package/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap +276 -27
  86. package/src/components/Autosuggest/Autosuggest.stories.mdx +4 -3
  87. package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +21 -5
  88. package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +52 -31
  89. package/src/components/Breadcrumbs/Breadcrumbs.tsx +8 -7
  90. package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +211 -12
  91. package/src/components/Button/Button.stories.mdx +87 -23
  92. package/src/components/Button/Button.test.tsx +25 -0
  93. package/src/components/Button/Button.tsx +18 -7
  94. package/src/components/Button/__snapshots__/Button.test.tsx.snap +27 -7
  95. package/src/components/Card/Card.stories.mdx +287 -194
  96. package/src/components/Card/Card.test.tsx +102 -0
  97. package/src/components/Card/Card.tsx +73 -32
  98. package/src/components/Card/__snapshots__/Card.test.tsx.snap +195 -35
  99. package/src/components/Chakra/Grid.stories.mdx +4 -4
  100. package/src/components/Checkbox/Checkbox.stories.mdx +62 -10
  101. package/src/components/Checkbox/Checkbox.test.tsx +32 -9
  102. package/src/components/Checkbox/Checkbox.tsx +20 -15
  103. package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +134 -7
  104. package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +65 -17
  105. package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +137 -81
  106. package/src/components/CheckboxGroup/CheckboxGroup.tsx +31 -21
  107. package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +332 -97
  108. package/src/components/ComponentWrapper/ComponentWrapper.test.tsx +12 -0
  109. package/src/components/ComponentWrapper/ComponentWrapper.tsx +39 -41
  110. package/src/components/ComponentWrapper/__snapshots__/ComponentWrapper.test.tsx.snap +47 -34
  111. package/src/components/DatePicker/DatePicker.stories.mdx +63 -27
  112. package/src/components/DatePicker/DatePicker.test.tsx +89 -13
  113. package/src/components/DatePicker/DatePicker.tsx +62 -56
  114. package/src/components/DatePicker/_DatePicker.scss +71 -13
  115. package/src/components/DatePicker/__snapshots__/DatePicker.test.tsx.snap +250 -206
  116. package/src/components/Fieldset/Fieldset.stories.mdx +33 -3
  117. package/src/components/Fieldset/Fieldset.test.tsx +58 -28
  118. package/src/components/Fieldset/Fieldset.tsx +35 -30
  119. package/src/components/Fieldset/__snapshots__/Fieldset.test.tsx.snap +40 -19
  120. package/src/components/Form/Form.stories.mdx +72 -39
  121. package/src/components/Form/Form.test.tsx +58 -15
  122. package/src/components/Form/Form.tsx +89 -67
  123. package/src/components/Form/__snapshots__/Form.test.tsx.snap +83 -5
  124. package/src/components/Grid/GridTypes.tsx +7 -7
  125. package/src/components/Grid/SimpleGrid.stories.mdx +34 -6
  126. package/src/components/Grid/SimpleGrid.test.tsx +9 -0
  127. package/src/components/Grid/SimpleGrid.tsx +29 -20
  128. package/src/components/Grid/__snapshots__/SimpleGrid.test.tsx.snap +16 -1
  129. package/src/components/Heading/Heading.stories.mdx +36 -3
  130. package/src/components/Heading/Heading.test.tsx +10 -0
  131. package/src/components/Heading/Heading.tsx +56 -50
  132. package/src/components/Heading/__snapshots__/Heading.test.tsx.snap +26 -7
  133. package/src/components/HelperErrorText/HelperErrorText.stories.mdx +64 -42
  134. package/src/components/HelperErrorText/HelperErrorText.test.tsx +15 -0
  135. package/src/components/HelperErrorText/HelperErrorText.tsx +40 -35
  136. package/src/components/HelperErrorText/__snapshots__/HelperErrorText.test.tsx.snap +35 -4
  137. package/src/components/Hero/Hero.stories.mdx +125 -95
  138. package/src/components/Hero/Hero.test.tsx +33 -0
  139. package/src/components/Hero/Hero.tsx +135 -126
  140. package/src/components/Hero/__snapshots__/Hero.test.tsx.snap +89 -17
  141. package/src/components/HorizontalRule/HorizontalRule.stories.mdx +26 -4
  142. package/src/components/HorizontalRule/HorizontalRule.test.tsx +9 -19
  143. package/src/components/HorizontalRule/HorizontalRule.tsx +9 -26
  144. package/src/components/HorizontalRule/__snapshots__/HorizontalRule.test.tsx.snap +18 -5
  145. package/src/components/Icons/Icon.stories.mdx +31 -6
  146. package/src/components/Icons/Icon.test.tsx +38 -0
  147. package/src/components/Icons/Icon.tsx +93 -76
  148. package/src/components/Icons/__snapshots__/Icon.test.tsx.snap +129 -0
  149. package/src/components/Image/Image.stories.mdx +29 -5
  150. package/src/components/Image/Image.test.tsx +8 -0
  151. package/src/components/Image/Image.tsx +38 -26
  152. package/src/components/Image/__snapshots__/Image.test.tsx.snap +24 -8
  153. package/src/components/Label/Label.stories.mdx +42 -20
  154. package/src/components/Label/Label.test.tsx +42 -17
  155. package/src/components/Label/Label.tsx +22 -13
  156. package/src/components/Label/__snapshots__/Label.test.tsx.snap +19 -15
  157. package/src/components/Link/Link.stories.mdx +25 -1
  158. package/src/components/Link/Link.test.tsx +21 -0
  159. package/src/components/Link/Link.tsx +8 -8
  160. package/src/components/Link/__snapshots__/Link.test.tsx.snap +37 -11
  161. package/src/components/List/List.stories.mdx +75 -40
  162. package/src/components/List/List.test.tsx +67 -19
  163. package/src/components/List/List.tsx +38 -25
  164. package/src/components/List/ListTypes.tsx +1 -1
  165. package/src/components/List/__snapshots__/List.test.tsx.snap +110 -8
  166. package/src/components/Logo/Logo.stories.mdx +30 -6
  167. package/src/components/Logo/Logo.test.tsx +17 -0
  168. package/src/components/Logo/Logo.tsx +18 -6
  169. package/src/components/Logo/LogoSvgs.tsx +4 -0
  170. package/src/components/Logo/LogoTypes.tsx +2 -0
  171. package/src/components/Logo/__snapshots__/Logo.test.tsx.snap +73 -2
  172. package/src/components/Modal/Modal.stories.mdx +13 -0
  173. package/src/components/Notification/Notification.stories.mdx +25 -1
  174. package/src/components/Notification/Notification.test.tsx +23 -0
  175. package/src/components/Notification/Notification.tsx +46 -44
  176. package/src/components/Notification/__snapshots__/Notification.test.tsx.snap +158 -29
  177. package/src/components/Pagination/Pagination.stories.mdx +24 -4
  178. package/src/components/Pagination/Pagination.test.tsx +25 -0
  179. package/src/components/Pagination/Pagination.tsx +6 -6
  180. package/src/components/Pagination/__snapshots__/Pagination.test.tsx.snap +244 -27
  181. package/src/components/Placeholder/Placeholder.tsx +3 -1
  182. package/src/components/ProgressIndicator/ProgressIndicator.stories.mdx +76 -10
  183. package/src/components/ProgressIndicator/ProgressIndicator.test.tsx +81 -11
  184. package/src/components/ProgressIndicator/ProgressIndicator.tsx +17 -9
  185. package/src/components/ProgressIndicator/__snapshots__/ProgressIndicator.test.tsx.snap +101 -14
  186. package/src/components/Radio/Radio.stories.mdx +64 -12
  187. package/src/components/Radio/Radio.test.tsx +28 -8
  188. package/src/components/Radio/Radio.tsx +66 -63
  189. package/src/components/Radio/__snapshots__/Radio.test.tsx.snap +103 -6
  190. package/src/components/RadioGroup/RadioGroup.stories.mdx +224 -89
  191. package/src/components/RadioGroup/RadioGroup.test.tsx +122 -62
  192. package/src/components/RadioGroup/RadioGroup.tsx +106 -100
  193. package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +1236 -1020
  194. package/src/components/SearchBar/SearchBar.stories.mdx +101 -36
  195. package/src/components/SearchBar/{SearchBar.Test.tsx → SearchBar.test.tsx} +46 -4
  196. package/src/components/SearchBar/SearchBar.tsx +17 -8
  197. package/src/components/SearchBar/__snapshots__/SearchBar.test.tsx.snap +1039 -0
  198. package/src/components/Select/Select.stories.mdx +128 -49
  199. package/src/components/Select/Select.test.tsx +63 -16
  200. package/src/components/Select/Select.tsx +125 -92
  201. package/src/components/Select/SelectTypes.tsx +5 -0
  202. package/src/components/Select/__snapshots__/Select.test.tsx.snap +749 -409
  203. package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +42 -10
  204. package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +8 -0
  205. package/src/components/SkeletonLoader/SkeletonLoader.tsx +76 -72
  206. package/src/components/SkeletonLoader/__snapshots__/SkeletonLoader.test.tsx.snap +169 -10
  207. package/src/components/Slider/Slider.stories.mdx +91 -42
  208. package/src/components/Slider/Slider.test.tsx +65 -17
  209. package/src/components/Slider/Slider.tsx +26 -19
  210. package/src/components/Slider/__snapshots__/Slider.test.tsx.snap +403 -226
  211. package/src/components/StatusBadge/StatusBadge.stories.mdx +19 -1
  212. package/src/components/StatusBadge/StatusBadge.test.tsx +16 -0
  213. package/src/components/StatusBadge/StatusBadge.tsx +25 -20
  214. package/src/components/StatusBadge/__snapshots__/StatusBadge.test.tsx.snap +22 -3
  215. package/src/components/StructuredContent/StructuredContent.stories.mdx +131 -12
  216. package/src/components/StructuredContent/StructuredContent.test.tsx +34 -0
  217. package/src/components/StructuredContent/StructuredContent.tsx +80 -75
  218. package/src/components/StructuredContent/__snapshots__/StructuredContent.test.tsx.snap +102 -17
  219. package/src/components/StyleGuide/Bidirectionality.stories.mdx +5 -5
  220. package/src/components/StyleGuide/Breakpoints.stories.mdx +6 -6
  221. package/src/components/StyleGuide/Buttons.stories.mdx +2 -12
  222. package/src/components/StyleGuide/ColorCard.tsx +1 -1
  223. package/src/components/StyleGuide/Colors.stories.mdx +1 -2
  224. package/src/components/StyleGuide/DesignTokens.stories.mdx +56 -26
  225. package/src/components/StyleGuide/Forms.stories.mdx +27 -12
  226. package/src/components/StyleGuide/Iconography.stories.mdx +2 -12
  227. package/src/components/StyleGuide/Spacing.stories.mdx +80 -41
  228. package/src/components/StyleGuide/Typography.stories.mdx +30 -21
  229. package/src/components/Table/Table.stories.mdx +38 -11
  230. package/src/components/Table/Table.test.tsx +15 -0
  231. package/src/components/Table/Table.tsx +7 -7
  232. package/src/components/Table/__snapshots__/Table.test.tsx.snap +408 -5
  233. package/src/components/Tabs/Tabs.stories.mdx +52 -3
  234. package/src/components/Tabs/Tabs.test.tsx +16 -0
  235. package/src/components/Tabs/Tabs.tsx +10 -6
  236. package/src/components/Tabs/__snapshots__/Tabs.test.tsx.snap +394 -5
  237. package/src/components/Template/Template.stories.mdx +47 -43
  238. package/src/components/Template/Template.test.tsx +33 -0
  239. package/src/components/Template/Template.tsx +65 -60
  240. package/src/components/Template/__snapshots__/Template.test.tsx.snap +191 -20
  241. package/src/components/Text/Text.stories.mdx +20 -1
  242. package/src/components/Text/Text.test.tsx +12 -0
  243. package/src/components/Text/Text.tsx +6 -4
  244. package/src/components/Text/__snapshots__/Text.test.tsx.snap +21 -4
  245. package/src/components/TextInput/TextInput.stories.mdx +65 -19
  246. package/src/components/TextInput/TextInput.test.tsx +42 -28
  247. package/src/components/TextInput/TextInput.tsx +121 -113
  248. package/src/components/TextInput/__snapshots__/TextInput.test.tsx.snap +96 -73
  249. package/src/components/Toggle/Toggle.stories.mdx +80 -22
  250. package/src/components/Toggle/Toggle.test.tsx +27 -9
  251. package/src/components/Toggle/Toggle.tsx +22 -18
  252. package/src/components/Toggle/__snapshots__/Toggle.test.tsx.snap +128 -5
  253. package/src/components/VideoPlayer/VideoPlayer.stories.mdx +52 -4
  254. package/src/components/VideoPlayer/VideoPlayer.test.tsx +23 -0
  255. package/src/components/VideoPlayer/VideoPlayer.tsx +133 -126
  256. package/src/components/VideoPlayer/__snapshots__/VideoPlayer.test.tsx.snap +81 -39
  257. package/src/docs/Chakra.stories.mdx +50 -9
  258. package/src/docs/Welcome.stories.mdx +160 -41
  259. package/src/hooks/useCarouselStyles.stories.mdx +22 -2
  260. package/src/hooks/useCarouselStyles.ts +3 -2
  261. package/src/hooks/useNYPLTheme.stories.mdx +101 -0
  262. package/src/hooks/useNYPLTheme.ts +30 -6
  263. package/src/hooks/useWindowSize.stories.mdx +23 -0
  264. package/src/index.ts +4 -1
  265. package/src/styles/base/_place-holder.scss +1 -1
  266. package/src/theme/components/button.ts +15 -7
  267. package/src/theme/components/card.ts +30 -19
  268. package/src/theme/components/checkbox.ts +10 -8
  269. package/src/theme/components/checkboxGroup.ts +1 -1
  270. package/src/theme/components/componentWrapper.ts +2 -2
  271. package/src/theme/components/customTable.ts +39 -31
  272. package/src/theme/components/fieldset.ts +1 -2
  273. package/src/theme/components/global.ts +25 -20
  274. package/src/theme/components/heading.ts +1 -1
  275. package/src/theme/components/helperErrorText.ts +1 -0
  276. package/src/theme/components/hero.ts +13 -15
  277. package/src/theme/components/label.ts +4 -3
  278. package/src/theme/components/list.ts +73 -66
  279. package/src/theme/components/notification.ts +2 -2
  280. package/src/theme/components/radio.ts +9 -9
  281. package/src/theme/components/radioGroup.ts +1 -1
  282. package/src/theme/components/select.ts +35 -22
  283. package/src/theme/components/skeletonLoader.ts +3 -3
  284. package/src/theme/components/slider.ts +8 -7
  285. package/src/theme/components/statusBadge.ts +2 -2
  286. package/src/theme/components/structuredContent.ts +66 -1
  287. package/src/theme/components/tabs.ts +2 -2
  288. package/src/theme/components/template.ts +9 -9
  289. package/src/theme/components/textInput.ts +13 -12
  290. package/src/theme/components/toggle.ts +17 -10
  291. package/src/theme/components/videoPlayer.ts +1 -1
  292. package/src/theme/foundations/colors.ts +1 -1
  293. package/src/theme/foundations/radii.ts +1 -0
  294. package/src/theme/foundations/spacing.ts +70 -22
  295. package/src/theme/foundations/typography.ts +2 -2
  296. package/src/utils/componentCategories.ts +1 -2
  297. package/dist/components/SearchBar/SearchBar.Test.d.ts +0 -1
  298. package/dist/helpers/generateUUID.d.ts +0 -1
  299. package/src/helpers/generateUUID.tsx +0 -5
@@ -60,7 +60,20 @@ import DSProvider from "../../theme/provider";
60
60
  | Component Version | DS Version |
61
61
  | ----------------- | ---------- |
62
62
  | Added | `0.0.4` |
63
- | Latest | `0.25.13` |
63
+ | Latest | `0.26.0` |
64
+
65
+ ## Table of Contents
66
+
67
+ - [Overview](#overview)
68
+ - [Component Props](#component-props)
69
+ - [Accessibility](#accessibility)
70
+ - [Form Components](#form-components)
71
+ - [Search Autocomplete](#search-autocomplete)
72
+ - [Form States](#form-states)
73
+ - [With Heading and Description Text](#with-heading-and-description-text)
74
+ - [TextInput and onSubmit Values](#textinput-and-onsubmit-values)
75
+
76
+ ## Overview
64
77
 
65
78
  <Description of={SearchBar} />
66
79
 
@@ -89,6 +102,8 @@ export const optionsGroup = [
89
102
  "Villagers",
90
103
  ];
91
104
 
105
+ ## Component Props
106
+
92
107
  <Canvas withToolbar>
93
108
  <Story
94
109
  name="SearchBar with Controls"
@@ -113,50 +128,75 @@ export const optionsGroup = [
113
128
  textInputProps: undefined,
114
129
  }}
115
130
  >
116
- {(args) => (
117
- <SearchBar
118
- {...args}
119
- selectProps={
120
- args.showSelect && {
121
- labelText: "Select a category",
122
- name: "selectName",
123
- optionsData: optionsGroup,
131
+ {(args) => {
132
+ const { helperText, showHelperText, showSelect, ...rest } = args;
133
+ return (
134
+ <SearchBar
135
+ {...rest}
136
+ selectProps={
137
+ showSelect && {
138
+ labelText: "Select a category",
139
+ name: "selectName",
140
+ optionsData: optionsGroup,
141
+ }
124
142
  }
125
- }
126
- textInputProps={{
127
- labelText: "Item Search",
128
- name: "textInputName",
129
- placeholder: "Item Search",
130
- }}
131
- helperText={args.showHelperText && args.helperText}
132
- />
133
- )}
143
+ textInputProps={{
144
+ labelText: "Item Search",
145
+ name: "textInputName",
146
+ placeholder: "Item Search",
147
+ }}
148
+ helperText={showHelperText && helperText}
149
+ />
150
+ );
151
+ }}
134
152
  </Story>
135
153
  </Canvas>
136
154
 
137
155
  <ArgsTable story="SearchBar with Controls" />
138
156
 
139
- ## Component Props
157
+ ## Accessibility
158
+
159
+ The `SearchBar` component is implemented with Reservoir `Select`, `TextInput`,
160
+ and `Button` accessible components. This a "complete" component that renders an
161
+ HTML `<form>` element that is submitted with a `<button>` element of `type="submit"`.
162
+ The `<form>` element also has a `role="search"` attribute that allows
163
+ screenreaders to pick up this entire search form.
164
+
165
+ Resources:
166
+
167
+ - [Reservoir Select](https://nypl.github.io/nypl-design-system/storybook-static/?path=/docs/components-form-elements-select--select-with-controls)
168
+ - [Reservoir TextInput](https://nypl.github.io/nypl-design-system/storybook-static/?path=/docs/components-form-elements-textinput--text-input-with-controls)
169
+ - [a11ymatters Accessible Search Form](https://www.a11ymatters.com/pattern/accessible-search/)
170
+ - [MDN ARIA: search role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/search_role)
171
+
172
+ ## Form Components
140
173
 
141
174
  ### Select Component
142
175
 
143
176
  To render an optional `Select` component, an object must be passed to the
144
177
  `selectProps` prop. It _must_ include `name`, `labelText`, and `optionsData`
145
- properties. The `onChange` property is optional. The `labelText` value won't be
146
- rendered but will be used for its `aria-label` attribute.
178
+ properties. The `onChange` and `value` properties are optional. The `labelText`
179
+ value won't be rendered but will be used for its `aria-label` attribute.
180
+
181
+ If you want to control the `Select` component, you **must** pass the `onChange`
182
+ and `value` props to the `selectProps` prop object. You must then control the
183
+ state of the selected value in your application. See the example at end of this
184
+ page for a full demonstration.
147
185
 
148
186
  ```
149
187
  const selectProps = {
150
- name: "select-form-name",
151
188
  labelText: "Select a category",
152
- optionsData: optionsGroup,
189
+ name: "select-form-name",
153
190
  onChange: (event) => {
154
191
  console.log(event.target.value);
155
192
  },
193
+ optionsData: optionsGroup,
194
+ value: "Art",
156
195
  };
157
196
 
158
197
  // ...
159
198
  <SearchBar
199
+ id="searchBar"
160
200
  onSubmit={() => {}}
161
201
  selectProps={selectProps}
162
202
  // ...
@@ -183,6 +223,7 @@ const textInputProps = {
183
223
 
184
224
  // ...
185
225
  <SearchBar
226
+ id="searchBar"
186
227
  onSubmit={() => {}}
187
228
  textInputProps={textInputProps}
188
229
  // ...
@@ -200,6 +241,7 @@ const textInputElement = <CustomInput {...props} />;
200
241
 
201
242
  // ...
202
243
  <SearchBar
244
+ id="searchBar"
203
245
  onSubmit={() => {}}
204
246
  textInputElement={textInputElement}
205
247
  // ...
@@ -227,6 +269,7 @@ const helperText = "";
227
269
 
228
270
  // ...
229
271
  <SearchBar
272
+ id="searchBar"
230
273
  onSubmit={() => {}}
231
274
  helperText="Search for items in <b>Animal Crossing New Horizons</b>."
232
275
  // ...
@@ -238,6 +281,7 @@ const helperText = "";
238
281
  <SearchBar
239
282
  descriptionText="The helper text below contains HTML in a string."
240
283
  helperText="Search for items in <b>Animal Crossing New Horizons</b>."
284
+ id="helper-text"
241
285
  onSubmit={() => {}}
242
286
  textInputProps={{
243
287
  labelText: "Item Search",
@@ -248,6 +292,7 @@ const helperText = "";
248
292
  <br />
249
293
  <SearchBar
250
294
  descriptionText="The invalid text below contains HTML in a string."
295
+ id="invalid-text"
251
296
  isInvalid
252
297
  invalidText="Could <b>not</b> find the item <b>:(</b>"
253
298
  onSubmit={() => {}}
@@ -277,6 +322,7 @@ precedence.
277
322
  <Story
278
323
  name="Search Autocomplete"
279
324
  args={{
325
+ id: "autocomplete",
280
326
  isDisabled: false,
281
327
  isInvalid: false,
282
328
  isRequired: false,
@@ -295,7 +341,7 @@ precedence.
295
341
  </Story>
296
342
  </Canvas>
297
343
 
298
- ## Other Examples
344
+ ## Form States
299
345
 
300
346
  Use the Controls in the `Basic` example to see different states in real time.
301
347
  Here are the same possible states of the `SearchBar` component in static examples.
@@ -309,15 +355,16 @@ handle the error state yourself.
309
355
  <Canvas>
310
356
  <DSProvider>
311
357
  <SearchBar
358
+ helperText="This is the helper text!"
359
+ id="error-state"
360
+ invalidText="Could not find the item :("
361
+ isInvalid
312
362
  onSubmit={() => {}}
313
363
  textInputProps={{
314
364
  labelText: "Item Search",
315
365
  name: "textInputName",
316
366
  placeholder: "Item Search",
317
367
  }}
318
- helperText="This is the helper text!"
319
- invalidText="Could not find the item :("
320
- isInvalid
321
368
  />
322
369
  </DSProvider>
323
370
  </Canvas>
@@ -331,19 +378,20 @@ handle the disabled state yourself.
331
378
  <Canvas>
332
379
  <DSProvider>
333
380
  <SearchBar
381
+ helperText="Reason for disabled state."
382
+ id="disabled-state"
383
+ isDisabled
334
384
  onSubmit={() => {}}
335
385
  textInputProps={{
336
386
  labelText: "Item Search",
337
387
  name: "textInputName",
338
388
  placeholder: "Item Search",
339
389
  }}
340
- helperText="Reason for disabled state."
341
- isDisabled
342
390
  />
343
391
  </DSProvider>
344
392
  </Canvas>
345
393
 
346
- ### With Heading and Description Text
394
+ ## With Heading and Description Text
347
395
 
348
396
  Use the `descriptionText` and `headingText` props to render a heading and
349
397
  description above the main `SearchBar` form component.
@@ -353,6 +401,7 @@ description above the main `SearchBar` form component.
353
401
  <SearchBar
354
402
  descriptionText="This is the description for this `SearchBar` instance."
355
403
  headingText="Heading for this `SearchBar`"
404
+ id="heading-and-description"
356
405
  onSubmit={() => {}}
357
406
  textInputProps={{
358
407
  labelText: "Item Search",
@@ -363,7 +412,7 @@ description above the main `SearchBar` form component.
363
412
  </DSProvider>
364
413
  </Canvas>
365
414
 
366
- ### TextInput and onSubmit Values
415
+ ## TextInput and onSubmit Values
367
416
 
368
417
  _NOTE: open the browser console to see the values logged in the example below._
369
418
 
@@ -387,7 +436,12 @@ values can be retrieved as `event.target.selectName.value` and
387
436
  `event.target.textInputName.value`.
388
437
 
389
438
  ```tsx
390
- function SearchBarValueExample() {
439
+ export function SearchBarValueExample() {
440
+ const [selectValue, setSelectValue] = React.useState("Tools");
441
+ const selectOnChange = (event) => {
442
+ console.log(`onChange Select value: ${event.target.value}`);
443
+ setSelectValue(event.target.value);
444
+ };
391
445
  const textInputOnChange = (event) => {
392
446
  console.log(`onChange TextInput value: ${event.target.value}`);
393
447
  };
@@ -398,11 +452,16 @@ function SearchBarValueExample() {
398
452
  };
399
453
  return (
400
454
  <SearchBar
455
+ helperText="Search for an item"
456
+ invalidText="Could not find the item :("
457
+ id="example-1"
401
458
  onSubmit={onSubmit}
402
459
  selectProps={{
403
460
  labelText: "Select a category",
404
461
  name: "selectName",
462
+ onChange: selectOnChange,
405
463
  optionsData: optionsGroup,
464
+ value: selectValue,
406
465
  }}
407
466
  textInputProps={{
408
467
  labelText: "Item Search",
@@ -410,14 +469,17 @@ function SearchBarValueExample() {
410
469
  onChange: textInputOnChange,
411
470
  placeholder: "Item Search",
412
471
  }}
413
- helperText="Search for an item"
414
- invalidText="Could not find the item :("
415
472
  />
416
473
  );
417
474
  }
418
475
  ```
419
476
 
420
477
  export function SearchBarValueExample() {
478
+ const [selectValue, setSelectValue] = React.useState("Tools");
479
+ const selectOnChange = (event) => {
480
+ console.log(`onChange Select value: ${event.target.value}`);
481
+ setSelectValue(event.target.value);
482
+ };
421
483
  const textInputOnChange = (event) => {
422
484
  console.log(`onChange TextInput value: ${event.target.value}`);
423
485
  };
@@ -428,11 +490,16 @@ export function SearchBarValueExample() {
428
490
  };
429
491
  return (
430
492
  <SearchBar
493
+ helperText="Search for an item"
494
+ invalidText="Could not find the item :("
495
+ id="example-1"
431
496
  onSubmit={onSubmit}
432
497
  selectProps={{
433
498
  labelText: "Select a category",
434
499
  name: "selectName",
500
+ onChange: selectOnChange,
435
501
  optionsData: optionsGroup,
502
+ value: selectValue,
436
503
  }}
437
504
  textInputProps={{
438
505
  labelText: "Item Search",
@@ -440,8 +507,6 @@ export function SearchBarValueExample() {
440
507
  onChange: textInputOnChange,
441
508
  placeholder: "Item Search",
442
509
  }}
443
- helperText="Search for an item"
444
- invalidText="Could not find the item :("
445
510
  />
446
511
  );
447
512
  }
@@ -22,6 +22,7 @@ const selectProps: SelectProps = {
22
22
  name: "selectName",
23
23
  labelText: "Select a category",
24
24
  optionsData: optionsGroup,
25
+ value: "Songs",
25
26
  };
26
27
  const textInputProps: TextInputProps = {
27
28
  labelText: "Item Search",
@@ -162,7 +163,9 @@ describe("SearchBar", () => {
162
163
  });
163
164
 
164
165
  it("calls the Select onChange callback function", () => {
165
- selectProps.onChange = jest.fn();
166
+ let selectValue = "Songs";
167
+ selectProps.onChange = (e) => (selectValue = e.target.value);
168
+ selectProps.value = selectValue;
166
169
 
167
170
  render(
168
171
  <SearchBar
@@ -175,13 +178,13 @@ describe("SearchBar", () => {
175
178
  />
176
179
  );
177
180
  const select = screen.getByLabelText(selectProps.labelText);
178
- expect(selectProps.onChange).toHaveBeenCalledTimes(0);
181
+ expect(selectValue).toEqual("Songs");
179
182
 
180
183
  userEvent.selectOptions(select, "Flowers");
181
- expect(selectProps.onChange).toHaveBeenCalledTimes(1);
184
+ expect(selectValue).toEqual("Flowers");
182
185
 
183
186
  userEvent.selectOptions(select, "Furniture");
184
- expect(selectProps.onChange).toHaveBeenCalledTimes(2);
187
+ expect(selectValue).toEqual("Furniture");
185
188
  });
186
189
 
187
190
  it("calls the callback function for the Button component ", () => {
@@ -266,6 +269,18 @@ describe("SearchBar", () => {
266
269
  ).toBeInTheDocument();
267
270
  });
268
271
 
272
+ it("logs a warning when there is no `id` passed", () => {
273
+ const warn = jest.spyOn(console, "warn");
274
+ render(
275
+ // @ts-ignore: Typescript complains when a required prop is not passed, but
276
+ // here we don't want to pass the required prop to make sure the warning appears.
277
+ <SearchBar labelText={labelText} onSubmit={jest.fn()} />
278
+ );
279
+ expect(warn).toHaveBeenCalledWith(
280
+ "NYPL Reservoir SearchBar: This component's required `id` prop was not passed."
281
+ );
282
+ });
283
+
269
284
  it("renders the UI snapshot correctly", () => {
270
285
  const basic = renderer
271
286
  .create(
@@ -378,6 +393,31 @@ describe("SearchBar", () => {
378
393
  />
379
394
  )
380
395
  .toJSON();
396
+ const withChakraProps = renderer
397
+ .create(
398
+ <SearchBar
399
+ helperText={helperText}
400
+ id="chakra"
401
+ labelText={labelText}
402
+ onSubmit={jest.fn()}
403
+ textInputProps={textInputProps}
404
+ p="20px"
405
+ color="ui.error.primary"
406
+ />
407
+ )
408
+ .toJSON();
409
+ const withOtherProps = renderer
410
+ .create(
411
+ <SearchBar
412
+ helperText={helperText}
413
+ id="props"
414
+ labelText={labelText}
415
+ onSubmit={jest.fn()}
416
+ textInputProps={textInputProps}
417
+ data-testid="props"
418
+ />
419
+ )
420
+ .toJSON();
381
421
 
382
422
  expect(basic).toMatchSnapshot();
383
423
  expect(withSelect).toMatchSnapshot();
@@ -389,5 +429,7 @@ describe("SearchBar", () => {
389
429
  expect(withHeading).toMatchSnapshot();
390
430
  expect(withDescription).toMatchSnapshot();
391
431
  expect(withHeadingAndDescription).toMatchSnapshot();
432
+ expect(withChakraProps).toMatchSnapshot();
433
+ expect(withOtherProps).toMatchSnapshot();
392
434
  });
393
435
  });
@@ -1,4 +1,4 @@
1
- import { Box, useMultiStyleConfig } from "@chakra-ui/react";
1
+ import { Box, chakra, useMultiStyleConfig } from "@chakra-ui/react";
2
2
  import * as React from "react";
3
3
 
4
4
  import Button from "../Button/Button";
@@ -11,8 +11,6 @@ import Select from "../Select/Select";
11
11
  import { SelectTypes } from "../Select/SelectTypes";
12
12
  import TextInput from "../TextInput/TextInput";
13
13
  import { TextInputTypes, TextInputVariants } from "../TextInput/TextInputTypes";
14
- import generateUUID from "../../helpers/generateUUID";
15
-
16
14
  interface BaseProps {
17
15
  labelText: string;
18
16
  name: string;
@@ -21,6 +19,7 @@ interface BaseProps {
21
19
  | React.ChangeEvent<HTMLInputElement>
22
20
  | React.ChangeEvent<HTMLTextAreaElement>
23
21
  ) => void;
22
+ value?: string;
24
23
  }
25
24
  // Internal interfaces that are used only for `SearchBar` props.
26
25
  export interface SelectProps extends BaseProps {
@@ -28,7 +27,6 @@ export interface SelectProps extends BaseProps {
28
27
  }
29
28
  export interface TextInputProps extends BaseProps {
30
29
  placeholder?: string;
31
- value?: string;
32
30
  }
33
31
 
34
32
  export interface SearchBarProps {
@@ -45,7 +43,7 @@ export interface SearchBarProps {
45
43
  /** The text to display below the form in a `HelperErrorText` component. */
46
44
  helperText?: HelperErrorTextType;
47
45
  /** ID that other components can cross reference for accessibility purposes */
48
- id?: string;
46
+ id: string;
49
47
  /** Optional string to populate the `HelperErrorText` for the error state
50
48
  * when `isInvalid` is true. */
51
49
  invalidText?: HelperErrorTextType;
@@ -76,7 +74,7 @@ export interface SearchBarProps {
76
74
  * Renders a wrapper `form` element to be used with `Select` (optional),
77
75
  * `Input`, and `Button` components together.
78
76
  */
79
- export default function SearchBar(props: SearchBarProps) {
77
+ export const SearchBar = chakra((props: SearchBarProps) => {
80
78
  const {
81
79
  action,
82
80
  buttonOnClick = null,
@@ -84,7 +82,7 @@ export default function SearchBar(props: SearchBarProps) {
84
82
  descriptionText,
85
83
  headingText,
86
84
  helperText,
87
- id = generateUUID(),
85
+ id,
88
86
  invalidText,
89
87
  isDisabled = false,
90
88
  isInvalid = false,
@@ -96,6 +94,7 @@ export default function SearchBar(props: SearchBarProps) {
96
94
  selectProps,
97
95
  textInputElement,
98
96
  textInputProps,
97
+ ...rest
99
98
  } = props;
100
99
  const styles = useMultiStyleConfig("SearchBar", {});
101
100
  const stateProps = {
@@ -121,6 +120,12 @@ export default function SearchBar(props: SearchBarProps) {
121
120
  lineHeight: "1.70",
122
121
  marginBottom: "auto",
123
122
  };
123
+
124
+ if (!id) {
125
+ console.warn(
126
+ "NYPL Reservoir SearchBar: This component's required `id` prop was not passed."
127
+ );
128
+ }
124
129
  // Render the `Select` component.
125
130
  const selectElem = selectProps && (
126
131
  <Select
@@ -130,6 +135,7 @@ export default function SearchBar(props: SearchBarProps) {
130
135
  name={selectProps?.name}
131
136
  onChange={selectProps?.onChange}
132
137
  selectType={SelectTypes.SearchBar}
138
+ value={selectProps?.value}
133
139
  {...stateProps}
134
140
  >
135
141
  {selectProps?.optionsData.map((option) => (
@@ -188,6 +194,7 @@ export default function SearchBar(props: SearchBarProps) {
188
194
  id={id}
189
195
  invalidText={invalidText}
190
196
  isInvalid={isInvalid}
197
+ {...rest}
191
198
  >
192
199
  <Box
193
200
  as="form"
@@ -206,4 +213,6 @@ export default function SearchBar(props: SearchBarProps) {
206
213
  </Box>
207
214
  </ComponentWrapper>
208
215
  );
209
- }
216
+ });
217
+
218
+ export default SearchBar;