@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
@@ -0,0 +1,147 @@
1
+ import {
2
+ ArgsTable,
3
+ Canvas,
4
+ Description,
5
+ Meta,
6
+ Story,
7
+ } from "@storybook/addon-docs";
8
+ import { withDesign } from "storybook-addon-designs";
9
+
10
+ import Button from "../Button/Button";
11
+ import ButtonGroup from "./ButtonGroup";
12
+ import Heading from "../Heading/Heading";
13
+ import SimpleGrid from "../Grid/SimpleGrid";
14
+ import { getCategory } from "../../utils/componentCategories";
15
+ import DSProvider from "../../theme/provider";
16
+
17
+ <Meta
18
+ title={getCategory("ButtonGroup")}
19
+ component={ButtonGroup}
20
+ decorators={[withDesign]}
21
+ parameters={{
22
+ jest: ["ButtonGroup.test.tsx"],
23
+ }}
24
+ argTypes={{
25
+ buttonWidth: { table: { defaultValue: { summary: "default" } } },
26
+ className: { control: false },
27
+ id: { control: false },
28
+ isDisabled: { table: { defaultValue: { summary: false } } },
29
+ layout: { table: { defaultValue: { summary: "row" } } },
30
+ }}
31
+ />
32
+
33
+ # ButtonGroup
34
+
35
+ | Component Version | DS Version |
36
+ | ----------------- | ---------- |
37
+ | Added | `0.28.0` |
38
+ | Latest | `0.28.0` |
39
+
40
+ ## Table of Contents
41
+
42
+ - [Overview](#overview)
43
+ - [Component Props](#component-props)
44
+ - [Accessibility](#accessibility)
45
+ - [Button Width](#button-width)
46
+ - [Layout](#layout)
47
+
48
+ ## Overview
49
+
50
+ <Description of={ButtonGroup} />
51
+
52
+ Note: The `ButtonGroup` component does not come from Chakra because we want to
53
+ display the `Button`s in a column layout as an option, as well as control the
54
+ width.
55
+
56
+ ## Component Props
57
+
58
+ <Canvas withToolbar>
59
+ <Story
60
+ name="ButtonGroup with Controls"
61
+ args={{
62
+ buttonWidth: "default",
63
+ className: undefined,
64
+ id: "button-id",
65
+ isDisabled: false,
66
+ layout: "row",
67
+ }}
68
+ >
69
+ {(args) => (
70
+ <ButtonGroup {...args}>
71
+ <Button buttonType="secondary" id="group-1">
72
+ Button
73
+ </Button>
74
+ <Button id="group-2">Submit</Button>
75
+ </ButtonGroup>
76
+ )}
77
+ </Story>
78
+ </Canvas>
79
+
80
+ <ArgsTable story="ButtonGroup with Controls" />
81
+
82
+ ## Accessibility
83
+
84
+ This component is a wrapper around the `Button` component. For accessibility
85
+ information on the `Button` component, see the
86
+ [Button Accessibility](https://nypl.github.io/nypl-design-system/reservoir/v0/?path=/docs/components-form-elements-button--button-with-controls#accessibility)
87
+ documentation.
88
+
89
+ ## Button Width
90
+
91
+ The `buttonWidth` prop can be used to set the width of the internal `Button`
92
+ components. The default value is `default` and it sets the width to `"fit-content"`
93
+ so the buttons will expand to its content. The `"full"` value will set the width
94
+ to the parent's width.
95
+
96
+ <Canvas>
97
+ <DSProvider>
98
+ <SimpleGrid columns={1}>
99
+ <Heading level="three">default fit-content</Heading>
100
+ <ButtonGroup>
101
+ <Button buttonType="secondary" id="width-fit-1">
102
+ Button
103
+ </Button>
104
+ <Button id="width-fit-2">Submit</Button>
105
+ </ButtonGroup>
106
+ <Heading level="three">full width</Heading>
107
+ <ButtonGroup buttonWidth="full">
108
+ <Button buttonType="secondary" id="width-full-1">
109
+ Button
110
+ </Button>
111
+ <Button id="width-full-2">Submit</Button>
112
+ </ButtonGroup>
113
+ </SimpleGrid>
114
+ </DSProvider>
115
+ </Canvas>
116
+
117
+ ## Layout
118
+
119
+ The `layout` prop can be used to set the layout to either `row` or `column`.
120
+
121
+ <Canvas>
122
+ <DSProvider>
123
+ <SimpleGrid columns={1}>
124
+ <Heading level="three">default row</Heading>
125
+ <ButtonGroup>
126
+ <Button buttonType="secondary" id="row-1">
127
+ Button
128
+ </Button>
129
+ <Button id="row-2">Submit</Button>
130
+ </ButtonGroup>
131
+ <Heading level="three">column</Heading>
132
+ <ButtonGroup layout="column">
133
+ <Button buttonType="secondary" id="column-1">
134
+ Button
135
+ </Button>
136
+ <Button id="column-2">Submit</Button>
137
+ </ButtonGroup>
138
+ <Heading level="three">column layout with full-width</Heading>
139
+ <ButtonGroup buttonWidth="full" layout="column">
140
+ <Button buttonType="secondary" id="column-full-1">
141
+ Button
142
+ </Button>
143
+ <Button id="column-full-2">Submit</Button>
144
+ </ButtonGroup>
145
+ </SimpleGrid>
146
+ </DSProvider>
147
+ </Canvas>
@@ -0,0 +1,141 @@
1
+ import * as React from "react";
2
+ import { render, screen } from "@testing-library/react";
3
+ import { axe } from "jest-axe";
4
+ import renderer from "react-test-renderer";
5
+
6
+ import Button from "../Button/Button";
7
+ import ButtonGroup from "../ButtonGroup/ButtonGroup";
8
+
9
+ describe("ButtonGroup Accessibility", () => {
10
+ it("passes axe accessibility test", async () => {
11
+ const { container } = render(
12
+ <ButtonGroup>
13
+ <Button buttonType="secondary" id="btn-1">
14
+ Button
15
+ </Button>
16
+ <Button id="btn-2">Submit</Button>
17
+ </ButtonGroup>
18
+ );
19
+ expect(await axe(container)).toHaveNoViolations();
20
+ });
21
+ });
22
+
23
+ describe("ButtonGroup", () => {
24
+ it("renders only Button components", () => {
25
+ render(
26
+ <ButtonGroup>
27
+ <Button buttonType="secondary" id="btn-1">
28
+ Button
29
+ </Button>
30
+ <Button id="btn-2">Submit</Button>
31
+ <p data-test="paragraph">This is not a button</p>
32
+ </ButtonGroup>
33
+ );
34
+
35
+ expect(screen.getAllByRole("button")).toHaveLength(2);
36
+ expect(screen.queryByTestId("paragraph")).not.toBeInTheDocument();
37
+ });
38
+
39
+ it("sets all `Button` children as disabled if isDisabled is true", () => {
40
+ const { rerender } = render(
41
+ <ButtonGroup>
42
+ <Button buttonType="secondary" id="btn-1">
43
+ Button
44
+ </Button>
45
+ <Button id="btn-2">Submit</Button>
46
+ </ButtonGroup>
47
+ );
48
+
49
+ expect(screen.getAllByRole("button")[0]).not.toBeDisabled();
50
+ expect(screen.getAllByRole("button")[1]).not.toBeDisabled();
51
+
52
+ rerender(
53
+ <ButtonGroup isDisabled>
54
+ <Button buttonType="secondary" id="btn-1">
55
+ Button
56
+ </Button>
57
+ <Button id="btn-2">Submit</Button>
58
+ </ButtonGroup>
59
+ );
60
+
61
+ expect(screen.getAllByRole("button")[0]).toBeDisabled();
62
+ expect(screen.getAllByRole("button")[1]).toBeDisabled();
63
+ });
64
+
65
+ it("logs a warning when any element that is not a Button is passed ", () => {
66
+ const warn = jest.spyOn(console, "warn");
67
+ render(
68
+ <ButtonGroup>
69
+ <Button buttonType="secondary" id="btn-1">
70
+ Button
71
+ </Button>
72
+ <Button id="btn-2">Submit</Button>
73
+ <p data-test="paragraph">This is not a button</p>
74
+ </ButtonGroup>
75
+ );
76
+ expect(warn).toHaveBeenCalledWith(
77
+ "NYPL Reservoir ButtonGroup: Only Button components can be children of ButtonGroup."
78
+ );
79
+ });
80
+ });
81
+
82
+ describe("ButtonGroup Snapshot", () => {
83
+ it("renders the UI snapshot correctly", () => {
84
+ const basic = renderer
85
+ .create(
86
+ <ButtonGroup>
87
+ <Button buttonType="secondary" id="btn-1">
88
+ Button
89
+ </Button>
90
+ <Button id="btn-2">Submit</Button>
91
+ </ButtonGroup>
92
+ )
93
+ .toJSON();
94
+ const fullWidth = renderer
95
+ .create(
96
+ <ButtonGroup buttonWidth="full">
97
+ <Button buttonType="secondary" id="btn-1">
98
+ Button
99
+ </Button>
100
+ <Button id="btn-2">Submit</Button>
101
+ </ButtonGroup>
102
+ )
103
+ .toJSON();
104
+ const column = renderer
105
+ .create(
106
+ <ButtonGroup layout="column">
107
+ <Button buttonType="secondary" id="btn-1">
108
+ Button
109
+ </Button>
110
+ <Button id="btn-2">Submit</Button>
111
+ </ButtonGroup>
112
+ )
113
+ .toJSON();
114
+ const withChakraProps = renderer
115
+ .create(
116
+ <ButtonGroup p="s" color="ui.error.primary">
117
+ <Button buttonType="secondary" id="btn-1">
118
+ Button
119
+ </Button>
120
+ <Button id="btn-2">Submit</Button>
121
+ </ButtonGroup>
122
+ )
123
+ .toJSON();
124
+ const withOtherProps = renderer
125
+ .create(
126
+ <ButtonGroup data-testid="testid">
127
+ <Button buttonType="secondary" id="btn-1">
128
+ Button
129
+ </Button>
130
+ <Button id="btn-2">Submit</Button>
131
+ </ButtonGroup>
132
+ )
133
+ .toJSON();
134
+
135
+ expect(basic).toMatchSnapshot();
136
+ expect(fullWidth).toMatchSnapshot();
137
+ expect(column).toMatchSnapshot();
138
+ expect(withChakraProps).toMatchSnapshot();
139
+ expect(withOtherProps).toMatchSnapshot();
140
+ });
141
+ });
@@ -0,0 +1,99 @@
1
+ import { chakra, Stack, useStyleConfig } from "@chakra-ui/react";
2
+ import * as React from "react";
3
+
4
+ import Button from "../Button/Button";
5
+ import { LayoutTypes } from "../../helpers/types";
6
+ import useWindowSize from "../../hooks/useWindowSize";
7
+
8
+ export type ButtonGroupWidths = "default" | "full";
9
+
10
+ interface ButtonGroupProps {
11
+ /** Sets the width to "default" (for "fit-content") or "full". */
12
+ buttonWidth?: ButtonGroupWidths;
13
+ /** Additional className to use. */
14
+ className?: string;
15
+ /** ID that other components can cross reference for accessibility purposes. */
16
+ id?: string;
17
+ /** Set's the disabled state to all the internal `Button` components. */
18
+ isDisabled?: boolean;
19
+ /** Renders the layout of `Button` components in a row or column. */
20
+ layout?: LayoutTypes;
21
+ }
22
+
23
+ const noop = () => {};
24
+
25
+ /**
26
+ * A simple wrapper to group `Button` components together. The layout can be set
27
+ * to row or column and the width of internal `Button` components can be set to
28
+ * the parent's full width or the `Button`'s content width
29
+ */
30
+ export const ButtonGroup = chakra(
31
+ (props: React.PropsWithChildren<ButtonGroupProps>) => {
32
+ const {
33
+ buttonWidth = "default",
34
+ children,
35
+ className = "",
36
+ id,
37
+ isDisabled = false,
38
+ layout = "row",
39
+ ...rest
40
+ } = props;
41
+ const newChildren: JSX.Element[] = [];
42
+ // Based on --nypl-breakpoint-medium
43
+ const breakpointMedium = 600;
44
+ const [finalLayout, setFinalLayout] = React.useState<LayoutTypes>(layout);
45
+ const [finalButtonWidth, setFinalButtonWidth] =
46
+ React.useState<ButtonGroupWidths>(buttonWidth);
47
+ const windowDimensions = useWindowSize();
48
+ React.useEffect(() => {
49
+ // When on a mobile device or narrow window, always set the layout to
50
+ // column and the button width to "full".
51
+ if (windowDimensions.width <= breakpointMedium) {
52
+ setFinalButtonWidth("full");
53
+ setFinalLayout("column");
54
+ } else {
55
+ // Otherwise, set the layout and button width to the values
56
+ // passed in via the `buttonWidth` and `layout` props.
57
+ setFinalButtonWidth(buttonWidth);
58
+ setFinalLayout(layout);
59
+ }
60
+ }, [buttonWidth, layout, windowDimensions.width]);
61
+ const styles = useStyleConfig("ButtonGroup", {
62
+ buttonWidth: finalButtonWidth,
63
+ });
64
+
65
+ React.Children.map(
66
+ children as JSX.Element,
67
+ (child: React.ReactElement, key: number) => {
68
+ if (child.type !== Button) {
69
+ // Special case for Storybook MDX documentation.
70
+ if (child.props.mdxType && child.props.mdxType === "Button") {
71
+ noop();
72
+ } else {
73
+ console.warn(
74
+ "NYPL Reservoir ButtonGroup: Only Button components can be children of ButtonGroup."
75
+ );
76
+ return;
77
+ }
78
+ }
79
+ newChildren.push(React.cloneElement(child, { key, isDisabled }));
80
+ }
81
+ );
82
+
83
+ return (
84
+ <Stack
85
+ id={id}
86
+ className={className}
87
+ direction={finalLayout}
88
+ // Always set the spacing to "8px".
89
+ spacing="xs"
90
+ sx={styles}
91
+ {...rest}
92
+ >
93
+ {newChildren}
94
+ </Stack>
95
+ );
96
+ }
97
+ );
98
+
99
+ export default ButtonGroup;
@@ -0,0 +1,117 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`ButtonGroup Snapshot renders the UI snapshot correctly 1`] = `
4
+ <div
5
+ className="chakra-stack css-ytb711"
6
+ >
7
+ <button
8
+ className="chakra-button css-1xdhyk6"
9
+ data-testid="button"
10
+ id="btn-1"
11
+ type="button"
12
+ >
13
+ Button
14
+ </button>
15
+ <button
16
+ className="chakra-button css-1xdhyk6"
17
+ data-testid="button"
18
+ id="btn-2"
19
+ type="button"
20
+ >
21
+ Submit
22
+ </button>
23
+ </div>
24
+ `;
25
+
26
+ exports[`ButtonGroup Snapshot renders the UI snapshot correctly 2`] = `
27
+ <div
28
+ className="chakra-stack css-ytb711"
29
+ >
30
+ <button
31
+ className="chakra-button css-1xdhyk6"
32
+ data-testid="button"
33
+ id="btn-1"
34
+ type="button"
35
+ >
36
+ Button
37
+ </button>
38
+ <button
39
+ className="chakra-button css-1xdhyk6"
40
+ data-testid="button"
41
+ id="btn-2"
42
+ type="button"
43
+ >
44
+ Submit
45
+ </button>
46
+ </div>
47
+ `;
48
+
49
+ exports[`ButtonGroup Snapshot renders the UI snapshot correctly 3`] = `
50
+ <div
51
+ className="chakra-stack css-6dfzd0"
52
+ >
53
+ <button
54
+ className="chakra-button css-1xdhyk6"
55
+ data-testid="button"
56
+ id="btn-1"
57
+ type="button"
58
+ >
59
+ Button
60
+ </button>
61
+ <button
62
+ className="chakra-button css-1xdhyk6"
63
+ data-testid="button"
64
+ id="btn-2"
65
+ type="button"
66
+ >
67
+ Submit
68
+ </button>
69
+ </div>
70
+ `;
71
+
72
+ exports[`ButtonGroup Snapshot renders the UI snapshot correctly 4`] = `
73
+ <div
74
+ className="chakra-stack css-1pxah8o"
75
+ >
76
+ <button
77
+ className="chakra-button css-1xdhyk6"
78
+ data-testid="button"
79
+ id="btn-1"
80
+ type="button"
81
+ >
82
+ Button
83
+ </button>
84
+ <button
85
+ className="chakra-button css-1xdhyk6"
86
+ data-testid="button"
87
+ id="btn-2"
88
+ type="button"
89
+ >
90
+ Submit
91
+ </button>
92
+ </div>
93
+ `;
94
+
95
+ exports[`ButtonGroup Snapshot renders the UI snapshot correctly 5`] = `
96
+ <div
97
+ className="chakra-stack css-ytb711"
98
+ data-testid="testid"
99
+ >
100
+ <button
101
+ className="chakra-button css-1xdhyk6"
102
+ data-testid="button"
103
+ id="btn-1"
104
+ type="button"
105
+ >
106
+ Button
107
+ </button>
108
+ <button
109
+ className="chakra-button css-1xdhyk6"
110
+ data-testid="button"
111
+ id="btn-2"
112
+ type="button"
113
+ >
114
+ Submit
115
+ </button>
116
+ </div>
117
+ `;