@nypl/design-system-react-components 0.27.0 → 0.28.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 (298) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/components/Accordion/Accordion.d.ts +1 -1
  3. package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +1 -5
  4. package/dist/components/Button/Button.d.ts +2 -10
  5. package/dist/components/ButtonGroup/ButtonGroup.d.ts +22 -0
  6. package/dist/components/Card/Card.d.ts +2 -2
  7. package/dist/components/Checkbox/Checkbox.d.ts +10 -8
  8. package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +1 -1
  9. package/dist/components/DatePicker/DatePicker.d.ts +1 -1
  10. package/dist/components/Form/Form.d.ts +2 -2
  11. package/dist/components/Grid/SimpleGrid.d.ts +6 -3
  12. package/dist/components/Heading/Heading.d.ts +2 -5
  13. package/dist/components/HelperErrorText/HelperErrorText.d.ts +1 -5
  14. package/dist/components/Hero/Hero.d.ts +13 -9
  15. package/dist/components/Icons/Icon.d.ts +6 -5
  16. package/dist/components/Icons/IconSvgs.d.ts +21 -21
  17. package/dist/components/Image/Image.d.ts +8 -5
  18. package/dist/components/Link/Link.d.ts +1 -9
  19. package/dist/components/List/List.d.ts +7 -11
  20. package/dist/components/Logo/Logo.d.ts +2 -5
  21. package/dist/components/Logo/LogoSvgs.d.ts +39 -39
  22. package/dist/components/Notification/Notification.d.ts +1 -1
  23. package/dist/components/ProgressIndicator/ProgressIndicator.d.ts +2 -1
  24. package/dist/components/RadioGroup/RadioGroup.d.ts +1 -1
  25. package/dist/components/SearchBar/SearchBar.d.ts +3 -2
  26. package/dist/components/Select/Select.d.ts +2 -5
  27. package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +4 -4
  28. package/dist/components/SkipNavigation/SkipNavigation.d.ts +17 -0
  29. package/dist/components/StatusBadge/StatusBadge.d.ts +2 -3
  30. package/dist/components/StructuredContent/StructuredContent.d.ts +2 -2
  31. package/dist/components/Table/Table.d.ts +1 -1
  32. package/dist/components/Template/Template.d.ts +2 -0
  33. package/dist/components/Text/Text.d.ts +1 -1
  34. package/dist/components/TextInput/TextInput.d.ts +21 -9
  35. package/dist/components/Toggle/Toggle.d.ts +1 -5
  36. package/dist/components/VideoPlayer/VideoPlayer.d.ts +2 -1
  37. package/dist/design-system-react-components.cjs.development.js +856 -1155
  38. package/dist/design-system-react-components.cjs.development.js.map +1 -1
  39. package/dist/design-system-react-components.cjs.production.min.js +1 -1
  40. package/dist/design-system-react-components.cjs.production.min.js.map +1 -1
  41. package/dist/design-system-react-components.esm.js +858 -1220
  42. package/dist/design-system-react-components.esm.js.map +1 -1
  43. package/dist/helpers/types.d.ts +1 -0
  44. package/dist/index.d.ts +26 -47
  45. package/dist/theme/components/buttonGroup.d.ts +11 -0
  46. package/dist/theme/components/card.d.ts +104 -8
  47. package/dist/theme/components/componentWrapper.d.ts +4 -3
  48. package/dist/theme/components/customTable.d.ts +11 -14
  49. package/dist/theme/components/fieldset.d.ts +4 -3
  50. package/dist/theme/components/helperErrorText.d.ts +4 -3
  51. package/dist/theme/components/hero.d.ts +1 -1
  52. package/dist/theme/components/horizontalRule.d.ts +4 -3
  53. package/dist/theme/components/icon.d.ts +47743 -1
  54. package/dist/theme/components/image.d.ts +563 -10
  55. package/dist/theme/components/label.d.ts +4 -3
  56. package/dist/theme/components/list.d.ts +6 -7
  57. package/dist/theme/components/logo.d.ts +474 -1
  58. package/dist/theme/components/notification.d.ts +20 -16
  59. package/dist/theme/components/progressIndicator.d.ts +6 -4
  60. package/dist/theme/components/select.d.ts +4 -4
  61. package/dist/theme/components/skeletonLoader.d.ts +14 -10
  62. package/dist/theme/components/skipNavigation.d.ts +22 -0
  63. package/dist/theme/components/slider.d.ts +7 -6
  64. package/dist/theme/components/structuredContent.d.ts +10 -9
  65. package/dist/theme/components/text.d.ts +7 -1
  66. package/dist/theme/components/toggle.d.ts +6 -4
  67. package/dist/theme/provider.d.ts +2 -4
  68. package/dist/utils/componentCategories.d.ts +1 -1
  69. package/dist/utils/interfaces.d.ts +5 -0
  70. package/dist/utils/utils.d.ts +2 -18
  71. package/package.json +2 -2
  72. package/src/__tests__/setup.ts +3 -3
  73. package/src/__tests__/utils/utils.test.ts +1 -23
  74. package/src/components/AccessibilityGuide/SkipNavigation.stories.mdx +22 -14
  75. package/src/components/Accordion/Accordion.stories.mdx +43 -44
  76. package/src/components/Accordion/Accordion.test.tsx +5 -13
  77. package/src/components/Accordion/Accordion.tsx +14 -18
  78. package/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap +6 -6
  79. package/src/components/Autosuggest/Autosuggest.stories.mdx +1 -1
  80. package/src/components/Autosuggest/Autosuggest.stories.tsx +23 -25
  81. package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +21 -37
  82. package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +4 -17
  83. package/src/components/Breadcrumbs/Breadcrumbs.tsx +18 -21
  84. package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +1 -100
  85. package/src/components/Button/Button.stories.mdx +89 -126
  86. package/src/components/Button/Button.test.tsx +16 -30
  87. package/src/components/Button/Button.tsx +14 -20
  88. package/src/components/ButtonGroup/ButtonGroup.stories.mdx +147 -0
  89. package/src/components/ButtonGroup/ButtonGroup.test.tsx +141 -0
  90. package/src/components/ButtonGroup/ButtonGroup.tsx +99 -0
  91. package/src/components/ButtonGroup/__snapshots__/ButtonGroup.test.tsx.snap +117 -0
  92. package/src/components/Card/Card.stories.mdx +143 -177
  93. package/src/components/Card/Card.test.tsx +36 -97
  94. package/src/components/Card/Card.tsx +78 -74
  95. package/src/components/Chakra/Box.stories.mdx +2 -6
  96. package/src/components/Chakra/Center.stories.mdx +5 -23
  97. package/src/components/Chakra/Flex.stories.mdx +4 -6
  98. package/src/components/Chakra/Stack.stories.mdx +9 -10
  99. package/src/components/Checkbox/Checkbox.stories.mdx +1 -1
  100. package/src/components/Checkbox/Checkbox.test.tsx +2 -2
  101. package/src/components/Checkbox/Checkbox.tsx +20 -13
  102. package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +6 -17
  103. package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +1 -7
  104. package/src/components/CheckboxGroup/CheckboxGroup.tsx +33 -29
  105. package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +0 -11
  106. package/src/components/ComponentWrapper/ComponentWrapper.tsx +3 -10
  107. package/src/components/DatePicker/DatePicker.stories.mdx +23 -37
  108. package/src/components/DatePicker/DatePicker.test.tsx +21 -19
  109. package/src/components/DatePicker/DatePicker.tsx +57 -49
  110. package/src/components/Form/Form.stories.mdx +46 -31
  111. package/src/components/Form/Form.test.tsx +1 -18
  112. package/src/components/Form/Form.tsx +7 -7
  113. package/src/components/Grid/SimpleGrid.stories.mdx +73 -49
  114. package/src/components/Grid/SimpleGrid.test.tsx +7 -9
  115. package/src/components/Grid/SimpleGrid.tsx +14 -11
  116. package/src/components/Heading/Heading.stories.mdx +27 -72
  117. package/src/components/Heading/Heading.test.tsx +18 -44
  118. package/src/components/Heading/Heading.tsx +7 -10
  119. package/src/components/HelperErrorText/HelperErrorText.stories.mdx +1 -3
  120. package/src/components/HelperErrorText/HelperErrorText.tsx +1 -5
  121. package/src/components/Hero/Hero.stories.mdx +219 -216
  122. package/src/components/Hero/Hero.test.tsx +107 -223
  123. package/src/components/Hero/Hero.tsx +63 -61
  124. package/src/components/Icons/Icon.stories.mdx +172 -118
  125. package/src/components/Icons/Icon.test.tsx +8 -16
  126. package/src/components/Icons/Icon.tsx +75 -29
  127. package/src/components/Icons/IconSvgs.tsx +42 -42
  128. package/src/components/Image/Image.stories.mdx +45 -132
  129. package/src/components/Image/Image.test.tsx +16 -31
  130. package/src/components/Image/Image.tsx +28 -12
  131. package/src/components/Link/Link.stories.mdx +30 -80
  132. package/src/components/Link/Link.test.tsx +25 -53
  133. package/src/components/Link/Link.tsx +43 -56
  134. package/src/components/Link/__snapshots__/Link.test.tsx.snap +1 -2
  135. package/src/components/List/List.stories.mdx +20 -31
  136. package/src/components/List/List.test.tsx +24 -43
  137. package/src/components/List/List.tsx +25 -36
  138. package/src/components/Logo/Logo.stories.mdx +94 -50
  139. package/src/components/Logo/Logo.test.tsx +10 -19
  140. package/src/components/Logo/Logo.tsx +50 -17
  141. package/src/components/Logo/LogoSvgs.tsx +78 -78
  142. package/src/components/Logo/__snapshots__/Logo.test.tsx.snap +4 -4
  143. package/src/components/Modal/Modal.stories.mdx +8 -9
  144. package/src/components/Modal/Modal.test.tsx +5 -10
  145. package/src/components/Modal/Modal.tsx +1 -1
  146. package/src/components/Notification/Notification.stories.mdx +10 -28
  147. package/src/components/Notification/Notification.test.tsx +9 -12
  148. package/src/components/Notification/Notification.tsx +34 -37
  149. package/src/components/Pagination/Pagination.stories.mdx +2 -2
  150. package/src/components/Pagination/Pagination.tsx +15 -10
  151. package/src/components/ProgressIndicator/ProgressIndicator.stories.mdx +27 -53
  152. package/src/components/ProgressIndicator/ProgressIndicator.test.tsx +9 -10
  153. package/src/components/ProgressIndicator/ProgressIndicator.tsx +17 -21
  154. package/src/components/ProgressIndicator/__snapshots__/ProgressIndicator.test.tsx.snap +0 -10
  155. package/src/components/Radio/Radio.stories.mdx +1 -1
  156. package/src/components/Radio/Radio.tsx +9 -6
  157. package/src/components/RadioGroup/RadioGroup.stories.mdx +15 -16
  158. package/src/components/RadioGroup/RadioGroup.test.tsx +2 -8
  159. package/src/components/RadioGroup/RadioGroup.tsx +28 -24
  160. package/src/components/SearchBar/SearchBar.stories.mdx +1 -1
  161. package/src/components/SearchBar/SearchBar.test.tsx +1 -1
  162. package/src/components/SearchBar/SearchBar.tsx +14 -22
  163. package/src/components/SearchBar/__snapshots__/SearchBar.test.tsx.snap +0 -12
  164. package/src/components/Select/Select.stories.mdx +8 -23
  165. package/src/components/Select/Select.test.tsx +6 -7
  166. package/src/components/Select/Select.tsx +13 -26
  167. package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +17 -56
  168. package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +7 -21
  169. package/src/components/SkeletonLoader/SkeletonLoader.tsx +9 -8
  170. package/src/components/SkeletonLoader/__snapshots__/SkeletonLoader.test.tsx.snap +33 -33
  171. package/src/components/SkipNavigation/SkipNavigation.stories.mdx +90 -0
  172. package/src/components/SkipNavigation/SkipNavigation.test.tsx +63 -0
  173. package/src/components/SkipNavigation/SkipNavigation.tsx +51 -0
  174. package/src/components/SkipNavigation/__snapshots__/SkipNavigation.test.tsx.snap +130 -0
  175. package/src/components/Slider/Slider.stories.mdx +19 -53
  176. package/src/components/Slider/Slider.test.tsx +2 -2
  177. package/src/components/Slider/Slider.tsx +10 -12
  178. package/src/components/Slider/__snapshots__/Slider.test.tsx.snap +2 -9
  179. package/src/components/StatusBadge/StatusBadge.stories.mdx +6 -21
  180. package/src/components/StatusBadge/StatusBadge.test.tsx +2 -3
  181. package/src/components/StatusBadge/StatusBadge.tsx +3 -10
  182. package/src/components/StructuredContent/StructuredContent.stories.mdx +30 -58
  183. package/src/components/StructuredContent/StructuredContent.test.tsx +42 -44
  184. package/src/components/StructuredContent/StructuredContent.tsx +9 -18
  185. package/src/components/StyleGuide/Bidirectionality.stories.mdx +9 -23
  186. package/src/components/StyleGuide/Buttons.stories.mdx +62 -62
  187. package/src/components/StyleGuide/ColorCard.tsx +2 -4
  188. package/src/components/StyleGuide/Colors.stories.mdx +7 -8
  189. package/src/components/StyleGuide/DesignTokens.stories.mdx +5 -7
  190. package/src/components/StyleGuide/Forms.stories.mdx +0 -1
  191. package/src/components/StyleGuide/Iconography.stories.mdx +59 -77
  192. package/src/components/StyleGuide/Spacing.stories.mdx +0 -1
  193. package/src/components/StyleGuide/Typography.stories.mdx +15 -18
  194. package/src/components/Table/Table.stories.mdx +85 -1
  195. package/src/components/Table/Table.test.tsx +57 -1
  196. package/src/components/Table/Table.tsx +7 -4
  197. package/src/components/Table/__snapshots__/Table.test.tsx.snap +121 -0
  198. package/src/components/Tabs/Tabs.stories.mdx +1 -1
  199. package/src/components/Tabs/Tabs.test.tsx +2 -2
  200. package/src/components/Tabs/Tabs.tsx +26 -27
  201. package/src/components/Template/Template.stories.mdx +49 -54
  202. package/src/components/Template/Template.tsx +9 -3
  203. package/src/components/Text/Text.stories.mdx +5 -11
  204. package/src/components/Text/Text.test.tsx +3 -6
  205. package/src/components/Text/Text.tsx +3 -5
  206. package/src/components/TextInput/TextInput.stories.mdx +10 -22
  207. package/src/components/TextInput/TextInput.test.tsx +32 -62
  208. package/src/components/TextInput/TextInput.tsx +61 -30
  209. package/src/components/TextInput/__snapshots__/TextInput.test.tsx.snap +1 -0
  210. package/src/components/Toggle/Toggle.stories.mdx +5 -16
  211. package/src/components/Toggle/Toggle.test.tsx +2 -3
  212. package/src/components/Toggle/Toggle.tsx +9 -10
  213. package/src/components/VideoPlayer/VideoPlayer.stories.mdx +13 -29
  214. package/src/components/VideoPlayer/VideoPlayer.test.tsx +18 -23
  215. package/src/components/VideoPlayer/VideoPlayer.tsx +13 -10
  216. package/src/docs/Chakra.stories.mdx +14 -11
  217. package/src/docs/Welcome.stories.mdx +23 -43
  218. package/src/helpers/types.ts +1 -0
  219. package/src/hooks/tests/useNYPLTheme.test.tsx +1 -1
  220. package/src/hooks/useNYPLTheme.stories.mdx +3 -6
  221. package/src/index.ts +51 -45
  222. package/src/theme/components/buttonGroup.ts +10 -0
  223. package/src/theme/components/card.ts +50 -15
  224. package/src/theme/components/componentWrapper.ts +5 -1
  225. package/src/theme/components/customTable.ts +8 -2
  226. package/src/theme/components/fieldset.ts +5 -1
  227. package/src/theme/components/helperErrorText.ts +5 -1
  228. package/src/theme/components/hero.ts +2 -2
  229. package/src/theme/components/horizontalRule.ts +5 -1
  230. package/src/theme/components/icon.ts +7 -1
  231. package/src/theme/components/image.ts +14 -3
  232. package/src/theme/components/label.ts +5 -1
  233. package/src/theme/components/list.ts +8 -2
  234. package/src/theme/components/logo.ts +5 -1
  235. package/src/theme/components/notification.ts +38 -14
  236. package/src/theme/components/progressIndicator.ts +10 -5
  237. package/src/theme/components/select.ts +5 -2
  238. package/src/theme/components/skeletonLoader.ts +8 -2
  239. package/src/theme/components/skipNavigation.ts +26 -0
  240. package/src/theme/components/slider.ts +13 -1
  241. package/src/theme/components/structuredContent.ts +11 -1
  242. package/src/theme/components/text.ts +12 -5
  243. package/src/theme/components/toggle.ts +9 -3
  244. package/src/theme/index.ts +4 -0
  245. package/src/theme/provider.tsx +1 -1
  246. package/src/utils/componentCategories.ts +13 -5
  247. package/src/utils/interfaces.ts +5 -0
  248. package/src/utils/utils.ts +2 -32
  249. package/dist/components/Accordion/AccordionTypes.d.ts +0 -5
  250. package/dist/components/Breadcrumbs/BreadcrumbsTypes.d.ts +0 -8
  251. package/dist/components/Button/ButtonTypes.d.ts +0 -8
  252. package/dist/components/DatePicker/DatePickerTypes.d.ts +0 -5
  253. package/dist/components/Form/FormTypes.d.ts +0 -2
  254. package/dist/components/Grid/GridTypes.d.ts +0 -9
  255. package/dist/components/Heading/HeadingTypes.d.ts +0 -14
  256. package/dist/components/Hero/HeroTypes.d.ts +0 -12
  257. package/dist/components/Icons/IconTypes.d.ts +0 -77
  258. package/dist/components/Image/ImageTypes.d.ts +0 -22
  259. package/dist/components/Link/LinkTypes.d.ts +0 -8
  260. package/dist/components/List/ListTypes.d.ts +0 -5
  261. package/dist/components/Logo/LogoTypes.d.ts +0 -54
  262. package/dist/components/Notification/NotificationTypes.d.ts +0 -5
  263. package/dist/components/ProgressIndicator/ProgressIndicatorTypes.d.ts +0 -8
  264. package/dist/components/Select/SelectTypes.d.ts +0 -8
  265. package/dist/components/SkeletonLoader/SkeletonLoaderTypes.d.ts +0 -5
  266. package/dist/components/StatusBadge/StatusBadgeTypes.d.ts +0 -5
  267. package/dist/components/StructuredContent/StructuredContentTypes.d.ts +0 -5
  268. package/dist/components/Text/TextTypes.d.ts +0 -6
  269. package/dist/components/TextInput/TextInputTypes.d.ts +0 -25
  270. package/dist/components/Toggle/ToggleTypes.d.ts +0 -4
  271. package/dist/components/VideoPlayer/VideoPlayerTypes.d.ts +0 -9
  272. package/dist/helpers/enums.d.ts +0 -4
  273. package/dist/utils/siteSections.d.ts +0 -2
  274. package/src/components/Accordion/AccordionTypes.tsx +0 -5
  275. package/src/components/Breadcrumbs/BreadcrumbsTypes.tsx +0 -8
  276. package/src/components/Button/ButtonTypes.tsx +0 -8
  277. package/src/components/DatePicker/DatePickerTypes.tsx +0 -5
  278. package/src/components/Form/FormTypes.tsx +0 -3
  279. package/src/components/Grid/GridTypes.tsx +0 -9
  280. package/src/components/Heading/HeadingTypes.tsx +0 -15
  281. package/src/components/Hero/HeroTypes.tsx +0 -20
  282. package/src/components/Icons/IconTypes.tsx +0 -83
  283. package/src/components/Image/ImageTypes.ts +0 -24
  284. package/src/components/Link/LinkTypes.tsx +0 -8
  285. package/src/components/List/ListTypes.tsx +0 -5
  286. package/src/components/Logo/LogoTypes.tsx +0 -56
  287. package/src/components/Notification/NotificationTypes.tsx +0 -5
  288. package/src/components/ProgressIndicator/ProgressIndicatorTypes.ts +0 -8
  289. package/src/components/Select/SelectTypes.tsx +0 -10
  290. package/src/components/SkeletonLoader/SkeletonLoaderTypes.tsx +0 -5
  291. package/src/components/StatusBadge/StatusBadgeTypes.tsx +0 -5
  292. package/src/components/StructuredContent/StructuredContentTypes.tsx +0 -5
  293. package/src/components/Text/TextTypes.tsx +0 -6
  294. package/src/components/TextInput/TextInputTypes.tsx +0 -48
  295. package/src/components/Toggle/ToggleTypes.tsx +0 -4
  296. package/src/components/VideoPlayer/VideoPlayerTypes.tsx +0 -10
  297. package/src/helpers/enums.ts +0 -4
  298. package/src/utils/siteSections.ts +0 -10
