@nypl/design-system-react-components 0.25.2 → 0.25.6

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 (238) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/README.md +47 -11
  3. package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +4 -0
  4. package/dist/components/Breadcrumbs/BreadcrumbsTypes.d.ts +1 -0
  5. package/dist/components/Button/Button.d.ts +9 -8
  6. package/dist/components/Button/ButtonTypes.d.ts +2 -1
  7. package/dist/components/Card/Card.d.ts +36 -52
  8. package/dist/components/Card/CardTypes.d.ts +0 -15
  9. package/dist/components/Checkbox/Checkbox.d.ts +8 -9
  10. package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +2 -2
  11. package/dist/components/DatePicker/DatePicker.d.ts +36 -36
  12. package/dist/components/Fieldset/Fieldset.d.ts +25 -0
  13. package/dist/components/HelperErrorText/HelperErrorText.d.ts +4 -0
  14. package/dist/components/HorizontalRule/HorizontalRule.d.ts +10 -3
  15. package/dist/components/Icons/Icon.d.ts +4 -0
  16. package/dist/components/Icons/IconSvgs.d.ts +11 -0
  17. package/dist/components/Icons/IconTypes.d.ts +11 -0
  18. package/dist/components/Image/Image.d.ts +19 -9
  19. package/dist/components/Image/ImageTypes.d.ts +20 -0
  20. package/dist/components/Link/Link.d.ts +4 -0
  21. package/dist/components/List/List.d.ts +7 -1
  22. package/dist/components/Notification/Notification.d.ts +6 -4
  23. package/dist/components/Pagination/Pagination.d.ts +16 -13
  24. package/dist/components/Pagination/Pagination.stories.d.ts +2 -0
  25. package/dist/components/ProgressIndicator/ProgressIndicator.d.ts +29 -0
  26. package/dist/components/ProgressIndicator/ProgressIndicatorTypes.d.ts +8 -0
  27. package/dist/components/RadioGroup/RadioGroup.d.ts +2 -2
  28. package/dist/components/SearchBar/SearchBar.d.ts +3 -3
  29. package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +18 -14
  30. package/dist/components/Slider/Slider.d.ts +57 -0
  31. package/dist/components/Tabs/Tabs.d.ts +1 -1
  32. package/dist/components/TextInput/TextInput.d.ts +10 -0
  33. package/dist/design-system-react-components.cjs.development.js +3058 -936
  34. package/dist/design-system-react-components.cjs.development.js.map +1 -1
  35. package/dist/design-system-react-components.cjs.production.min.js +1 -1
  36. package/dist/design-system-react-components.cjs.production.min.js.map +1 -1
  37. package/dist/design-system-react-components.esm.js +3049 -921
  38. package/dist/design-system-react-components.esm.js.map +1 -1
  39. package/dist/index.d.ts +12 -6
  40. package/dist/resources.scss +180 -170
  41. package/dist/styles.css +1 -1
  42. package/dist/theme/components/breadcrumb.d.ts +9 -0
  43. package/dist/theme/components/button.d.ts +22 -8
  44. package/dist/theme/components/card.d.ts +168 -0
  45. package/dist/theme/components/checkbox.d.ts +5 -1
  46. package/dist/theme/components/checkboxGroup.d.ts +12 -0
  47. package/dist/theme/components/datePicker.d.ts +16 -0
  48. package/dist/theme/components/fieldset.d.ts +27 -0
  49. package/dist/theme/components/global.d.ts +23 -13
  50. package/dist/theme/components/globalMixins.d.ts +9 -1
  51. package/dist/theme/components/heading.d.ts +5 -0
  52. package/dist/theme/components/image.d.ts +31 -0
  53. package/dist/theme/components/label.d.ts +5 -3
  54. package/dist/theme/components/link.d.ts +4 -0
  55. package/dist/theme/components/list.d.ts +5 -1
  56. package/dist/theme/components/notification.d.ts +4 -14
  57. package/dist/theme/components/pagination.d.ts +19 -0
  58. package/dist/theme/components/progressIndicator.d.ts +50 -0
  59. package/dist/theme/components/radioGroup.d.ts +12 -0
  60. package/dist/theme/components/select.d.ts +11 -2
  61. package/dist/theme/components/skeletonLoader.d.ts +98 -0
  62. package/dist/theme/components/slider.d.ts +51 -0
  63. package/dist/theme/components/textInput.d.ts +8 -0
  64. package/dist/theme/foundations/breakpoints.d.ts +8 -8
  65. package/dist/theme/foundations/global.d.ts +6 -1
  66. package/package.json +72 -84
  67. package/src/__tests__/setup.ts +2 -2
  68. package/src/components/Accordion/Accordion.stories.mdx +39 -42
  69. package/src/components/Autosuggest/Autosuggest.stories.mdx +3 -3
  70. package/src/components/Autosuggest/Autosuggest.stories.tsx +1 -0
  71. package/src/components/Autosuggest/_Autosuggest.scss +5 -5
  72. package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +24 -8
  73. package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +33 -0
  74. package/src/components/Breadcrumbs/Breadcrumbs.tsx +5 -1
  75. package/src/components/Breadcrumbs/BreadcrumbsTypes.tsx +1 -0
  76. package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +298 -1
  77. package/src/components/Button/Button.stories.mdx +15 -10
  78. package/src/components/Button/Button.test.tsx +21 -7
  79. package/src/components/Button/Button.tsx +18 -33
  80. package/src/components/Button/ButtonTypes.tsx +1 -0
  81. package/src/components/Button/__snapshots__/Button.test.tsx.snap +41 -10
  82. package/src/components/Card/Card.stories.mdx +296 -259
  83. package/src/components/Card/Card.test.tsx +156 -84
  84. package/src/components/Card/Card.tsx +195 -145
  85. package/src/components/Card/CardTypes.tsx +0 -17
  86. package/src/components/Card/__snapshots__/Card.test.tsx.snap +410 -0
  87. package/src/components/CardEdition/CardEdition.stories.tsx +15 -47
  88. package/src/components/CardEdition/_CardEdition.scss +22 -23
  89. package/src/components/Chakra/Box.stories.mdx +14 -15
  90. package/src/components/Chakra/Center.stories.mdx +15 -8
  91. package/src/components/Chakra/Grid.stories.mdx +16 -7
  92. package/src/components/Chakra/Stack.stories.mdx +35 -18
  93. package/src/components/Checkbox/Checkbox.stories.mdx +33 -11
  94. package/src/components/Checkbox/Checkbox.test.tsx +30 -3
  95. package/src/components/Checkbox/Checkbox.tsx +27 -27
  96. package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +90 -2
  97. package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +82 -2
  98. package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +1 -1
  99. package/src/components/CheckboxGroup/CheckboxGroup.tsx +14 -15
  100. package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +44 -80
  101. package/src/components/DatePicker/DatePicker.stories.mdx +163 -62
  102. package/src/components/DatePicker/DatePicker.test.tsx +248 -65
  103. package/src/components/DatePicker/DatePicker.tsx +158 -130
  104. package/src/components/DatePicker/_DatePicker.scss +33 -67
  105. package/src/components/DatePicker/__snapshots__/DatePicker.test.tsx.snap +818 -0
  106. package/src/components/Fieldset/Fieldset.stories.mdx +55 -0
  107. package/src/components/Fieldset/Fieldset.test.tsx +125 -0
  108. package/src/components/Fieldset/Fieldset.tsx +52 -0
  109. package/src/components/Fieldset/__snapshots__/Fieldset.test.tsx.snap +68 -0
  110. package/src/components/Form/Form.stories.mdx +4 -5
  111. package/src/components/Form/Form.tsx +1 -0
  112. package/src/components/Grid/SimpleGrid.stories.mdx +32 -39
  113. package/src/components/Grid/SimpleGrid.test.tsx +4 -4
  114. package/src/components/Heading/Heading.stories.mdx +3 -4
  115. package/src/components/HelperErrorText/HelperErrorText.stories.mdx +1 -1
  116. package/src/components/HelperErrorText/HelperErrorText.tsx +5 -1
  117. package/src/components/Hero/HeroTypes.tsx +1 -0
  118. package/src/components/Hero/__snapshots__/Hero.test.tsx.snap +7 -7
  119. package/src/components/HorizontalRule/HorizontalRule.stories.mdx +6 -5
  120. package/src/components/HorizontalRule/HorizontalRule.test.tsx +17 -0
  121. package/src/components/HorizontalRule/HorizontalRule.tsx +21 -4
  122. package/src/components/HorizontalRule/__snapshots__/HorizontalRule.test.tsx.snap +5 -5
  123. package/src/components/Icons/Icon.stories.mdx +11 -3
  124. package/src/components/Icons/Icon.test.tsx +18 -0
  125. package/src/components/Icons/Icon.tsx +6 -0
  126. package/src/components/Icons/IconSvgs.tsx +22 -0
  127. package/src/components/Icons/IconTypes.tsx +11 -0
  128. package/src/components/Image/Image.stories.mdx +220 -0
  129. package/src/components/Image/Image.test.tsx +131 -29
  130. package/src/components/Image/Image.tsx +84 -56
  131. package/src/components/Image/ImageTypes.ts +22 -0
  132. package/src/components/Image/__snapshots__/Image.test.tsx.snap +190 -0
  133. package/src/components/Input/Input.stories.tsx +20 -64
  134. package/src/components/Input/_Input.scss +23 -14
  135. package/src/components/Link/Link.tsx +4 -1
  136. package/src/components/List/List.stories.mdx +1 -1
  137. package/src/components/List/List.tsx +11 -4
  138. package/src/components/Modal/Modal.stories.mdx +3 -3
  139. package/src/components/Modal/_Modal.scss +2 -2
  140. package/src/components/Notification/Notification.stories.mdx +1 -3
  141. package/src/components/Notification/Notification.tsx +24 -9
  142. package/src/components/Notification/__snapshots__/Notification.test.tsx.snap +2 -0
  143. package/src/components/Pagination/Pagination.stories.mdx +26 -27
  144. package/src/components/Pagination/Pagination.stories.tsx +11 -16
  145. package/src/components/Pagination/Pagination.test.tsx +276 -146
  146. package/src/components/Pagination/Pagination.tsx +174 -154
  147. package/src/components/Pagination/__snapshots__/Pagination.test.tsx.snap +285 -0
  148. package/src/components/ProgressIndicator/ProgressIndicator.stories.mdx +292 -0
  149. package/src/components/ProgressIndicator/ProgressIndicator.test.tsx +225 -0
  150. package/src/components/ProgressIndicator/ProgressIndicator.tsx +126 -0
  151. package/src/components/ProgressIndicator/ProgressIndicatorTypes.ts +8 -0
  152. package/src/components/ProgressIndicator/__snapshots__/ProgressIndicator.test.tsx.snap +357 -0
  153. package/src/components/Radio/__snapshots__/Radio.test.tsx.snap +3 -0
  154. package/src/components/RadioGroup/RadioGroup.stories.mdx +3 -4
  155. package/src/components/RadioGroup/RadioGroup.tsx +11 -16
  156. package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +39 -71
  157. package/src/components/SearchBar/SearchBar.Test.tsx +66 -21
  158. package/src/components/SearchBar/SearchBar.stories.mdx +114 -10
  159. package/src/components/SearchBar/SearchBar.tsx +15 -5
  160. package/src/components/Select/SelectTypes.tsx +1 -0
  161. package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +28 -59
  162. package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +97 -177
  163. package/src/components/SkeletonLoader/SkeletonLoader.tsx +74 -71
  164. package/src/components/SkeletonLoader/__snapshots__/SkeletonLoader.test.tsx.snap +739 -0
  165. package/src/components/Slider/Slider.stories.mdx +529 -0
  166. package/src/components/Slider/Slider.test.tsx +653 -0
  167. package/src/components/Slider/Slider.tsx +303 -0
  168. package/src/components/Slider/__snapshots__/Slider.test.tsx.snap +1946 -0
  169. package/src/components/StyleGuide/Bidirectionality.stories.mdx +1 -1
  170. package/src/components/StyleGuide/Breakpoints.stories.mdx +21 -7
  171. package/src/components/StyleGuide/Buttons.stories.mdx +69 -15
  172. package/src/components/StyleGuide/ColorCard.tsx +0 -1
  173. package/src/components/StyleGuide/DesignTokens.stories.mdx +170 -0
  174. package/src/components/StyleGuide/Iconography.stories.mdx +51 -62
  175. package/src/components/Tabs/Tabs.tsx +5 -5
  176. package/src/components/Template/Template.stories.mdx +11 -16
  177. package/src/components/TextInput/TextInput.stories.mdx +1 -1
  178. package/src/components/TextInput/TextInput.tsx +23 -6
  179. package/src/components/TextInput/TextInputTypes.tsx +2 -0
  180. package/src/components/VideoPlayer/VideoPlayer.stories.mdx +2 -3
  181. package/src/docs/Chakra.stories.mdx +2 -2
  182. package/src/index.ts +20 -12
  183. package/src/resources.scss +5 -5
  184. package/src/styles/base/{_02-breakpoints.scss → _01-breakpoints.scss} +9 -10
  185. package/src/styles/base/{_03-mixins.scss → _02-mixins.scss} +16 -5
  186. package/src/styles/base/{_04-base.scss → _03-base.scss} +7 -2
  187. package/src/styles/base/{_05-focus.scss → _04-focus.scss} +0 -15
  188. package/src/styles/base/_place-holder.scss +14 -3
  189. package/src/styles/{03-space → space}/_space-inline.scss +14 -14
  190. package/src/styles/{03-space → space}/_space-inset.scss +10 -10
  191. package/src/styles/space/_space-stack.scss +116 -0
  192. package/src/styles.scss +13 -55
  193. package/src/theme/components/breadcrumb.ts +10 -0
  194. package/src/theme/components/button.ts +18 -12
  195. package/src/theme/components/card.ts +174 -0
  196. package/src/theme/components/checkbox.ts +7 -2
  197. package/src/theme/components/checkboxGroup.ts +8 -0
  198. package/src/theme/components/datePicker.ts +17 -0
  199. package/src/theme/components/fieldset.ts +18 -0
  200. package/src/theme/components/global.ts +26 -15
  201. package/src/theme/components/globalMixins.ts +9 -1
  202. package/src/theme/components/heading.ts +5 -0
  203. package/src/theme/components/image.ts +116 -0
  204. package/src/theme/components/label.ts +3 -10
  205. package/src/theme/components/link.ts +4 -0
  206. package/src/theme/components/list.ts +6 -3
  207. package/src/theme/components/notification.ts +12 -14
  208. package/src/theme/components/pagination.ts +20 -0
  209. package/src/theme/components/progressIndicator.ts +62 -0
  210. package/src/theme/components/radioGroup.ts +8 -0
  211. package/src/theme/components/select.ts +5 -2
  212. package/src/theme/components/skeletonLoader.ts +107 -0
  213. package/src/theme/components/slider.ts +79 -0
  214. package/src/theme/components/textInput.ts +2 -0
  215. package/src/theme/foundations/breakpoints.ts +8 -8
  216. package/src/theme/foundations/global.ts +6 -1
  217. package/src/theme/index.ts +22 -4
  218. package/src/utils/componentCategories.ts +4 -3
  219. package/dist/components/Image/Image.stories.d.ts +0 -18
  220. package/dist/theme/components/customCheckboxGroup.d.ts +0 -18
  221. package/dist/theme/components/customRadioGroup.d.ts +0 -18
  222. package/src/components/Button/_Button.scss +0 -32
  223. package/src/components/Card/_Card.scss +0 -308
  224. package/src/components/Image/Image.stories.tsx +0 -54
  225. package/src/components/Image/_Image.scss +0 -38
  226. package/src/components/Pagination/_Pagination.scss +0 -40
  227. package/src/components/SkeletonLoader/_SkeletonLoader.scss +0 -142
  228. package/src/styles/01-colors/_colors-brand.scss +0 -62
  229. package/src/styles/01-colors/_colors-utility.scss +0 -67
  230. package/src/styles/02-typography/_type-scale.css +0 -11
  231. package/src/styles/02-typography/_type-weight.css +0 -7
  232. package/src/styles/02-typography/_typefaces.css +0 -4
  233. package/src/styles/03-space/_space-stack.scss +0 -116
  234. package/src/styles/03-space/_space.css +0 -30
  235. package/src/styles/base/_card-grid.scss +0 -77
  236. package/src/styles/base/_typography.scss +0 -11
  237. package/src/theme/components/customCheckboxGroup.ts +0 -12
  238. package/src/theme/components/customRadioGroup.ts +0 -12
