@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
@@ -8,15 +8,8 @@ import {
8
8
  import { withDesign } from "storybook-addon-designs";
9
9
 
10
10
  import DatePicker from "./DatePicker";
11
- import { DatePickerTypes } from "./DatePickerTypes";
12
11
  import { getCategory } from "../../utils/componentCategories";
13
12
  import DSProvider from "../../theme/provider";
14
- import { getStorybookEnumValues } from "../../utils/utils";
15
-
16
- export const enumValues = getStorybookEnumValues(
17
- DatePickerTypes,
18
- "DatePickerTypes"
19
- );
20
13
 
21
14
  <Meta
22
15
  title={getCategory("DatePicker")}
@@ -36,8 +29,7 @@ export const enumValues = getStorybookEnumValues(
36
29
  },
37
30
  dateType: {
38
31
  control: { type: "select" },
39
- table: { defaultValue: { summary: "DatePickerTypes.Full" } },
40
- options: enumValues.options,
32
+ table: { defaultValue: { summary: "full" } },
41
33
  },
42
34
  id: { control: false },
43
35
  isDateRange: {
@@ -78,7 +70,7 @@ export const enumValues = getStorybookEnumValues(
78
70
  | Component Version | DS Version |
79
71
  | ----------------- | ---------- |
80
72
  | Added | `0.24.0` |
81
- | Latest | `0.26.0` |
73
+ | Latest | `0.28.0` |
82
74
 
83
75
  ## Table of Contents
84
76
 
@@ -107,7 +99,7 @@ also be added through props.
107
99
  args={{
108
100
  className: undefined,
109
101
  dateFormat: "yyyy-MM-dd",
110
- dateType: "DatePickerTypes.Full",
102
+ dateType: "full",
111
103
  helperText: "Note that the Library may be closed on Sundays.",
112
104
  helperTextFrom: "Select start date.",
113
105
  helperTextTo: "Select end date.",
@@ -131,13 +123,7 @@ also be added through props.
131
123
  showRequiredLabel: true,
132
124
  }}
133
125
  >
134
- {(args) => (
135
- <DatePicker
136
- {...args}
137
- dateType={enumValues.getValue(args.dateType)}
138
- onChange={undefined}
139
- />
140
- )}
126
+ {(args) => <DatePicker {...args} onChange={undefined} />}
141
127
  </Story>
142
128
  </Canvas>
143
129
 
@@ -182,7 +168,7 @@ popup calendar.
182
168
  <DatePicker
183
169
  id="date-range"
184
170
  dateFormat="yyyy-MM-dd"
185
- dateType={DatePickerTypes.Full}
171
+ dateType="full"
186
172
  minDate="1/1/2022"
187
173
  maxDate="7/1/2022"
188
174
  labelText="Select the date range you want to visit NYPL"
@@ -204,19 +190,19 @@ popup calendar.
204
190
  By default, the `DatePicker` will display the input date value in the full
205
191
  format that contains the year, month, and day such as "2021-01-30". Although
206
192
  this is the default, it can be explicitly set through the `dateType` prop with
207
- value of `DatePickerTypes.Full`.
193
+ value of `"full"`.
208
194
 
209
195
  ### Month Date Input
210
196
 
211
197
  It's possible to select dates by skipping the day value and only selecting
212
- the month and the year when `dateType` is set to `DatePickerTypes.Month`. Note
198
+ the month and the year when `dateType` is set to `"month"`. Note
213
199
  that all 12 months will appear in the popup calendar with their abbreviated names.
214
200
 
215
201
  <Canvas withToolbar>
216
202
  <Story name="Month Date Input">
217
203
  <DatePicker
218
204
  id="month-date"
219
- dateType={DatePickerTypes.Month}
205
+ dateType="month"
220
206
  labelText="Select the month you want to visit NYPL"
221
207
  helperText="Note that the Library may be closed on Sundays."
222
208
  invalidText="Please select a valid month."
@@ -227,14 +213,14 @@ that all 12 months will appear in the popup calendar with their abbreviated name
227
213
  ### Year Date Input
228
214
 
229
215
  It's possible to select dates by only the year when `dateType` is set to
230
- `DatePickerTypes.Year`. Note that only 12 values will appear in the popup
231
- calendar; the four previous years, the current year, and the next seven years.
216
+ `"year"`. Note that only 12 values will appear in the popup calendar; the four
217
+ previous years, the current year, and the next seven years.
232
218
 
233
219
  <Canvas withToolbar>
234
220
  <Story name="Year Date Input">
235
221
  <DatePicker
236
222
  id="year-date"
237
- dateType={DatePickerTypes.Year}
223
+ dateType="year"
238
224
  labelText="Select the year you want to visit NYPL"
239
225
  helperText="Note that the Library may be closed on Sundays."
240
226
  />
@@ -249,7 +235,7 @@ calendar; the four previous years, the current year, and the next seven years.
249
235
  <DSProvider>
250
236
  <DatePicker
251
237
  id="invalid-date"
252
- dateType={DatePickerTypes.Full}
238
+ dateType="full"
253
239
  labelText="Select the year you want to visit NYPL"
254
240
  helperText="Note that the Library may be closed on Sundays."
255
241
  invalidText="Please select a valid date."
@@ -265,7 +251,7 @@ calendar; the four previous years, the current year, and the next seven years.
265
251
  <DSProvider>
266
252
  <DatePicker
267
253
  id="disabled-date"
268
- dateType={DatePickerTypes.Full}
254
+ dateType="full"
269
255
  labelText="Select the year you want to visit NYPL"
270
256
  isDateRange
271
257
  isDisabled
@@ -281,8 +267,8 @@ date input, can be hidden when `showRequiredLabel` is set to `false`.
281
267
  <Canvas>
282
268
  <DSProvider>
283
269
  <DatePicker
284
- id="disabled-date"
285
- dateType={DatePickerTypes.Full}
270
+ id="required-date"
271
+ dateType="full"
286
272
  labelText="Select the year you want to visit NYPL"
287
273
  isDateRange
288
274
  isRequired
@@ -305,7 +291,7 @@ styleguide, we display dates as "year-month-day" by default.
305
291
  <DSProvider>
306
292
  <DatePicker
307
293
  id="init-dates"
308
- dateType={DatePickerTypes.Full}
294
+ dateType="full"
309
295
  labelText="Select the date you want to visit NYPL"
310
296
  initialDate="12/1/21"
311
297
  initialDateTo="12/10/21"
@@ -325,7 +311,7 @@ written in [ISO-8601 format](https://www.w3.org/TR/NOTE-datetime).
325
311
  <DatePicker
326
312
  id="format-date"
327
313
  dateFormat="MM-dd-yyyy"
328
- dateType={DatePickerTypes.Full}
314
+ dateType="full"
329
315
  labelText="Select the date you want to visit NYPL"
330
316
  initialDate="12/1/21"
331
317
  initialDateTo="12/10/21"
@@ -345,7 +331,7 @@ February to see the dates that are available to select in 2022.
345
331
  <DatePicker
346
332
  id="max-min-dates"
347
333
  dateFormat="MM-dd-yyyy"
348
- dateType={DatePickerTypes.Full}
334
+ dateType="full"
349
335
  labelText="Select the date you want to visit NYPL"
350
336
  minDate="1/1/2022"
351
337
  maxDate="3/1/2022"
@@ -358,10 +344,10 @@ February to see the dates that are available to select in 2022.
358
344
 
359
345
  ### Controlled Component Using `onChange` prop
360
346
 
361
- If your application uses controlled React components and the Reservoir Design
347
+ If your application uses controlled React components and the Reservoir Design
362
348
  System (DS) DatePicker must be controlled, you can extract the data through the
363
349
  `onChange` prop function. This will be called every time the date is updated in
364
- either the start date input field or the end date input field. The returned
350
+ either the start date input field or the end date input field. The returned
365
351
  data is an object with `startDate` and `endDate` keys and `Date` object values.
366
352
 
367
353
  ```tsx
@@ -381,7 +367,7 @@ const onChange = (data) => {
381
367
  // Example of the DS DatePicker instance with the function above:
382
368
  <DatePicker
383
369
  id="date-range"
384
- dateType={DatePickerTypes.Full}
370
+ dateType="full"
385
371
  labelText="Select the date range you want to visit NYPL"
386
372
  invalidText="Please select a valid date range."
387
373
  onChange={onChange}
@@ -425,7 +411,7 @@ const submitForm = (formData) => {
425
411
  >
426
412
  <DatePicker
427
413
  id="date-range"
428
- dateType={DatePickerTypes.Full}
414
+ dateType="full"
429
415
  labelText="Select the date range you want to visit NYPL"
430
416
  nameFrom="visitDateFrom"
431
417
  nameTo="visitDateTo"
@@ -446,7 +432,7 @@ const refEnd = React.createRef<TextInputRefType>();
446
432
  // ...
447
433
  <DatePicker
448
434
  id="date-range"
449
- dateType={DatePickerTypes.Full}
435
+ dateType="full"
450
436
  labelText="Select the date range you want to visit NYPL"
451
437
  nameFrom="visitDateFrom"
452
438
  nameTo="visitDateTo"
@@ -4,13 +4,12 @@ import { axe } from "jest-axe";
4
4
  import userEvent from "@testing-library/user-event";
5
5
  import renderer from "react-test-renderer";
6
6
 
7
- import DatePicker from "./DatePicker";
8
- import { DatePickerTypes } from "./DatePickerTypes";
7
+ import DatePicker, { DatePickerTypes, FullDateType } from "./DatePicker";
9
8
  import { TextInputRefType } from "../TextInput/TextInput";
10
9
 
11
10
  /** This adds a "0" padding for date values under "10". */
12
- const strPad = (n) => String("0" + n).slice(-2);
13
- const monthArray = [
11
+ const strPad = (n: number) => String("0" + n).slice(-2);
12
+ const monthArray: string[] = [
14
13
  "January",
15
14
  "February",
16
15
  "March",
@@ -58,11 +57,11 @@ describe("DatePicker", () => {
58
57
  return [year, month, day];
59
58
  };
60
59
  /** Returns today's date in string format based on the DatePicker type. */
61
- const getTodaysDateDisplay = (type?) => {
60
+ const getTodaysDateDisplay = (type?: DatePickerTypes) => {
62
61
  const [year, month, day] = getTodaysValues();
63
- if (DatePickerTypes.Year === type) {
62
+ if ("year" === type) {
64
63
  return `${year}`;
65
- } else if (DatePickerTypes.Month === type) {
64
+ } else if ("month" === type) {
66
65
  return `${month}-${year}`;
67
66
  }
68
67
  return `${year}-${month}-${day}`;
@@ -106,12 +105,12 @@ describe("DatePicker", () => {
106
105
  render(
107
106
  <DatePicker
108
107
  id="datePicker"
109
- dateType={DatePickerTypes.Month}
108
+ dateType="month"
110
109
  labelText="Select the month you want to visit NYPL"
111
110
  />
112
111
  );
113
112
  const [year, month] = getTodaysValues();
114
- const date = getTodaysDateDisplay(DatePickerTypes.Month);
113
+ const date = getTodaysDateDisplay("month");
115
114
 
116
115
  expect(
117
116
  screen.getByLabelText(/Select the month you want to visit NYPL/i)
@@ -125,12 +124,12 @@ describe("DatePicker", () => {
125
124
  render(
126
125
  <DatePicker
127
126
  id="datePicker"
128
- dateType={DatePickerTypes.Year}
127
+ dateType="year"
129
128
  labelText="Select the month you want to visit NYPL"
130
129
  />
131
130
  );
132
131
  const [year] = getTodaysValues();
133
- const date = getTodaysDateDisplay(DatePickerTypes.Year);
132
+ const date = getTodaysDateDisplay("year");
134
133
 
135
134
  expect(
136
135
  screen.getByLabelText(/Select the month you want to visit NYPL/i)
@@ -316,8 +315,11 @@ describe("DatePicker", () => {
316
315
  });
317
316
 
318
317
  it("should pass the value to the `onChange` function", () => {
319
- let dateObject: any = {};
320
- const onChange = (data) => {
318
+ let dateObject: FullDateType = {
319
+ startDate: new Date(),
320
+ endDate: new Date(),
321
+ };
322
+ const onChange = (data: FullDateType) => {
321
323
  dateObject = data;
322
324
  };
323
325
  render(
@@ -370,7 +372,7 @@ describe("DatePicker", () => {
370
372
  it("should throw a warning when `onChange` is passed as well as a `ref` prop.", () => {
371
373
  const warn = jest.spyOn(console, "warn");
372
374
  const ref = React.createRef<TextInputRefType>();
373
- const onChange = (_data) => {};
375
+ const onChange = (_data: {}) => {};
374
376
  render(
375
377
  <DatePicker
376
378
  id="datePicker"
@@ -788,7 +790,7 @@ describe("DatePicker", () => {
788
790
  userEvent.click(screen.getByText(midMonthDay));
789
791
  // So only the month should change accordingly.
790
792
  const newMonthValue = `${newDayValue.substr(0, 5)}${strPad(
791
- "10"
793
+ 10
792
794
  )}${newDayValue.substr(7)}`;
793
795
  expect(screen.getByDisplayValue(newMonthValue)).toBeInTheDocument();
794
796
  });
@@ -797,7 +799,7 @@ describe("DatePicker", () => {
797
799
  render(
798
800
  <DatePicker
799
801
  id="datePicker"
800
- dateType={DatePickerTypes.Month}
802
+ dateType="month"
801
803
  labelText="Select the month you want to visit NYPL"
802
804
  />
803
805
  );
@@ -824,7 +826,7 @@ describe("DatePicker", () => {
824
826
  render(
825
827
  <DatePicker
826
828
  id="datePicker"
827
- dateType={DatePickerTypes.Month}
829
+ dateType="month"
828
830
  initialDate="4/1/1988"
829
831
  labelText="Select the month you want to visit NYPL"
830
832
  />
@@ -864,7 +866,7 @@ describe("DatePicker", () => {
864
866
  render(
865
867
  <DatePicker
866
868
  id="datePicker"
867
- dateType={DatePickerTypes.Year}
869
+ dateType="year"
868
870
  labelText="Select the year you want to visit NYPL"
869
871
  />
870
872
  );
@@ -902,7 +904,7 @@ describe("DatePicker", () => {
902
904
  render(
903
905
  <DatePicker
904
906
  id="datePicker"
905
- dateType={DatePickerTypes.Year}
907
+ dateType="year"
906
908
  labelText="Select the year you want to visit NYPL"
907
909
  />
908
910
  );
@@ -2,10 +2,8 @@ import { chakra, useMultiStyleConfig } from "@chakra-ui/react";
2
2
  import React, { useState, forwardRef } from "react";
3
3
  import ReactDatePicker from "react-datepicker";
4
4
 
5
- import { DatePickerTypes } from "./DatePickerTypes";
6
5
  import Fieldset from "../Fieldset/Fieldset";
7
6
  import { FormRow, FormField } from "../Form/Form";
8
- import { FormGaps } from "../Form/FormTypes";
9
7
  import HelperErrorText, {
10
8
  HelperErrorTextType,
11
9
  } from "../HelperErrorText/HelperErrorText";
@@ -14,6 +12,19 @@ import TextInput, {
14
12
  TextInputRefType,
15
13
  } from "../TextInput/TextInput";
16
14
 
15
+ interface ReactDatePickerAttrs {
16
+ popperClassName: string;
17
+ popperPlacement: string;
18
+ popperModifiers: any[];
19
+ minDate: Date | null;
20
+ maxDate: Date | null;
21
+ dateFormat: string;
22
+ showMonthYearPicker?: boolean;
23
+ showYearPicker?: boolean;
24
+ yearItemNumber?: number;
25
+ }
26
+ export type DatePickerTypes = "full" | "month" | "year";
27
+
17
28
  // The object shape for the DatePicker's start and end date state values.
18
29
  export interface FullDateType {
19
30
  /** Date object that gets returned for the onChange
@@ -50,9 +61,6 @@ interface DatePickerWrapperProps extends DateRangeRowProps {
50
61
  // Interface used by the internal DS `TextInput` component as a custom
51
62
  // component for the ReactDatePicker plugin component. Internal use only.
52
63
  interface CustomTextInputProps extends Partial<InputProps> {
53
- /** The ReactDatePicker plugin has its own `id` prop so we use this to pass the
54
- * value from the parent `DatePicker` component. */
55
- dsId: string;
56
64
  /** The ReactDatePicker plugin manipulates the ref value so we declare our
57
65
  * own for some cases. */
58
66
  dsRef?: React.Ref<TextInputRefType>;
@@ -124,16 +132,15 @@ export interface DatePickerProps extends DatePickerWrapperProps {
124
132
  const CustomTextInput = forwardRef<TextInputRefType, CustomTextInputProps>(
125
133
  (
126
134
  {
127
- additionalStyles = {},
128
- attributes,
129
- dsId,
130
135
  dsRef,
131
136
  helperText,
137
+ id,
132
138
  invalidText,
133
139
  isDisabled,
134
140
  isInvalid,
135
141
  isRequired,
136
142
  labelText,
143
+ name,
137
144
  onChange,
138
145
  onClick,
139
146
  showLabel,
@@ -142,28 +149,30 @@ const CustomTextInput = forwardRef<TextInputRefType, CustomTextInputProps>(
142
149
  value,
143
150
  },
144
151
  ref: React.Ref<TextInputRefType>
145
- ) => (
146
- <TextInput
147
- id={dsId}
148
- showLabel={showLabel}
149
- onChange={onChange}
150
- value={value}
151
- labelText={labelText}
152
- isDisabled={isDisabled}
153
- isRequired={isRequired}
154
- showHelperInvalidText={showHelperInvalidText}
155
- showRequiredLabel={showRequiredLabel}
156
- isInvalid={isInvalid}
157
- helperText={helperText}
158
- invalidText={invalidText}
159
- // Use either the specific prop-based or the `forwardRef` value.
160
- // `react-datepicker` manipulates the `ref` value so when we
161
- // want a specific ref, use the `dsRef` prop.
162
- ref={dsRef || ref}
163
- attributes={{ ...attributes, onClick }}
164
- additionalStyles={additionalStyles}
165
- />
166
- )
152
+ ) => {
153
+ return (
154
+ <TextInput
155
+ helperText={helperText}
156
+ id={id}
157
+ invalidText={invalidText}
158
+ isDisabled={isDisabled}
159
+ isInvalid={isInvalid}
160
+ isRequired={isRequired}
161
+ labelText={labelText}
162
+ name={name}
163
+ onChange={onChange}
164
+ onClick={onClick}
165
+ showHelperInvalidText={showHelperInvalidText}
166
+ showLabel={showLabel}
167
+ showRequiredLabel={showRequiredLabel}
168
+ value={value}
169
+ // Use either the specific prop-based or the `forwardRef` value.
170
+ // `react-datepicker` manipulates the `ref` value so when we
171
+ // want a specific ref, use the `dsRef` prop.
172
+ ref={dsRef || ref}
173
+ />
174
+ );
175
+ }
167
176
  );
168
177
 
169
178
  /**
@@ -216,7 +225,7 @@ const DateRangeRow: React.FC<DateRangeRowProps> = ({
216
225
  children,
217
226
  }) =>
218
227
  isDateRange ? (
219
- <FormRow id={`${id}-form-row`} gap={FormGaps.ExtraSmall}>
228
+ <FormRow id={`${id}-form-row`} gap="grid.xs">
220
229
  {children}
221
230
  </FormRow>
222
231
  ) : (
@@ -231,7 +240,7 @@ export const DatePicker = chakra(
231
240
  const {
232
241
  className,
233
242
  dateFormat = "yyyy-MM-dd",
234
- dateType = DatePickerTypes.Full,
243
+ dateType = "full",
235
244
  helperText,
236
245
  helperTextFrom,
237
246
  helperTextTo,
@@ -268,14 +277,14 @@ export const DatePicker = chakra(
268
277
  // This updates the internal state for the start and end date values,
269
278
  // and also calls the `onChange` prop if it was passed to return the
270
279
  // date value to the parent.
271
- const onChangeDefault = (date, value) => {
280
+ const onChangeDefault = (date: Date, value: string) => {
272
281
  setFullDate({ ...fullDate, [value]: date });
273
282
  onChange && onChange({ ...fullDate, [value]: date });
274
283
  };
275
- // How many years to display in the DatePickerTypes.Year option.
284
+ // How many years to display in the "year" option.
276
285
  const yearsToDisplay = 12;
277
286
  // Both `ReactDatePicker` components share some props.
278
- let baseDatePickerAttrs = {
287
+ let baseDatePickerAttrs: ReactDatePickerAttrs = {
279
288
  popperClassName: "date-picker-calendar",
280
289
  popperPlacement: "bottom-start",
281
290
  popperModifiers: [
@@ -292,7 +301,6 @@ export const DatePicker = chakra(
292
301
  };
293
302
  // Both custom `TextInput` components share some props.
294
303
  let baseCustomTextInputAttrs = {
295
- dsId: `${id}-start`,
296
304
  isRequired,
297
305
  // In the date range type, don't display the "(Required)" text in
298
306
  // individual input labels. It'll display in the legend element.
@@ -305,7 +313,7 @@ export const DatePicker = chakra(
305
313
  helperText: isDateRange ? helperTextFrom : helperText,
306
314
  showHelperInvalidText,
307
315
  invalidText,
308
- additionalStyles: finalStyles.subLabels,
316
+ __css: finalStyles.subLabels,
309
317
  };
310
318
  // These are attribute objects for the `react-datepicker` package component.
311
319
  let startDatePickerAttrs = {};
@@ -316,10 +324,10 @@ export const DatePicker = chakra(
316
324
  let startLabelText = labelText;
317
325
 
318
326
  // Update the appropriate props for the selected date type to render.
319
- if (dateType === DatePickerTypes.Month) {
327
+ if (dateType === "month") {
320
328
  baseDatePickerAttrs["showMonthYearPicker"] = true;
321
329
  baseDatePickerAttrs.dateFormat = "MM-yyyy";
322
- } else if (dateType === DatePickerTypes.Year) {
330
+ } else if (dateType === "year") {
323
331
  baseDatePickerAttrs["showYearPicker"] = true;
324
332
  baseDatePickerAttrs["yearItemNumber"] = yearsToDisplay;
325
333
  baseDatePickerAttrs.dateFormat = "yyyy";
@@ -354,7 +362,6 @@ export const DatePicker = chakra(
354
362
  if (isDateRange) {
355
363
  const endCustomTextInputAttrs = {
356
364
  ...baseCustomTextInputAttrs,
357
- dsId: `${id}-end`,
358
365
  helperText: helperTextTo,
359
366
  };
360
367
  // These props are used to follow the pattern recommended by
@@ -375,33 +382,34 @@ export const DatePicker = chakra(
375
382
  startLabelText = "From";
376
383
  endDatePickerElement = (
377
384
  <ReactDatePicker
378
- selected={fullDate.endDate}
379
- onChange={(date) => onChangeDefault(date, "endDate")}
380
385
  customInput={
381
386
  <CustomTextInput
382
- labelText="To"
383
387
  dsRef={refTo}
384
- attributes={{ name: nameTo }}
388
+ labelText="To"
385
389
  {...endCustomTextInputAttrs}
386
390
  />
387
391
  }
392
+ id={`${id}-end`}
393
+ name={nameTo}
394
+ onChange={(date: Date) => onChangeDefault(date, "endDate")}
395
+ selected={fullDate.endDate}
388
396
  {...endDatePickerAttrs}
389
397
  />
390
398
  );
391
399
  }
392
-
393
400
  const startDatePickerElement = (
394
401
  <ReactDatePicker
395
- selected={fullDate.startDate}
396
- onChange={(date) => onChangeDefault(date, "startDate")}
397
402
  customInput={
398
403
  <CustomTextInput
399
- labelText={startLabelText}
400
404
  dsRef={ref}
401
- attributes={{ name: nameFrom }}
405
+ labelText={startLabelText}
402
406
  {...baseCustomTextInputAttrs}
403
407
  />
404
408
  }
409
+ id={`${id}-start`}
410
+ name={nameFrom}
411
+ onChange={(date: Date) => onChangeDefault(date, "startDate")}
412
+ selected={fullDate.startDate}
405
413
  {...startDatePickerAttrs}
406
414
  />
407
415
  );