@@ -1,11 +1,10 @@
1
1
  import * as React from "react";
2
- import { render, screen, fireEvent } from "@testing-library/react";
2
+ import { render, RenderResult, screen } from "@testing-library/react";
3
3
  import { axe } from "jest-axe";
4
4
  import renderer from "react-test-renderer";
5
5
  import userEvent from "@testing-library/user-event";
6
6
 
7
7
  import TextInput from "./TextInput";
8
- import { TextInputTypes } from "./TextInputTypes";
9
8
 
10
9
  describe("TextInput Accessibility", () => {
11
10
  it("passes axe accessibility test for the input element", async () => {
@@ -16,7 +15,7 @@ describe("TextInput Accessibility", () => {
16
15
  labelText="Custom input label"
17
16
  onChange={jest.fn()}
18
17
  placeholder="Input Placeholder"
19
- type={TextInputTypes.text}
18
+ type="text"
20
19
  />
21
20
  );
22
21
  expect(await axe(container)).toHaveNoViolations();
@@ -30,7 +29,7 @@ describe("TextInput Accessibility", () => {
30
29
  labelText="Custom textarea label"
31
30
  onChange={jest.fn()}
32
31
  placeholder="Input Placeholder"
33
- type={TextInputTypes.textarea}
32
+ type="textarea"
34
33
  />
35
34
  );
36
35
  expect(await axe(container)).toHaveNoViolations();
@@ -38,22 +37,19 @@ describe("TextInput Accessibility", () => {
38
37
  });
39
38
 
40
39
  describe("TextInput", () => {
41
- let utils;
42
- let changeHandler;
43
- let focusHandler;
40
+ let changeHandler: jest.MockedFunction<() => void>;
41
+ let utils: RenderResult;
44
42
 
45
43
  beforeEach(() => {
46
- focusHandler = jest.fn();
47
44
  changeHandler = jest.fn();
48
45
  utils = render(
49
46
  <TextInput
50
- attributes={{ onFocus: focusHandler }}
51
47
  id="myTextInput"
52
48
  isRequired
53
49
  labelText="Custom Input Label"
54
50
  onChange={changeHandler}
55
51
  placeholder="Input Placeholder"
56
- type={TextInputTypes.text}
52
+ type="text"
57
53
  />
58
54
  );
59
55
  });
@@ -74,14 +70,13 @@ describe("TextInput", () => {
74
70
  it("does not render '(Required)' along with the label text", () => {
75
71
  utils.rerender(
76
72
  <TextInput
77
- attributes={{ onFocus: focusHandler }}
78
73
  id="myTextInput"
79
74
  isRequired
80
75
  labelText="Custom Input Label"
81
76
  onChange={changeHandler}
82
77
  placeholder="Input Placeholder"
83
78
  showRequiredLabel={false}
84
- type={TextInputTypes.text}
79
+ type="text"
85
80
  />
86
81
  );
87
82
 
@@ -108,12 +103,6 @@ describe("TextInput", () => {
108
103
  );
109
104
  });
110
105
 
111
- it("allows user to pass in additional attributes", () => {
112
- expect(focusHandler).toHaveBeenCalledTimes(0);
113
- fireEvent.focus(screen.getByLabelText(/Custom Input Label/i));
114
- expect(focusHandler).toHaveBeenCalledTimes(1);
115
- });
116
-
117
106
  it("changing the value calls the onChange handler", () => {
118
107
  expect(changeHandler).toHaveBeenCalledTimes(0);
119
108
  userEvent.type(screen.getByLabelText(/Custom Input Label/i), "Hello");
@@ -144,7 +133,7 @@ describe("Renders TextInput with auto-generated ID, hidden label and visible hel
144
133
  labelText="Custom Input Label"
145
134
  placeholder="Input Placeholder"
146
135
  showLabel={false}
147
- type={TextInputTypes.text}
136
+ type="text"
148
137
  />
149
138
  );
150
139
  });
@@ -170,9 +159,10 @@ describe("Renders TextInput with auto-generated ID, hidden label and visible hel
170
159
  });
171
160
 
172
161
  describe("TextInput shows error state", () => {
173
- let rerender;
162
+ let utils: RenderResult;
163
+
174
164
  beforeEach(() => {
175
- const utils = render(
165
+ utils = render(
176
166
  <TextInput
177
167
  helperText="Custom Helper Text"
178
168
  id="myTextInputError"
@@ -180,11 +170,9 @@ describe("TextInput shows error state", () => {
180
170
  isInvalid
181
171
  labelText="Custom Input Label"
182
172
  placeholder="Input Placeholder"
183
- type={TextInputTypes.text}
173
+ type="text"
184
174
  />
185
175
  );
186
-
187
- rerender = utils.rerender;
188
176
  });
189
177
 
190
178
  it("renders Input component", () => {
@@ -201,7 +189,7 @@ describe("TextInput shows error state", () => {
201
189
  });
202
190
 
203
191
  it("does not render the invalid text when 'showHelperInvalidText' is set to false", () => {
204
- rerender(
192
+ utils.rerender(
205
193
  <TextInput
206
194
  helperText="Custom Helper Text"
207
195
  id="myTextInputError"
@@ -210,7 +198,7 @@ describe("TextInput shows error state", () => {
210
198
  labelText="Custom Input Label"
211
199
  placeholder="Input Placeholder"
212
200
  showHelperInvalidText={false}
213
- type={TextInputTypes.text}
201
+ type="text"
214
202
  />
215
203
  );
216
204
  expect(screen.queryByText("Custom Helper Text")).not.toBeInTheDocument();
@@ -224,22 +212,17 @@ describe("TextInput shows error state", () => {
224
212
  });
225
213
  });
226
214
 
227
- describe("Renders HTML attributes passed through the `attributes` prop", () => {
215
+ describe("Renders HTML attributes passed", () => {
228
216
  const onChangeSpy = jest.fn();
229
- const onBlurSpy = jest.fn();
230
217
  beforeEach(() => {
231
218
  render(
232
219
  <TextInput
233
- attributes={{
234
- onChange: onChangeSpy,
235
- onBlur: onBlurSpy,
236
- maxLength: 10,
237
- tabIndex: 0,
238
- }}
239
220
  id="inputID-attributes"
240
221
  labelText="Input Label"
222
+ maxLength={10}
223
+ onChange={onChangeSpy}
241
224
  placeholder="Input Placeholder"
242
- type={TextInputTypes.text}
225
+ type="text"
243
226
  />
244
227
  );
245
228
  });
@@ -251,24 +234,11 @@ describe("Renders HTML attributes passed through the `attributes` prop", () => {
251
234
  );
252
235
  });
253
236
 
254
- it("has a tabIndex", () => {
255
- expect(screen.getByLabelText(/Input Label/i)).toHaveAttribute(
256
- "tabIndex",
257
- "0"
258
- );
259
- });
260
-
261
237
  it("calls the onChange function", () => {
262
238
  expect(onChangeSpy).toHaveBeenCalledTimes(0);
263
239
  userEvent.type(screen.getByLabelText(/Input Label/i), "Hello");
264
240
  expect(onChangeSpy).toHaveBeenCalledTimes(5);
265
241
  });
266
-
267
- it("calls the onBlur function", () => {
268
- expect(onBlurSpy).toHaveBeenCalledTimes(0);
269
- fireEvent.blur(screen.getByLabelText(/Input Label/i));
270
- expect(onBlurSpy).toHaveBeenCalledTimes(1);
271
- });
272
242
  });
273
243
 
274
244
  // TODO:
@@ -280,7 +250,7 @@ describe("Renders HTML attributes passed through the `attributes` prop", () => {
280
250
  // id="inputID-attributes"
281
251
  // labelText="Input Label"
282
252
  // placeholder={"Input Placeholder"}
283
- // type={TextInputTypes.text}
253
+ // type="text"
284
254
  // ref={ref}
285
255
  // />
286
256
  // );
@@ -294,7 +264,7 @@ describe("Renders HTML attributes passed through the `attributes` prop", () => {
294
264
  // id="inputID-attributes"
295
265
  // labelText="Input Label"
296
266
  // placeholder={"Input Placeholder"}
297
- // type={TextInputTypes.textarea}
267
+ // type="textarea"
298
268
  // ref={ref}
299
269
  // />
300
270
  // );
@@ -308,7 +278,7 @@ describe("Hidden input", () => {
308
278
  <TextInput
309
279
  id="inputID-hidden"
310
280
  labelText="Hidden Input Label"
311
- type={TextInputTypes.hidden}
281
+ type="hidden"
312
282
  value="hidden"
313
283
  />
314
284
  );
@@ -328,7 +298,7 @@ describe("Hidden input", () => {
328
298
  helperText="Helper Text"
329
299
  id="inputID-hidden"
330
300
  labelText="Hidden Input Label"
331
- type={TextInputTypes.hidden}
301
+ type="hidden"
332
302
  value="hidden"
333
303
  />
334
304
  );
@@ -345,7 +315,7 @@ describe("Textarea element type", () => {
345
315
  id="myTextarea"
346
316
  labelText="Custom textarea Label"
347
317
  placeholder="Textarea Placeholder"
348
- type={TextInputTypes.textarea}
318
+ type="textarea"
349
319
  />
350
320
  );
351
321
  });
@@ -368,7 +338,7 @@ describe("UI Snapshots", () => {
368
338
  isRequired
369
339
  labelText="Custom Input Label"
370
340
  placeholder="Input Placeholder"
371
- type={TextInputTypes.text}
341
+ type="text"
372
342
  />
373
343
  )
374
344
  .toJSON();
@@ -378,7 +348,7 @@ describe("UI Snapshots", () => {
378
348
  id="myTextInput"
379
349
  labelText="Custom Input Label"
380
350
  placeholder="Input Placeholder"
381
- type={TextInputTypes.text}
351
+ type="text"
382
352
  />
383
353
  )
384
354
  .toJSON();
@@ -390,7 +360,7 @@ describe("UI Snapshots", () => {
390
360
  labelText="Custom Input Label"
391
361
  placeholder="Input Placeholder"
392
362
  showLabel={false}
393
- type={TextInputTypes.text}
363
+ type="text"
394
364
  />
395
365
  )
396
366
  .toJSON();
@@ -402,7 +372,7 @@ describe("UI Snapshots", () => {
402
372
  isRequired
403
373
  labelText="Custom Input Label"
404
374
  placeholder="Input Placeholder"
405
- type={TextInputTypes.text}
375
+ type="text"
406
376
  />
407
377
  )
408
378
  .toJSON();
@@ -414,7 +384,7 @@ describe("UI Snapshots", () => {
414
384
  isRequired
415
385
  labelText="Custom Input Label"
416
386
  placeholder="Input Placeholder"
417
- type={TextInputTypes.text}
387
+ type="text"
418
388
  />
419
389
  )
420
390
  .toJSON();
@@ -426,7 +396,7 @@ describe("UI Snapshots", () => {
426
396
  isRequired
427
397
  labelText="Custom Input Label"
428
398
  placeholder="Input Placeholder"
429
- type={TextInputTypes.text}
399
+ type="text"
430
400
  />
431
401
  )
432
402
  .toJSON();
@@ -436,7 +406,7 @@ describe("UI Snapshots", () => {
436
406
  id="chakra"
437
407
  labelText="Custom Input Label"
438
408
  placeholder="Input Placeholder"
439
- type={TextInputTypes.text}
409
+ type="text"
440
410
  p="20px"
441
411
  color="ui.error.primary"
442
412
  />
@@ -448,7 +418,7 @@ describe("UI Snapshots", () => {
448
418
  id="props"
449
419
  labelText="Custom Input Label"
450
420
  placeholder="Input Placeholder"
451
- type={TextInputTypes.text}
421
+ type="text"
452
422
  data-testid="props"
453
423
  />
454
424
  )
@@ -471,7 +441,7 @@ describe("UI Snapshots", () => {
471
441
  id="myTextarea"
472
442
  labelText="Custom textarea Label"
473
443
  placeholder="Textarea Placeholder"
474
- type={TextInputTypes.textarea}
444
+ type="textarea"
475
445
  />
476
446
  )
477
447
  .toJSON();
@@ -7,21 +7,37 @@ import {
7
7
  } from "@chakra-ui/react";
8
8
  import * as React from "react";
9
9
 
10
- import {
11
- TextInputTypes,
12
- TextInputFormats,
13
- TextInputVariants,
14
- } from "./TextInputTypes";
15
10
  import Label from "../Label/Label";
16
11
  import HelperErrorText, {
17
12
  HelperErrorTextType,
18
13
  } from "../HelperErrorText/HelperErrorText";
19
14
 
15
+ // HTML Input types as defined by MDN: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input
16
+ export type TextInputTypes =
17
+ | "email"
18
+ | "hidden"
19
+ | "number"
20
+ | "password"
21
+ | "text"
22
+ | "textarea"
23
+ | "tel"
24
+ | "url";
25
+
26
+ // Only used internally.
27
+ export const TextInputFormats = {
28
+ email: "jdoe@domain.com",
29
+ hidden: "",
30
+ password: "",
31
+ text: "",
32
+ tel: "(123) 123-1234",
33
+ textarea: "",
34
+ url: "https://domain.com",
35
+ };
36
+
37
+ // Only used internally in `TextInput` and `SearchBar`.
38
+ export type TextInputVariants = "default" | "searchBar" | "searchBarSelect";
39
+
20
40
  export interface InputProps {
21
- /** Optionally pass in additional Chakra-based styles. */
22
- additionalStyles?: { [key: string]: any };
23
- /** Additional attributes to pass to the `<input>` or `<textarea>` element */
24
- attributes?: { [key: string]: any };
25
41
  /** A class name for the TextInput parent div. */
26
42
  className?: string;
27
43
  /** The starting value of the input field. */
@@ -41,6 +57,12 @@ export interface InputProps {
41
57
  /** Provides text for a `Label` component if `showLabel` is set to true;
42
58
  * populates an `aria-label` attribute if `showLabel` is set to false. */
43
59
  labelText: string;
60
+ /** The max number for a `number` TextInput type. */
61
+ max?: number;
62
+ /** The max length of the input field. */
63
+ maxLength?: number;
64
+ /** The min number for a `number` TextInput type. */
65
+ min?: number;
44
66
  /** Used to reference the input element in forms. */
45
67
  name?: string;
46
68
  /** The action to perform on the `input`/`textarea`'s onChange function */
@@ -49,6 +71,10 @@ export interface InputProps {
49
71
  | React.ChangeEvent<HTMLInputElement>
50
72
  | React.ChangeEvent<HTMLTextAreaElement>
51
73
  ) => void;
74
+ /** The action to perform on the `input`/`textarea`'s onClick function */
75
+ onClick?: (event: React.MouseEvent<HTMLInputElement, MouseEvent>) => void;
76
+ /** The action to perform on the `input`/`textarea`'s onFocus function */
77
+ onFocus?: (event: React.FocusEvent<HTMLInputElement>) => void;
52
78
  /** Populates the placeholder for the input/textarea elements */
53
79
  placeholder?: string;
54
80
  /** Offers the ability to hide the helper/invalid text. */
@@ -84,8 +110,6 @@ export const TextInput = chakra(
84
110
  React.forwardRef<TextInputRefType, InputProps>(
85
111
  (props, ref: React.Ref<TextInputRefType>) => {
86
112
  const {
87
- additionalStyles = {},
88
- attributes = {},
89
113
  className,
90
114
  defaultValue,
91
115
  helperText,
@@ -95,30 +119,35 @@ export const TextInput = chakra(
95
119
  isInvalid = false,
96
120
  isRequired = false,
97
121
  labelText,
122
+ max,
123
+ maxLength,
124
+ min,
98
125
  name,
99
126
  onChange,
127
+ onClick,
128
+ onFocus,
100
129
  placeholder,
101
130
  showHelperInvalidText = true,
102
131
  showLabel = true,
103
132
  showRequiredLabel = true,
104
133
  step = 1,
105
- textInputType = TextInputVariants.Default,
106
- type = TextInputTypes.text,
134
+ textInputType = "default",
135
+ type = "text",
107
136
  value,
108
137
  ...rest
109
138
  } = props;
110
139
  const styles = useMultiStyleConfig("TextInput", {
111
140
  variant: textInputType,
112
141
  });
113
- const finalStyles = { ...styles, ...additionalStyles };
114
- const isTextArea = type === TextInputTypes.textarea;
115
- const isHidden = type === TextInputTypes.hidden;
142
+ const isTextArea = type === "textarea";
143
+ const isHidden = type === "hidden";
116
144
  const finalInvalidText = invalidText
117
145
  ? invalidText
118
146
  : "There is an error related to this field.";
119
147
  let footnote: HelperErrorTextType = isInvalid
120
148
  ? finalInvalidText
121
149
  : helperText;
150
+ let ariaAttributes = {};
122
151
  let fieldOutput;
123
152
  let options;
124
153
 
@@ -129,18 +158,14 @@ export const TextInput = chakra(
129
158
  }
130
159
 
131
160
  if (!showLabel) {
132
- attributes["aria-label"] =
161
+ ariaAttributes["aria-label"] =
133
162
  labelText && footnote ? `${labelText} - ${footnote}` : labelText;
134
163
  } else if (helperText) {
135
- attributes["aria-describedby"] = `${id}-helperText`;
164
+ ariaAttributes["aria-describedby"] = `${id}-helperText`;
136
165
  }
137
166
 
138
- if (
139
- type === TextInputTypes.tel ||
140
- type === TextInputTypes.url ||
141
- type === TextInputTypes.email
142
- ) {
143
- const example = TextInputFormats[type];
167
+ if (type === "tel" || type === "url" || type === "email") {
168
+ const example = TextInputFormats[type] || "";
144
169
  footnote = (
145
170
  <>
146
171
  Ex: {example}
@@ -160,29 +185,35 @@ export const TextInput = chakra(
160
185
  isDisabled,
161
186
  isRequired,
162
187
  isInvalid,
163
- placeholder,
188
+ max,
189
+ maxLength,
190
+ min,
164
191
  name,
165
192
  onChange,
193
+ onClick,
194
+ onFocus,
195
+ placeholder,
166
196
  ref,
167
197
  // The `step` attribute is useful for the number type.
168
- step: type === TextInputTypes.number ? step : null,
169
- ...attributes,
198
+ step: type === "number" ? step : null,
199
+ ...ariaAttributes,
200
+ ...rest,
170
201
  };
171
202
  // For `input` and `textarea`, all attributes are the same but `input`
172
203
  // also needs `type` and `value` to render correctly.
173
204
  if (!isTextArea) {
174
205
  options = { type, value, ...options } as any;
175
- fieldOutput = <ChakraInput {...options} __css={finalStyles.input} />;
206
+ fieldOutput = <ChakraInput {...options} __css={styles.input} />;
176
207
  } else {
177
208
  fieldOutput = (
178
- <ChakraTextarea {...options} __css={finalStyles.textarea}>
209
+ <ChakraTextarea {...options} __css={styles.textarea}>
179
210
  {value}
180
211
  </ChakraTextarea>
181
212
  );
182
213
  }
183
214
 
184
215
  return (
185
- <Box __css={finalStyles} className={className} {...rest}>
216
+ <Box __css={styles} className={className} {...rest}>
186
217
  {labelText && showLabel && !isHidden && (
187
218
  <Label
188
219
  htmlFor={id}
@@ -226,6 +226,7 @@ exports[`UI Snapshots renders the text input UI snapshot correctly 8`] = `
226
226
  </label>
227
227
  <input
228
228
  className="chakra-input css-0"
229
+ data-testid="props"
229
230
  disabled={false}
230
231
  id="props"
231
232
  onBlur={[Function]}
@@ -11,15 +11,8 @@ import { withDesign } from "storybook-addon-designs";
11
11
  import Heading from "../Heading/Heading";
12
12
  import SimpleGrid from "../Grid/SimpleGrid";
13
13
  import Toggle from "./Toggle";
14
- import { ToggleSizes } from "./ToggleTypes";
15
14
  import { getCategory } from "../../utils/componentCategories";
16
15
  import DSProvider from "../../theme/provider";
17
- import { getStorybookEnumValues } from "../../utils/utils";
18
-
19
- export const sizeEnumValues = getStorybookEnumValues(
20
- ToggleSizes,
21
- "ToggleSizes"
22
- );
23
16
 
24
17
  <Meta
25
18
  title={getCategory("Toggle")}
@@ -33,7 +26,6 @@ export const sizeEnumValues = getStorybookEnumValues(
33
26
  jest: ["Toggle.test.tsx"],
34
27
  }}
35
28
  argTypes={{
36
- additionalStyles: { control: false },
37
29
  defaultChecked: { control: false },
38
30
  id: { control: false },
39
31
  key: { table: { disable: true } },
@@ -42,9 +34,7 @@ export const sizeEnumValues = getStorybookEnumValues(
42
34
  ref: { table: { disable: true } },
43
35
  size: {
44
36
  control: {
45
- type: "select",
46
- table: { defaultValue: { summary: "ToggleSizes.Default" } },
47
- options: sizeEnumValues.options,
37
+ table: { defaultValue: { summary: "default" } },
48
38
  },
49
39
  },
50
40
  }}
@@ -55,7 +45,7 @@ export const sizeEnumValues = getStorybookEnumValues(
55
45
  | Component Version | DS Version |
56
46
  | ----------------- | ---------- |
57
47
  | Added | `0.25.8` |
58
- | Latest | `0.26.0` |
48
+ | Latest | `0.28.0` |
59
49
 
60
50
  ## Table of Contents
61
51
 
@@ -89,7 +79,6 @@ should be short and to the point, often three words or less.
89
79
  <Story
90
80
  name="Toggle"
91
81
  args={{
92
- additionalStyles: undefined,
93
82
  defaultChecked: false,
94
83
  helperText: "This is the helper text!",
95
84
  id: "toggle-1",
@@ -104,7 +93,7 @@ should be short and to the point, often three words or less.
104
93
  size: "ToogleSizes.Large",
105
94
  }}
106
95
  >
107
- {(args) => <Toggle {...args} size={sizeEnumValues.getValue(args.size)} />}
96
+ {(args) => <Toggle {...args} />}
108
97
  </Story>
109
98
  </Canvas>
110
99
 
@@ -143,10 +132,10 @@ Resources:
143
132
  <Toggle
144
133
  defaultChecked={true}
145
134
  id="small-checked"
146
- size={ToggleSizes.Small}
135
+ size="small"
147
136
  labelText="On"
148
137
  />
149
- <Toggle id="default-small" size={ToggleSizes.Small} labelText="Off" />
138
+ <Toggle id="default-small" size="small" labelText="Off" />
150
139
  </VStack>
151
140
  </SimpleGrid>
152
141
  </DSProvider>
@@ -5,7 +5,6 @@ import * as React from "react";
5
5
  import renderer from "react-test-renderer";
6
6
 
7
7
  import Toggle from "./Toggle";
8
- import { ToggleSizes } from "./ToggleTypes";
9
8
 
10
9
  describe("Toggle Accessibility", () => {
11
10
  it("Passes axe accessibility test", async () => {
@@ -17,7 +16,7 @@ describe("Toggle Accessibility", () => {
17
16
  });
18
17
 
19
18
  describe("Toggle", () => {
20
- let changeHandler;
19
+ let changeHandler: jest.MockedFunction<() => void>;
21
20
 
22
21
  beforeEach(() => {
23
22
  changeHandler = jest.fn();
@@ -142,7 +141,7 @@ describe("Toggle", () => {
142
141
  id="Toggle-disabled"
143
142
  labelText="Test Label"
144
143
  isDisabled
145
- size={ToggleSizes.Small}
144
+ size="small"
146
145
  />
147
146
  )
148
147
  .toJSON();
@@ -10,10 +10,10 @@ import * as React from "react";
10
10
  import HelperErrorText, {
11
11
  HelperErrorTextType,
12
12
  } from "../HelperErrorText/HelperErrorText";
13
- import { ToggleSizes } from "./ToggleTypes";
13
+ import { AriaAttributes } from "../../utils/interfaces";
14
+
15
+ export type ToggleSizes = "default" | "small";
14
16
  export interface ToggleProps {
15
- /** Optionally pass in additional Chakra-based styles. */
16
- additionalStyles?: { [key: string]: any };
17
17
  /** Used for uncontrolled scenarios. Sets the state of the Toggle when the page first loads.
18
18
  * If true, the toggle will be initially set to the "on" position. */
19
19
  defaultChecked?: boolean;
@@ -57,7 +57,6 @@ export const onChangeDefault = () => {
57
57
  export const Toggle = chakra(
58
58
  React.forwardRef<HTMLInputElement, ToggleProps>((props, ref?) => {
59
59
  const {
60
- additionalStyles = {},
61
60
  defaultChecked = false,
62
61
  helperText,
63
62
  id,
@@ -69,11 +68,11 @@ export const Toggle = chakra(
69
68
  labelText,
70
69
  name,
71
70
  onChange = onChangeDefault,
72
- size = ToggleSizes.Default,
71
+ size = "default",
73
72
  ...rest
74
73
  } = props;
75
- const footnote: HelperErrorTextType = isInvalid ? invalidText : helperText;
76
- const ariaAttributes = {};
74
+ const footnote = isInvalid ? invalidText : helperText;
75
+ const ariaAttributes: AriaAttributes = {};
77
76
  const styles = useMultiStyleConfig("Toggle", { isDisabled, size });
78
77
  const switchStyles = useStyleConfig("Switch", { size });
79
78
  ariaAttributes["aria-label"] =
@@ -87,7 +86,7 @@ export const Toggle = chakra(
87
86
 
88
87
  return (
89
88
  <>
90
- <Box __css={{ ...styles, ...additionalStyles }} {...rest}>
89
+ <Box __css={styles} {...rest}>
91
90
  <Switch
92
91
  id={id}
93
92
  name={name || "default"}
@@ -95,7 +94,7 @@ export const Toggle = chakra(
95
94
  isInvalid={isInvalid}
96
95
  isRequired={isRequired}
97
96
  ref={ref}
98
- size={size === ToggleSizes.Default ? "lg" : "sm"}
97
+ size={size === "default" ? "lg" : "sm"}
99
98
  lineHeight="1.5"
100
99
  {...(isChecked !== undefined
101
100
  ? {
@@ -113,10 +112,10 @@ export const Toggle = chakra(
113
112
  </Box>
114
113
  {footnote && (
115
114
  <HelperErrorText
116
- additionalStyles={styles.helperErrorText}
117
115
  id={`${id}-helperText`}
118
116
  isInvalid={isInvalid}
119
117
  text={footnote}
118
+ __css={styles.helperErrorText}
120
119
  />
121
120
  )}
122
121
  </>