@@ -19,12 +19,13 @@ const optionsGroup = [
19
19
  "Villagers",
20
20
  ];
21
21
  const selectProps = {
22
- name: "nhItemSearch",
22
+ name: "selectName",
23
23
  labelText: "Select a category",
24
24
  optionsData: optionsGroup,
25
25
  };
26
26
  const textInputProps = {
27
27
  labelText: "Item Search",
28
+ name: "textInputName",
28
29
  placeholder: "Item Search",
29
30
  };
30
31
  const helperErrorText = "Search for items in Animal Crossing New Horizons";
@@ -34,13 +35,13 @@ describe("SearchBar Accessibility", () => {
34
35
  it("passes axe accessibility test", async () => {
35
36
  const { container } = render(
36
37
  <SearchBar
38
+ helperErrorText={helperErrorText}
37
39
  id="id"
40
+ invalidText={invalidText}
38
41
  labelText="Searchbar"
39
42
  onSubmit={jest.fn()}
40
43
  selectProps={selectProps}
41
44
  textInputProps={textInputProps}
42
- helperErrorText={helperErrorText}
43
- invalidText={invalidText}
44
45
  />
45
46
  );
46
47
  expect(await axe(container)).toHaveNoViolations();
@@ -54,11 +55,11 @@ describe("SearchBar", () => {
54
55
  it("renders the basic form", () => {
55
56
  render(
56
57
  <SearchBar
58
+ helperErrorText={helperErrorText}
57
59
  id="id"
58
60
  labelText="searchbar"
59
61
  onSubmit={searchBarSubmit}
60
62
  textInputProps={textInputProps}
61
- helperErrorText={helperErrorText}
62
63
  />
63
64
  );
64
65
  expect(screen.getByRole("search")).toBeInTheDocument();
@@ -73,12 +74,12 @@ describe("SearchBar", () => {
73
74
  it("renders an optional Select component", () => {
74
75
  render(
75
76
  <SearchBar
77
+ helperErrorText={helperErrorText}
76
78
  id="id"
77
79
  labelText="searchbar"
78
80
  onSubmit={searchBarSubmit}
79
81
  selectProps={selectProps}
80
82
  textInputProps={textInputProps}
81
- helperErrorText={helperErrorText}
82
83
  />
83
84
  );
84
85
  expect(screen.getByRole("combobox")).toBeInTheDocument();
@@ -88,14 +89,14 @@ describe("SearchBar", () => {
88
89
  it("renders the invalid text in the invalid state", () => {
89
90
  render(
90
91
  <SearchBar
92
+ helperErrorText={helperErrorText}
91
93
  id="id"
94
+ invalidText={invalidText}
95
+ isInvalid
92
96
  labelText="searchbar"
93
97
  onSubmit={searchBarSubmit}
94
98
  selectProps={selectProps}
95
99
  textInputProps={textInputProps}
96
- helperErrorText={helperErrorText}
97
- invalidText={invalidText}
98
- isInvalid
99
100
  />
100
101
  );
101
102
  expect(screen.getByText(invalidText)).toBeInTheDocument();
@@ -105,14 +106,14 @@ describe("SearchBar", () => {
105
106
  it("does not render the default invalid text from the Select or TextInput components", () => {
106
107
  render(
107
108
  <SearchBar
109
+ helperErrorText={helperErrorText}
108
110
  id="id"
111
+ invalidText={invalidText}
112
+ isInvalid
109
113
  labelText="searchbar"
110
114
  onSubmit={searchBarSubmit}
111
115
  selectProps={selectProps}
112
116
  textInputProps={textInputProps}
113
- helperErrorText={helperErrorText}
114
- invalidText={invalidText}
115
- isInvalid
116
117
  />
117
118
  );
118
119
  expect(
@@ -123,12 +124,12 @@ describe("SearchBar", () => {
123
124
  it("calls the callback function on submit ", () => {
124
125
  render(
125
126
  <SearchBar
126
- labelText="searchBar"
127
+ helperErrorText={helperErrorText}
127
128
  id="id"
129
+ labelText="searchBar"
128
130
  onSubmit={searchBarSubmit}
129
131
  selectProps={selectProps}
130
132
  textInputProps={textInputProps}
131
- helperErrorText={helperErrorText}
132
133
  />
133
134
  );
134
135
  expect(searchBarSubmit).toHaveBeenCalledTimes(0);
@@ -138,34 +139,65 @@ describe("SearchBar", () => {
138
139
  expect(buttonCallback).toHaveBeenCalledTimes(1);
139
140
  });
140
141
 
142
+ it("Renders 'required' in the placeholder text", () => {
143
+ const { rerender } = render(
144
+ <SearchBar
145
+ id="requiredState"
146
+ isDisabled
147
+ isRequired
148
+ labelText="searchbar"
149
+ onSubmit={jest.fn()}
150
+ textInputProps={textInputProps}
151
+ />
152
+ );
153
+
154
+ expect(
155
+ screen.getByPlaceholderText("Item Search (Required)")
156
+ ).not.toBeInTheDocument();
157
+
158
+ rerender(
159
+ <SearchBar
160
+ id="requiredState"
161
+ isDisabled
162
+ isRequired
163
+ labelText="searchbar"
164
+ onSubmit={jest.fn()}
165
+ textInputProps={textInputProps}
166
+ />
167
+ );
168
+ expect(
169
+ screen.getByPlaceholderText("Item Search (Required)")
170
+ ).toBeInTheDocument();
171
+ });
172
+
141
173
  it("Renders the UI snapshot correctly", () => {
142
174
  const basic = renderer
143
175
  .create(
144
176
  <SearchBar
145
- id="id"
177
+ helperErrorText={helperErrorText}
178
+ id="basic"
146
179
  labelText="searchbar"
147
180
  onSubmit={jest.fn()}
148
181
  textInputProps={textInputProps}
149
- helperErrorText={helperErrorText}
150
182
  />
151
183
  )
152
184
  .toJSON();
153
185
  const withSelect = renderer
154
186
  .create(
155
187
  <SearchBar
156
- id="id"
188
+ helperErrorText={helperErrorText}
189
+ id="withSelect"
157
190
  labelText="searchbar"
158
191
  onSubmit={jest.fn()}
159
192
  selectProps={selectProps}
160
193
  textInputProps={textInputProps}
161
- helperErrorText={helperErrorText}
162
194
  />
163
195
  )
164
196
  .toJSON();
165
197
  const withoutHelperText = renderer
166
198
  .create(
167
199
  <SearchBar
168
- id="id"
200
+ id="withoutHelperText"
169
201
  labelText="searchbar"
170
202
  onSubmit={jest.fn()}
171
203
  textInputProps={textInputProps}
@@ -175,22 +207,34 @@ describe("SearchBar", () => {
175
207
  const invalidState = renderer
176
208
  .create(
177
209
  <SearchBar
178
- id="id"
210
+ id="invalidState"
211
+ isInvalid
179
212
  labelText="searchbar"
180
213
  onSubmit={jest.fn()}
181
214
  textInputProps={textInputProps}
182
- isInvalid
183
215
  />
184
216
  )
185
217
  .toJSON();
186
218
  const disabledState = renderer
187
219
  .create(
188
220
  <SearchBar
189
- id="id"
221
+ id="disabledState"
222
+ isDisabled
190
223
  labelText="searchbar"
191
224
  onSubmit={jest.fn()}
192
225
  textInputProps={textInputProps}
226
+ />
227
+ )
228
+ .toJSON();
229
+ const requiredState = renderer
230
+ .create(
231
+ <SearchBar
232
+ id="requiredState"
193
233
  isDisabled
234
+ isRequired
235
+ labelText="searchbar"
236
+ onSubmit={jest.fn()}
237
+ textInputProps={textInputProps}
194
238
  />
195
239
  )
196
240
  .toJSON();
@@ -200,5 +244,6 @@ describe("SearchBar", () => {
200
244
  expect(withoutHelperText).toMatchSnapshot();
201
245
  expect(invalidState).toMatchSnapshot();
202
246
  expect(disabledState).toMatchSnapshot();
247
+ expect(requiredState).toMatchSnapshot();
203
248
  });
204
249
  });
@@ -19,8 +19,7 @@ import DSProvider from "../../theme/provider";
19
19
  parameters={{
20
20
  design: {
21
21
  type: "figma",
22
- url:
23
- "https://www.figma.com/file/qShodlfNCJHb8n03IFyApM/Master?node-id=11689%3A423",
22
+ url: "https://www.figma.com/file/qShodlfNCJHb8n03IFyApM/Master?node-id=11689%3A423",
24
23
  },
25
24
  jest: ["SearchBar.test.tsx"],
26
25
  }}
@@ -40,6 +39,11 @@ import DSProvider from "../../theme/provider";
40
39
 
41
40
  # SearchBar
42
41
 
42
+ | Component Version | DS Version |
43
+ | ----------------- | ---------- |
44
+ | Added | `0.0.4` |
45
+ | Latest | `0.25.6` |
46
+
43
47
  <Description of={SearchBar} />
44
48
 
45
49
  The main wrapper element that is rendered is a `<form>` DOM element. All the
@@ -51,6 +55,9 @@ based on the required props.
51
55
  The `Select` dropdown narrows the search within a specific category, typically
52
56
  title or author. Toggle the `Select` through the Controls.
53
57
 
58
+ Note: The labels for the `Select` and `TextInput` components are not visible but
59
+ aria-labels are used to make these children components accessible.
60
+
54
61
  export const optionsGroup = [
55
62
  "Art",
56
63
  "Bushes",
@@ -68,13 +75,13 @@ export const optionsGroup = [
68
75
  <Story
69
76
  name="Basic"
70
77
  args={{
71
- showHelperText: true,
72
- showSelect: true,
78
+ helperErrorText: "Search for items in Animal Crossing New Horizons",
73
79
  invalidText: "Could not find the item :(",
74
80
  isDisabled: false,
75
81
  isInvalid: false,
76
82
  isRequired: false,
77
- helperErrorText: "Search for items in Animal Crossing New Horizons",
83
+ showHelperText: true,
84
+ showSelect: true,
78
85
  }}
79
86
  >
80
87
  {(args) => (
@@ -83,13 +90,14 @@ export const optionsGroup = [
83
90
  {...args}
84
91
  selectProps={
85
92
  args.showSelect && {
86
- name: "nhItemSearch",
87
93
  labelText: "Select a category",
94
+ name: "selectName",
88
95
  optionsData: optionsGroup,
89
96
  }
90
97
  }
91
98
  textInputProps={{
92
99
  labelText: "Item Search",
100
+ name: "textInputName",
93
101
  placeholder: "Item Search",
94
102
  }}
95
103
  helperErrorText={args.showHelperText && args.helperErrorText}
@@ -127,14 +135,19 @@ const selectProps = {
127
135
  ### TextInput Component
128
136
 
129
137
  To render the `TextInput` component, an object must be passed to the
130
- `textInputProps` prop. It _must_ include `labelText` and `placeholder`
138
+ `textInputProps` prop. It _must_ include `labelText`, `name`, and `placeholder`
131
139
  properties. The `labelText` value won't be rendered but will be used for its
132
- `aria-label` attribute.
140
+ `aria-label` attribute. Optional values to pass include `onChange` and `value`.
133
141
 
134
142
  ```
135
143
  const textInputProps = {
136
144
  labelText: "Item Search",
145
+ name: "textInputName",
146
+ onChange: (event) => {
147
+ console.log(event.target.value);
148
+ },
137
149
  placeholder: "Item Search",
150
+ value: "Horizon"
138
151
  };
139
152
 
140
153
  // ...
@@ -202,8 +215,8 @@ precedence.
202
215
  <Story
203
216
  name="Search Autocomplete"
204
217
  args={{
205
- isInvalid: false,
206
218
  isDisabled: false,
219
+ isInvalid: false,
207
220
  isRequired: false,
208
221
  }}
209
222
  >
@@ -237,9 +250,10 @@ handle the error state yourself.
237
250
  onSubmit={() => {}}
238
251
  textInputProps={{
239
252
  labelText: "Item Search",
253
+ name: "textInputName",
240
254
  placeholder: "Item Search",
241
255
  }}
242
- helperErrorText="Sorry, we can't find that item!"
256
+ helperErrorText="This is the helper text!"
243
257
  invalidText="Could not find the item :("
244
258
  isInvalid
245
259
  />
@@ -258,6 +272,7 @@ handle the disabled state yourself.
258
272
  obSubmit={() => {}}
259
273
  textInputProps={{
260
274
  labelText: "Item Search",
275
+ name: "textInputName",
261
276
  placeholder: "Item Search",
262
277
  }}
263
278
  helperErrorText="Reason for disabled state."
@@ -265,3 +280,92 @@ handle the disabled state yourself.
265
280
  />
266
281
  </DSProvider>
267
282
  </Canvas>
283
+
284
+ ### TextInput and onSubmit Values
285
+
286
+ _NOTE: open the browser console to see the values logged in the example below._
287
+
288
+ It is possible to get certain values from the `SearchBar` component by passing
289
+ callback functions as props.
290
+
291
+ The keyword value in the `TextInput` component can be accessed by passing a
292
+ function to the `onChange` property in the `textInputProp` prop. This is useful
293
+ for validating the keyword the user entered.
294
+
295
+ To get values when the form is submitted, you must:
296
+
297
+ - pass values for the `name` property in the `selectProps` and `textInputProps`
298
+ prop objects.
299
+ - get the values returned in the `onSubmit` callback function.
300
+
301
+ In the following example, the `name` for the `Select` is "selectName" and the
302
+ `name` for the `TextInput` is "textInputName". The `onSubmit` function can get
303
+ the submitted values through the `event` object. In the example below, the
304
+ values can be retrieved as `event.target.selectName.value` and
305
+ `event.target.textInputName.value`.
306
+
307
+ ```tsx
308
+ function SearchBarValueExample() {
309
+ const textInputOnChange = (event) => {
310
+ console.log(`onChange TextInput value: ${event.target.value}`);
311
+ };
312
+ const onSubmit = (event) => {
313
+ event.preventDefault();
314
+ console.log(`onSubmit Select value: ${event.target.searchName.value}`);
315
+ console.log(`onSubmit TextInput value ${event.target.textInputName.value}`);
316
+ };
317
+ return (
318
+ <SearchBar
319
+ onSubmit={onSubmit}
320
+ selectProps={{
321
+ labelText: "Select a category",
322
+ name: "selectName",
323
+ optionsData: optionsGroup,
324
+ }}
325
+ textInputProps={{
326
+ labelText: "Item Search",
327
+ name: "textInputName",
328
+ onChange: textInputOnChange,
329
+ placeholder: "Item Search",
330
+ }}
331
+ helperErrorText="Search for an item"
332
+ invalidText="Could not find the item :("
333
+ />
334
+ );
335
+ }
336
+ ```
337
+
338
+ export function SearchBarValueExample() {
339
+ const textInputOnChange = (event) => {
340
+ console.log(`onChange TextInput value: ${event.target.value}`);
341
+ };
342
+ const onSubmit = (event) => {
343
+ event.preventDefault();
344
+ console.log(`onSubmit Select value: ${event.target.selectName.value}`);
345
+ console.log(`onSubmit TextInput value ${event.target.textInputName.value}`);
346
+ };
347
+ return (
348
+ <SearchBar
349
+ onSubmit={onSubmit}
350
+ selectProps={{
351
+ labelText: "Select a category",
352
+ name: "selectName",
353
+ optionsData: optionsGroup,
354
+ }}
355
+ textInputProps={{
356
+ labelText: "Item Search",
357
+ name: "textInputName",
358
+ onChange: textInputOnChange,
359
+ placeholder: "Item Search",
360
+ }}
361
+ helperErrorText="Search for an item"
362
+ invalidText="Could not find the item :("
363
+ />
364
+ );
365
+ }
366
+
367
+ <Canvas>
368
+ <DSProvider>
369
+ <SearchBarValueExample />
370
+ </DSProvider>
371
+ </Canvas>
@@ -20,7 +20,14 @@ interface SelectProps {
20
20
  }
21
21
  interface TextInputProps {
22
22
  labelText: string;
23
+ name: string;
24
+ onChange?: (
25
+ event:
26
+ | React.ChangeEvent<HTMLInputElement>
27
+ | React.ChangeEvent<HTMLTextAreaElement>
28
+ ) => void;
23
29
  placeholder: string;
30
+ value?: string;
24
31
  }
25
32
 
26
33
  export interface SearchBarProps {
@@ -51,9 +58,6 @@ export interface SearchBarProps {
51
58
  onSubmit: (event: React.FormEvent) => void;
52
59
  /** Required props to render a `Select` element. */
53
60
  selectProps?: SelectProps | undefined;
54
- /** Will be used to visually display the label text for this
55
- * `SearchBar` component. False by default. */
56
- showLabel?: boolean;
57
61
  /** Custom input element to render instead of a `TextInput` element. */
58
62
  textInputElement?: JSX.Element;
59
63
  /** Required props to render a `TextInput` element. */
@@ -95,6 +99,9 @@ export default function SearchBar(props: SearchBarProps) {
95
99
  const ariaDescribedby = helperErrorTextID;
96
100
  const footnote = isInvalid ? invalidText : helperErrorText;
97
101
  const finalAriaLabel = footnote ? `${labelText} - ${footnote}` : labelText;
102
+ const textInputPlaceholder = `${textInputProps?.placeholder} ${
103
+ isRequired ? "(Required)" : ""
104
+ }`;
98
105
  // Render the `Select` component.
99
106
  const selectElem = selectProps && (
100
107
  <Select
@@ -116,13 +123,16 @@ export default function SearchBar(props: SearchBarProps) {
116
123
  <TextInput
117
124
  id={generateUUID()}
118
125
  labelText={textInputProps?.labelText}
119
- placeholder={textInputProps?.placeholder}
126
+ placeholder={textInputPlaceholder}
127
+ onChange={textInputProps?.onChange}
128
+ name={textInputProps?.name}
120
129
  type={TextInputTypes.text}
121
130
  variantType={
122
131
  selectElem
123
132
  ? TextInputVariants.SearchBarSelect
124
133
  : TextInputVariants.SearchBar
125
134
  }
135
+ value={textInputProps?.value}
126
136
  {...stateProps}
127
137
  />
128
138
  );
@@ -133,7 +143,7 @@ export default function SearchBar(props: SearchBarProps) {
133
143
  buttonType={ButtonTypes.SearchBar}
134
144
  type="submit"
135
145
  onClick={buttonOnClick}
136
- disabled={isDisabled}
146
+ isDisabled={isDisabled}
137
147
  >
138
148
  <Icon
139
149
  name={IconNames.Search}
@@ -1,3 +1,4 @@
1
+ // Only used for internal purposes.
1
2
  export enum SelectTypes {
2
3
  Default = "default",
3
4
  SearchBar = "searchbar",
@@ -3,18 +3,18 @@ import {
3
3
  Story,
4
4
  Canvas,
5
5
  ArgsTable,
6
- Preview,
7
6
  Description,
8
7
  } from "@storybook/addon-docs/blocks";
9
8
  import { withDesign } from "storybook-addon-designs";
9
+ import { action } from "@storybook/addon-actions";
10
10
 
11
+ import { getCategory } from "../../utils/componentCategories";
11
12
  import SkeletonLoader from "./SkeletonLoader";
12
13
  import {
13
14
  SkeletonLoaderLayouts,
14
15
  SkeletonLoaderImageRatios,
15
16
  } from "./SkeletonLoaderTypes";
16
- import { action } from "@storybook/addon-actions";
17
- import { getCategory } from "../../utils/componentCategories";
17
+ import SimpleGrid from "../Grid/SimpleGrid";
18
18
 
19
19
  <Meta
20
20
  title={getCategory("SkeletonLoader")}
@@ -29,33 +29,15 @@ import { getCategory } from "../../utils/componentCategories";
29
29
  jest: ["SkeletonLoader.test.tsx"],
30
30
  }}
31
31
  argTypes={{
32
- attributes: { table: { disable: true } },
33
32
  className: { table: { disable: true } },
34
- modifiers: { table: { disable: true } },
35
- layout: {
36
- table: { defaultValue: { summary: "column" } },
37
- },
38
- showImage: {
39
- table: { defaultValue: { summary: "true" } },
40
- },
41
- showHeading: {
42
- table: { defaultValue: { summary: "true" } },
43
- },
44
- showContent: {
45
- table: { defaultValue: { summary: "true" } },
46
- },
47
- showButton: {
48
- table: { defaultValue: { summary: "false" } },
49
- },
50
- headingSize: {
51
- table: { defaultValue: { summary: "1" } },
52
- },
53
- contentSize: {
54
- table: { defaultValue: { summary: "3" } },
55
- },
56
- imageAspectRatio: {
57
- table: { defaultValue: { summary: "square" } },
58
- },
33
+ contentSize: { table: { defaultValue: { summary: "3" } } },
34
+ headingSize: { table: { defaultValue: { summary: "1" } } },
35
+ imageAspectRatio: { table: { defaultValue: { summary: "square" } } },
36
+ layout: { table: { defaultValue: { summary: "column" } } },
37
+ showButton: { table: { defaultValue: { summary: "false" } } },
38
+ showContent: { table: { defaultValue: { summary: "true" } } },
39
+ showHeading: { table: { defaultValue: { summary: "true" } } },
40
+ showImage: { table: { defaultValue: { summary: "true" } } },
59
41
  }}
60
42
  />
61
43
 
@@ -64,41 +46,34 @@ import { getCategory } from "../../utils/componentCategories";
64
46
  | Component Version | DS Version |
65
47
  | ----------------- | ---------- |
66
48
  | Added | `0.17.3` |
67
- | Latest | `0.23.4` |
49
+ | Latest | `0.25.3` |
68
50
 
69
51
  <Description of={SkeletonLoader} />
70
52
 
71
- The `SkeletonLoader` component renders a placeholder to be used while dynamic
72
- content is loading. The `layout`, `width` and placeholder elements within the
73
- `SkeletonLoader` can be customized.
53
+ The `layout`, `width`, and placeholder elements within the `SkeletonLoader` can
54
+ be customized.
74
55
 
75
- Please note that the initial rendering below has the `width` prop set to `300px`.
76
- The default value is `100%`.
56
+ Please note that the initial rendering below has the `width` prop set to `300px`
57
+ to better view the example. The default value is `100%`.
77
58
 
78
- <Preview withToolbar>
59
+ <Canvas withToolbar>
79
60
  <Story
80
- name="SkeletonLoader"
61
+ name="Basic with Props"
81
62
  args={{
82
63
  width: "300px",
83
64
  }}
84
65
  >
85
66
  {(args) => <SkeletonLoader {...args} />}
86
67
  </Story>
87
- </Preview>
68
+ </Canvas>
88
69
 
89
- <ArgsTable story="SkeletonLoader" />
70
+ <ArgsTable story="Basic with Props" />
90
71
 
91
72
  # Card Placeholders in a Grid
92
73
 
93
- <Preview>
74
+ <Canvas>
94
75
  <Story name="Placeholders in a Grid">
95
- <div
96
- style={{
97
- display: "grid",
98
- gap: "2rem",
99
- gridTemplateColumns: "repeat(3, 1fr)",
100
- }}
101
- >
76
+ <SimpleGrid columns={3}>
102
77
  <SkeletonLoader
103
78
  imageAspectRatio={SkeletonLoaderImageRatios.Landscape}
104
79
  border
@@ -123,26 +98,20 @@ The default value is `100%`.
123
98
  imageAspectRatio={SkeletonLoaderImageRatios.Landscape}
124
99
  border
125
100
  />
126
- </div>
101
+ </SimpleGrid>
127
102
  </Story>
128
- </Preview>
103
+ </Canvas>
129
104
 
130
105
  # Text Placeholders in a List
131
106
 
132
- <Preview>
107
+ <Canvas>
133
108
  <Story name="Placeholders in a List">
134
- <div
135
- style={{
136
- display: "grid",
137
- gap: "2rem",
138
- gridTemplateColumns: "repeat(1, 1fr)",
139
- }}
140
- >
109
+ <SimpleGrid columns={1}>
141
110
  <SkeletonLoader layout={SkeletonLoaderLayouts.Row} showImage={false} />
142
111
  <SkeletonLoader layout={SkeletonLoaderLayouts.Row} showImage={false} />
143
112
  <SkeletonLoader layout={SkeletonLoaderLayouts.Row} showImage={false} />
144
113
  <SkeletonLoader layout={SkeletonLoaderLayouts.Row} showImage={false} />
145
114
  <SkeletonLoader layout={SkeletonLoaderLayouts.Row} showImage={false} />
146
- </div>
115
+ </SimpleGrid>
147
116
  </Story>
148
- </Preview>
117
+ </Canvas>