@nypl/design-system-react-components 0.23.4 → 0.25.1

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 (307) hide show
  1. package/CHANGELOG.md +98 -1
  2. package/README.md +46 -11
  3. package/dist/components/Accordion/Accordion.d.ts +14 -14
  4. package/dist/components/Autosuggest/Autosuggest.stories.d.ts +1 -0
  5. package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +11 -14
  6. package/dist/components/Breadcrumbs/BreadcrumbsTypes.d.ts +6 -0
  7. package/dist/components/Button/Button.d.ts +6 -13
  8. package/dist/components/Button/ButtonTypes.d.ts +5 -3
  9. package/dist/components/Card/Card.d.ts +59 -10
  10. package/dist/components/Card/CardTypes.d.ts +19 -0
  11. package/dist/components/CardEdition/CardEdition.d.ts +21 -0
  12. package/dist/components/{StyleGuide/Colors.stories.d.ts → CardEdition/CardEdition.stories.d.ts} +5 -2
  13. package/dist/components/Checkbox/Checkbox.d.ts +21 -16
  14. package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +43 -0
  15. package/dist/components/CheckboxGroup/CheckboxGroupLayoutTypes.d.ts +4 -0
  16. package/dist/components/DatePicker/DatePicker.d.ts +79 -0
  17. package/dist/components/DatePicker/DatePickerTypes.d.ts +5 -0
  18. package/dist/components/Form/Form.d.ts +16 -8
  19. package/dist/components/Form/FormTypes.d.ts +2 -0
  20. package/dist/components/Grid/GridTypes.d.ts +9 -0
  21. package/dist/components/Grid/SimpleGrid.d.ts +14 -0
  22. package/dist/components/Heading/Heading.d.ts +9 -11
  23. package/dist/components/Heading/{HeadingDisplaySizes.d.ts → HeadingTypes.d.ts} +8 -0
  24. package/dist/components/HelperErrorText/HelperErrorText.stories.d.ts +2 -1
  25. package/dist/components/Hero/Hero.d.ts +19 -14
  26. package/dist/components/Hero/HeroTypes.d.ts +10 -5
  27. package/dist/components/Icons/Icon.d.ts +13 -16
  28. package/dist/components/Icons/IconSvgs.d.ts +4 -0
  29. package/dist/components/Icons/IconTypes.d.ts +78 -60
  30. package/dist/components/Image/Image.stories.d.ts +2 -1
  31. package/dist/components/Label/Label.d.ts +10 -26
  32. package/dist/components/Link/Link.d.ts +8 -12
  33. package/dist/components/List/List.stories.d.ts +1 -0
  34. package/dist/components/Radio/Radio.d.ts +30 -24
  35. package/dist/components/RadioGroup/RadioGroup.d.ts +40 -0
  36. package/dist/components/RadioGroup/RadioGroupLayoutTypes.d.ts +4 -0
  37. package/dist/components/SearchBar/SearchBar.d.ts +45 -27
  38. package/dist/components/Select/Select.d.ts +34 -35
  39. package/dist/components/Select/SelectTypes.d.ts +4 -0
  40. package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +1 -1
  41. package/dist/components/SkeletonLoader/SkeletonLoaderTypes.d.ts +2 -2
  42. package/dist/components/StatusBadge/StatusBadge.d.ts +8 -6
  43. package/dist/components/StatusBadge/StatusBadgeTypes.d.ts +5 -0
  44. package/dist/components/Tabs/Tabs.d.ts +25 -0
  45. package/dist/components/Template/Template.d.ts +91 -0
  46. package/dist/components/Text/Text.d.ts +16 -0
  47. package/dist/components/Text/TextTypes.d.ts +6 -0
  48. package/dist/components/TextInput/TextInput.d.ts +37 -30
  49. package/dist/components/TextInput/TextInputTypes.d.ts +5 -0
  50. package/dist/design-system-react-components.cjs.development.js +4102 -917
  51. package/dist/design-system-react-components.cjs.development.js.map +1 -1
  52. package/dist/design-system-react-components.cjs.production.min.js +1 -1
  53. package/dist/design-system-react-components.cjs.production.min.js.map +1 -1
  54. package/dist/design-system-react-components.esm.js +4023 -920
  55. package/dist/design-system-react-components.esm.js.map +1 -1
  56. package/dist/index.d.ts +23 -5
  57. package/dist/resources.scss +133 -24
  58. package/dist/styles.css +1 -1
  59. package/dist/theme/components/accordion.d.ts +25 -0
  60. package/dist/theme/components/breadcrumb.d.ts +90 -0
  61. package/dist/theme/components/button.d.ts +109 -0
  62. package/dist/theme/components/checkbox.d.ts +91 -0
  63. package/dist/theme/components/customCheckboxGroup.d.ts +18 -0
  64. package/dist/theme/components/customRadioGroup.d.ts +18 -0
  65. package/dist/theme/components/global.d.ts +55 -0
  66. package/dist/theme/components/globalMixins.d.ts +15 -0
  67. package/dist/theme/components/heading.d.ts +110 -0
  68. package/dist/theme/components/hero.d.ts +492 -0
  69. package/dist/theme/components/icon.d.ts +13 -0
  70. package/dist/theme/components/label.d.ts +16 -0
  71. package/dist/theme/components/link.d.ts +45 -0
  72. package/dist/theme/components/radio.d.ts +95 -0
  73. package/dist/theme/components/searchBar.d.ts +20 -0
  74. package/dist/theme/components/select.d.ts +58 -0
  75. package/dist/theme/components/statusBadge.d.ts +25 -0
  76. package/dist/theme/components/tabs.d.ts +85 -0
  77. package/dist/theme/components/template.d.ts +105 -0
  78. package/dist/theme/components/text.d.ts +20 -0
  79. package/dist/theme/components/textInput.d.ts +105 -0
  80. package/dist/theme/foundations/breakpoints.d.ts +23 -0
  81. package/dist/theme/foundations/colors.d.ts +3 -0
  82. package/dist/theme/foundations/global.d.ts +23 -0
  83. package/dist/theme/foundations/shadows.d.ts +4 -0
  84. package/dist/theme/foundations/spacing.d.ts +77 -0
  85. package/dist/theme/foundations/typography.d.ts +8 -0
  86. package/dist/theme/index.d.ts +20 -0
  87. package/dist/theme/provider.d.ts +5 -0
  88. package/dist/theme/types.d.ts +1 -0
  89. package/dist/utils/utils.d.ts +6 -0
  90. package/package.json +9 -2
  91. package/src/components/Accordion/Accordion.stories.mdx +233 -33
  92. package/src/components/Accordion/Accordion.test.tsx +135 -19
  93. package/src/components/Accordion/Accordion.tsx +81 -56
  94. package/src/components/Autosuggest/Autosuggest.stories.mdx +4 -3
  95. package/src/components/Autosuggest/Autosuggest.stories.tsx +1 -1
  96. package/src/components/Autosuggest/_Autosuggest.scss +2 -2
  97. package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +57 -56
  98. package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +31 -25
  99. package/src/components/Breadcrumbs/Breadcrumbs.tsx +71 -73
  100. package/src/components/Breadcrumbs/BreadcrumbsTypes.tsx +6 -0
  101. package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +100 -0
  102. package/src/components/Button/Button.stories.mdx +125 -138
  103. package/src/components/Button/Button.test.tsx +65 -11
  104. package/src/components/Button/Button.tsx +72 -68
  105. package/src/components/Button/ButtonTypes.tsx +4 -2
  106. package/src/components/Button/_Button.scss +7 -92
  107. package/src/components/Button/__snapshots__/Button.test.tsx.snap +58 -3
  108. package/src/components/Card/Card.stories.mdx +694 -0
  109. package/src/components/Card/Card.test.tsx +97 -102
  110. package/src/components/Card/Card.tsx +182 -31
  111. package/src/components/Card/CardTypes.tsx +21 -0
  112. package/src/components/Card/_Card.scss +234 -49
  113. package/src/components/{Card/Card.stories.tsx → CardEdition/CardEdition.stories.tsx} +32 -22
  114. package/src/components/CardEdition/CardEdition.test.tsx +395 -0
  115. package/src/components/CardEdition/CardEdition.tsx +60 -0
  116. package/src/components/CardEdition/_CardEdition.scss +138 -0
  117. package/src/components/Chakra/Box.stories.mdx +57 -0
  118. package/src/components/Chakra/Center.stories.mdx +99 -0
  119. package/src/components/Chakra/Grid.stories.mdx +79 -0
  120. package/src/components/Chakra/Stack.stories.mdx +93 -0
  121. package/src/components/Checkbox/Checkbox.stories.mdx +57 -35
  122. package/src/components/Checkbox/Checkbox.test.tsx +117 -147
  123. package/src/components/Checkbox/Checkbox.tsx +76 -50
  124. package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +325 -0
  125. package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +249 -0
  126. package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +345 -0
  127. package/src/components/CheckboxGroup/CheckboxGroup.tsx +148 -0
  128. package/src/components/CheckboxGroup/CheckboxGroupLayoutTypes.tsx +4 -0
  129. package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +1360 -0
  130. package/src/components/DatePicker/DatePicker.stories.mdx +284 -0
  131. package/src/components/DatePicker/DatePicker.test.tsx +657 -0
  132. package/src/components/DatePicker/DatePicker.tsx +396 -0
  133. package/src/components/DatePicker/DatePickerTypes.tsx +5 -0
  134. package/src/components/DatePicker/_DatePicker.scss +76 -0
  135. package/src/components/Form/Form.stories.mdx +130 -27
  136. package/src/components/Form/Form.test.tsx +78 -36
  137. package/src/components/Form/Form.tsx +53 -19
  138. package/src/components/Form/FormTypes.tsx +3 -0
  139. package/src/components/Form/__snapshots__/Form.test.tsx.snap +38 -0
  140. package/src/components/Grid/GridTypes.tsx +9 -0
  141. package/src/components/Grid/SimpleGrid.stories.mdx +275 -0
  142. package/src/components/Grid/SimpleGrid.test.tsx +66 -0
  143. package/src/components/Grid/SimpleGrid.tsx +37 -0
  144. package/src/components/Grid/__snapshots__/SimpleGrid.test.tsx.snap +8 -0
  145. package/src/components/Heading/Heading.stories.mdx +63 -33
  146. package/src/components/Heading/Heading.test.tsx +24 -16
  147. package/src/components/Heading/Heading.tsx +54 -38
  148. package/src/components/Heading/{HeadingDisplaySizes.tsx → HeadingTypes.tsx} +9 -0
  149. package/src/components/HelperErrorText/HelperErrorText.stories.tsx +2 -1
  150. package/src/components/HelperErrorText/_HelperErrorText.scss +1 -1
  151. package/src/components/Hero/Hero.stories.mdx +195 -85
  152. package/src/components/Hero/Hero.test.tsx +544 -113
  153. package/src/components/Hero/Hero.tsx +80 -93
  154. package/src/components/Hero/HeroTypes.tsx +17 -5
  155. package/src/components/Hero/__snapshots__/Hero.test.tsx.snap +307 -0
  156. package/src/components/HorizontalRule/HorizontalRule.stories.mdx +6 -1
  157. package/src/components/HorizontalRule/_HorizontalRule.scss +1 -1
  158. package/src/components/Icons/Icon.stories.mdx +89 -74
  159. package/src/components/Icons/Icon.test.tsx +30 -22
  160. package/src/components/Icons/Icon.tsx +63 -61
  161. package/src/components/Icons/IconSvgs.tsx +8 -0
  162. package/src/components/Icons/IconTypes.tsx +80 -60
  163. package/src/components/Image/Image.stories.tsx +2 -1
  164. package/src/components/Input/_Input.scss +2 -2
  165. package/src/components/Label/Label.stories.mdx +77 -0
  166. package/src/components/Label/Label.test.tsx +43 -12
  167. package/src/components/Label/Label.tsx +28 -45
  168. package/src/components/Label/__snapshots__/Label.test.tsx.snap +41 -0
  169. package/src/components/Link/Link.stories.mdx +47 -41
  170. package/src/components/Link/Link.test.tsx +33 -44
  171. package/src/components/Link/Link.tsx +114 -100
  172. package/src/components/List/List.stories.mdx +7 -3
  173. package/src/components/List/List.stories.tsx +14 -9
  174. package/src/components/List/List.test.tsx +12 -8
  175. package/src/components/List/List.tsx +9 -7
  176. package/src/components/List/_List.scss +3 -3
  177. package/src/components/Modal/Modal.stories.mdx +7 -3
  178. package/src/components/Modal/_Modal.scss +1 -1
  179. package/src/components/Notification/Notification.stories.mdx +99 -65
  180. package/src/components/Notification/Notification.test.tsx +3 -16
  181. package/src/components/Notification/Notification.tsx +12 -12
  182. package/src/components/Notification/_Notification.scss +5 -4
  183. package/src/components/Notification/__snapshots__/Notification.test.tsx.snap +1 -1
  184. package/src/components/Pagination/Pagination.stories.mdx +7 -1
  185. package/src/components/Pagination/Pagination.test.tsx +16 -10
  186. package/src/components/Radio/Radio.stories.mdx +57 -46
  187. package/src/components/Radio/Radio.test.tsx +92 -138
  188. package/src/components/Radio/Radio.tsx +70 -69
  189. package/src/components/Radio/__snapshots__/Radio.test.tsx.snap +250 -0
  190. package/src/components/RadioGroup/RadioGroup.stories.mdx +247 -0
  191. package/src/components/RadioGroup/RadioGroup.test.tsx +327 -0
  192. package/src/components/RadioGroup/RadioGroup.tsx +154 -0
  193. package/src/components/RadioGroup/RadioGroupLayoutTypes.tsx +4 -0
  194. package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +1101 -0
  195. package/src/components/SearchBar/SearchBar.Test.tsx +151 -16
  196. package/src/components/SearchBar/SearchBar.stories.mdx +196 -224
  197. package/src/components/SearchBar/SearchBar.tsx +151 -46
  198. package/src/components/Select/Select.stories.mdx +193 -168
  199. package/src/components/Select/Select.test.tsx +129 -324
  200. package/src/components/Select/Select.tsx +120 -160
  201. package/src/components/Select/SelectTypes.tsx +4 -0
  202. package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +18 -29
  203. package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +7 -7
  204. package/src/components/SkeletonLoader/SkeletonLoader.tsx +4 -2
  205. package/src/components/SkeletonLoader/SkeletonLoaderTypes.tsx +2 -2
  206. package/src/components/SkeletonLoader/_SkeletonLoader.scss +3 -3
  207. package/src/components/StatusBadge/StatusBadge.stories.mdx +91 -0
  208. package/src/components/StatusBadge/StatusBadge.test.tsx +35 -7
  209. package/src/components/StatusBadge/StatusBadge.tsx +24 -25
  210. package/src/components/StatusBadge/StatusBadgeTypes.tsx +5 -0
  211. package/src/components/StatusBadge/__snapshots__/StatusBadge.test.tsx.snap +28 -0
  212. package/src/components/StyleGuide/Bidirectionality.stories.mdx +112 -90
  213. package/src/components/StyleGuide/Buttons.stories.mdx +98 -100
  214. package/src/components/StyleGuide/Colors.stories.mdx +336 -0
  215. package/src/components/StyleGuide/Forms.stories.mdx +85 -0
  216. package/src/components/StyleGuide/Iconography.stories.mdx +86 -93
  217. package/src/components/StyleGuide/Spacing.stories.mdx +0 -1
  218. package/src/components/StyleGuide/Typography.stories.mdx +164 -166
  219. package/src/components/StyleGuide/UIDocCard.tsx +4 -4
  220. package/src/components/Tabs/Tabs.stories.mdx +221 -0
  221. package/src/components/Tabs/Tabs.test.tsx +264 -0
  222. package/src/components/Tabs/Tabs.tsx +220 -0
  223. package/src/components/Template/Template.stories.mdx +574 -0
  224. package/src/components/Template/Template.test.tsx +124 -0
  225. package/src/components/Template/Template.tsx +226 -0
  226. package/src/components/Text/Text.stories.mdx +70 -0
  227. package/src/components/Text/Text.test.tsx +63 -0
  228. package/src/components/Text/Text.tsx +55 -0
  229. package/src/components/Text/TextTypes.tsx +6 -0
  230. package/src/components/Text/__snapshots__/Text.test.tsx.snap +33 -0
  231. package/src/components/TextInput/TextInput.stories.mdx +90 -90
  232. package/src/components/TextInput/TextInput.test.tsx +103 -83
  233. package/src/components/TextInput/TextInput.tsx +108 -91
  234. package/src/components/TextInput/TextInputTypes.tsx +6 -0
  235. package/src/components/VideoPlayer/VideoPlayer.stories.mdx +2 -1
  236. package/src/components/VideoPlayer/VideoPlayer.tsx +4 -2
  237. package/src/components/VideoPlayer/_VideoPlayer.scss +1 -1
  238. package/src/docs/Chakra.stories.mdx +341 -0
  239. package/src/docs/Intro.stories.mdx +31 -24
  240. package/src/index.ts +70 -5
  241. package/src/styles/01-colors/_colors-brand.scss +6 -4
  242. package/src/styles/01-colors/_colors-utility.scss +14 -15
  243. package/src/styles/03-space/_space-inline.scss +47 -7
  244. package/src/styles/03-space/_space-inset.scss +33 -5
  245. package/src/styles/03-space/_space-stack.scss +48 -8
  246. package/src/styles/base/_02-breakpoints.scss +5 -4
  247. package/src/styles/base/_04-base.scss +2 -1
  248. package/src/styles/base/_place-holder.scss +1 -1
  249. package/src/styles/base/_typography.scss +1 -29
  250. package/src/styles.scss +22 -25
  251. package/src/theme/components/accordion.ts +30 -0
  252. package/src/theme/components/breadcrumb.ts +77 -0
  253. package/src/theme/components/button.ts +125 -0
  254. package/src/theme/components/checkbox.ts +107 -0
  255. package/src/theme/components/customCheckboxGroup.ts +12 -0
  256. package/src/theme/components/customRadioGroup.ts +12 -0
  257. package/src/theme/components/global.ts +71 -0
  258. package/src/theme/components/globalMixins.ts +16 -0
  259. package/src/theme/components/heading.ts +72 -0
  260. package/src/theme/components/hero.ts +239 -0
  261. package/src/theme/components/icon.ts +79 -0
  262. package/src/theme/components/label.ts +17 -0
  263. package/src/theme/components/link.ts +47 -0
  264. package/src/theme/components/radio.ts +106 -0
  265. package/src/theme/components/searchBar.ts +21 -0
  266. package/src/theme/components/select.ts +50 -0
  267. package/src/theme/components/statusBadge.ts +27 -0
  268. package/src/theme/components/tabs.ts +79 -0
  269. package/src/theme/components/template.ts +114 -0
  270. package/src/theme/components/text.ts +31 -0
  271. package/src/theme/components/textInput.ts +61 -0
  272. package/src/theme/foundations/breakpoints.ts +24 -0
  273. package/src/theme/foundations/colors.ts +208 -0
  274. package/src/theme/foundations/global.ts +26 -0
  275. package/src/theme/foundations/shadows.ts +5 -0
  276. package/src/theme/foundations/spacing.ts +85 -0
  277. package/src/theme/foundations/typography.ts +35 -0
  278. package/src/theme/index.ts +88 -0
  279. package/src/theme/provider.tsx +9 -0
  280. package/src/theme/types.ts +1 -0
  281. package/src/utils/componentCategories.ts +56 -21
  282. package/src/utils/utils.ts +13 -0
  283. package/dist/components/Accordion/Accordion.stories.d.ts +0 -5
  284. package/dist/components/Card/Card.stories.d.ts +0 -27
  285. package/dist/components/Label/Label.stories.d.ts +0 -12
  286. package/dist/components/StatusBadge/StatusBadge.stories.d.ts +0 -8
  287. package/dist/components/Template/Template.stories.d.ts +0 -29
  288. package/src/components/Accordion/Accordion.stories.tsx +0 -65
  289. package/src/components/Accordion/_Accordion.scss +0 -81
  290. package/src/components/Breadcrumbs/_Breadcrumbs.scss +0 -97
  291. package/src/components/Checkbox/_Checkbox.scss +0 -97
  292. package/src/components/Form/_Form.scss +0 -28
  293. package/src/components/Heading/_Heading.scss +0 -163
  294. package/src/components/Hero/_Hero.scss +0 -256
  295. package/src/components/Icons/_Icons.scss +0 -116
  296. package/src/components/Label/Label.stories.tsx +0 -30
  297. package/src/components/Label/_Label.scss +0 -22
  298. package/src/components/Link/_Link.scss +0 -73
  299. package/src/components/Radio/_Radio.scss +0 -84
  300. package/src/components/SearchBar/_SearchBar.scss +0 -16
  301. package/src/components/Select/_Select.scss +0 -82
  302. package/src/components/StatusBadge/StatusBadge.stories.tsx +0 -33
  303. package/src/components/StatusBadge/_StatusBadge.scss +0 -23
  304. package/src/components/StyleGuide/Colors.stories.tsx +0 -288
  305. package/src/components/Template/Template.stories.tsx +0 -85
  306. package/src/components/Template/_Template.scss +0 -63
  307. package/src/components/TextInput/_TextInput.scss +0 -59
@@ -3,18 +3,22 @@ import {
3
3
  Story,
4
4
  Canvas,
5
5
  ArgsTable,
6
- Preview,
7
6
  Description,
8
7
  } from "@storybook/addon-docs/blocks";
9
8
  import { withDesign } from "storybook-addon-designs";
10
9
 
11
- import Button from "./Button";
10
+ import Button, { ButtonGroup } from "./Button";
12
11
  import { ButtonTypes } from "./ButtonTypes";
13
12
  import Icon from "../Icons/Icon";
14
- import { IconNames, IconRotationTypes } from "../Icons/IconTypes";
15
- import { action } from "@storybook/addon-actions";
13
+ import {
14
+ IconNames,
15
+ IconRotationTypes,
16
+ IconAlign,
17
+ IconSizes,
18
+ } from "../Icons/IconTypes";
16
19
  import getCSSVariable from "../../helpers/getCSSVariable";
17
20
  import { getCategory } from "../../utils/componentCategories";
21
+ import DSProvider from "../../theme/provider";
18
22
 
19
23
  <Meta
20
24
  title={getCategory("Button")}
@@ -32,61 +36,51 @@ import { getCategory } from "../../utils/componentCategories";
32
36
 
33
37
  # Button
34
38
 
39
+ | Component Version | DS Version |
40
+ | ----------------- | ---------- |
41
+ | Added | `0.0.4` |
42
+ | Latest | `0.25.0` |
43
+
35
44
  <Description of={Button} />
36
45
 
37
46
  Update the `buttonType` in the Controls section to see the types of buttons
38
47
  that can be rendered.
39
48
 
40
49
  - `ButtonTypes.Primary` is used for actions that move the user forward.
41
- - `ButtonTypes.Secondary` is used for actions taht move the user back, such as cancellations
42
- - `ButtonTypes.Pill` is used for equally weighted actions within cards and always in a set
43
- - `ButtonTypes.Link` is used for equally weighted actions in a text based list
50
+ - `ButtonTypes.Secondary` is used for actions that move the user back, such as cancellations.
51
+ - `ButtonTypes.Pill` is used for equally weighted actions within cards and always in a set.
52
+ - `ButtonTypes.Link` is used for equally weighted actions in a text based list.
53
+
54
+ When one and only one `Icon` component is passed inside a `Button` component,
55
+ it will automatically be configured to use the `"icon-only"` type.
44
56
 
45
- <Preview withToolbar>
57
+ <Canvas withToolbar>
46
58
  <Story name="Basic">{(args) => <Button {...args}>Button Text</Button>}</Story>
47
- </Preview>
59
+ </Canvas>
48
60
 
49
61
  <ArgsTable story="Basic" />
50
62
 
51
63
  ## Button Groups
52
64
 
53
- Primary and secondary buttons can be used in groups like so:
65
+ Primary and secondary buttons should be grouped like in the following example.
66
+ The `ButtonGroup` component, which is directly exported from Chakra UI, should
67
+ be used to wrap the `Button` cmoponent.
54
68
 
55
69
  <Canvas>
56
70
  <Story name="Button Groups">
57
- <div
58
- style={{
59
- display: "flex",
60
- justifyContent: "space-between",
61
- width: "180px",
62
- }}
63
- >
71
+ <ButtonGroup>
64
72
  <Button buttonType={ButtonTypes.Secondary}>Button</Button>
65
73
  <Button buttonType={ButtonTypes.Primary}>Submit</Button>
66
- </div>
67
- <br />
68
- <div
69
- style={{
70
- display: "flex",
71
- justifyContent: "space-between",
72
- width: "280px",
73
- }}
74
- >
75
- <Button buttonType={ButtonTypes.Secondary}>
76
- <span style={{ width: "100px" }}>Button</span>
77
- </Button>
78
- <Button buttonType={ButtonTypes.Primary}>
79
- <span style={{ width: "100px" }}>Submit</span>
80
- </Button>
81
- </div>
74
+ </ButtonGroup>
82
75
  </Story>
83
76
  </Canvas>
84
77
 
85
78
  ## With Icons
86
79
 
87
80
  The `Icon` component collaborates great with the `Button` component. Check out
88
- `src/components/Icons/IconTypes` to see the list of icon and logo names that
89
- can be rendered or check out the Controls section for this story.
81
+ [`src/components/Icons/IconTypes`](https://github.com/NYPL/nypl-design-system/blob/development/src/components/Icons/IconTypes.tsx)
82
+ to see the full list of icon and logo names that can be rendered. Use the
83
+ Controls for this Story section to preview a `Button` with the selected icon.
90
84
 
91
85
  <Canvas>
92
86
  <Story
@@ -94,14 +88,14 @@ can be rendered or check out the Controls section for this story.
94
88
  args={{
95
89
  displayLeft: true,
96
90
  buttonText: "Button Text",
97
- iconType: IconNames.search,
91
+ iconType: IconNames.Search,
98
92
  }}
99
93
  argTypes={{
100
94
  iconType: {
101
95
  control: {
102
96
  type: "select",
103
- options: IconNames,
104
97
  },
98
+ options: Object.values(IconNames).map((value) => value),
105
99
  },
106
100
  }}
107
101
  >
@@ -110,16 +104,16 @@ can be rendered or check out the Controls section for this story.
110
104
  {args.displayLeft && (
111
105
  <Icon
112
106
  name={args.iconType}
113
- decorative={true}
114
- modifiers={["small", "icon-left"]}
107
+ align={IconAlign.Left}
108
+ size={IconSizes.Small}
115
109
  />
116
110
  )}
117
111
  {args.buttonText}
118
112
  {!args.displayLeft && (
119
113
  <Icon
120
114
  name={args.iconType}
121
- decorative={true}
122
- modifiers={["small", "icon-right"]}
115
+ align={IconAlign.Right}
116
+ size={IconSizes.Small}
123
117
  />
124
118
  )}
125
119
  </Button>
@@ -130,32 +124,28 @@ can be rendered or check out the Controls section for this story.
130
124
  The icon can be placed to the left or the right of the button text.
131
125
 
132
126
  <Canvas>
133
- <div
134
- style={{
135
- display: "flex",
136
- justifyContent: "space-between",
137
- width: "220px",
138
- }}
139
- >
140
- <Button buttonType={ButtonTypes.Secondary}>
141
- <Icon
142
- name={IconNames.arrow}
143
- decorative={true}
144
- iconRotation={IconRotationTypes.rotate90}
145
- modifiers={["small", "icon-left"]}
146
- />
147
- Previous
148
- </Button>
149
- <Button buttonType={ButtonTypes.Secondary}>
150
- Next
151
- <Icon
152
- name={IconNames.arrow}
153
- decorative={true}
154
- iconRotation={IconRotationTypes.rotate270}
155
- modifiers={["small", "icon-right"]}
156
- />
157
- </Button>
158
- </div>
127
+ <DSProvider>
128
+ <ButtonGroup>
129
+ <Button buttonType={ButtonTypes.Secondary}>
130
+ <Icon
131
+ name={IconNames.Arrow}
132
+ iconRotation={IconRotationTypes.Rotate90}
133
+ align={IconAlign.Left}
134
+ size={IconSizes.Small}
135
+ />
136
+ Previous
137
+ </Button>
138
+ <Button buttonType={ButtonTypes.Secondary}>
139
+ Next
140
+ <Icon
141
+ name={IconNames.Arrow}
142
+ iconRotation={IconRotationTypes.Rotate270}
143
+ align={IconAlign.Right}
144
+ size={IconSizes.Small}
145
+ />
146
+ </Button>
147
+ </ButtonGroup>
148
+ </DSProvider>
159
149
  </Canvas>
160
150
 
161
151
  Text in a button is optional if an icon is rendered, but make sure that there
@@ -163,94 +153,91 @@ is an `aria-label` passed to the `Button` component through the `attributes` pro
163
153
  `attributes={{ "aria-label": "Previous" }}`
164
154
 
165
155
  <Canvas>
166
- <div
167
- style={{
168
- display: "flex",
169
- justifyContent: "space-between",
170
- width: "200px",
171
- }}
172
- >
173
- <Button
174
- buttonType={ButtonTypes.Secondary}
175
- attributes={{
176
- "aria-label": "Previous",
177
- }}
178
- >
179
- <Icon
180
- name={IconNames.arrow}
181
- decorative={true}
182
- iconRotation={IconRotationTypes.rotate90}
183
- modifiers={["small"]}
184
- />
185
- </Button>
186
- <Button
187
- buttonType={ButtonTypes.Secondary}
188
- attributes={{
189
- "aria-label": "Next",
190
- }}
191
- >
192
- <Icon
193
- name={IconNames.arrow}
194
- decorative={true}
195
- iconRotation={IconRotationTypes.rotate270}
196
- modifiers={["small"]}
197
- />
198
- </Button>
199
- <Button
200
- buttonType={ButtonTypes.Secondary}
201
- attributes={{
202
- "aria-label": "Close",
203
- }}
204
- >
205
- <Icon name={IconNames.close} decorative={true} modifiers={["small"]} />
206
- </Button>
207
- </div>
156
+ <DSProvider>
157
+ <ButtonGroup>
158
+ <Button
159
+ buttonType={ButtonTypes.Secondary}
160
+ attributes={{
161
+ "aria-label": "Previous",
162
+ }}
163
+ >
164
+ <Icon
165
+ name={IconNames.Arrow}
166
+ iconRotation={IconRotationTypes.Rotate90}
167
+ size={IconSizes.Small}
168
+ />
169
+ </Button>
170
+ <Button
171
+ buttonType={ButtonTypes.Secondary}
172
+ attributes={{
173
+ "aria-label": "Next",
174
+ }}
175
+ >
176
+ <Icon
177
+ name={IconNames.Arrow}
178
+ iconRotation={IconRotationTypes.Rotate270}
179
+ size={IconSizes.Small}
180
+ />
181
+ </Button>
182
+ <Button
183
+ buttonType={ButtonTypes.Secondary}
184
+ attributes={{
185
+ "aria-label": "Close",
186
+ }}
187
+ >
188
+ <Icon name={IconNames.Close} size={IconSizes.Small} />
189
+ </Button>
190
+ </ButtonGroup>
191
+ </DSProvider>
208
192
  </Canvas>
209
193
 
210
194
  ## Patterns
211
195
 
212
- Buttons are blue by default but should be red when it is intended as a call out.
213
- The "Back to Top" button must be of `ButtonTypes` `Secondary` and must include an up arrow icon.
196
+ Buttons are blue by default but should be red when it is intended to be used as
197
+ a call out. The "Back to Top" button must be of `ButtonTypes` `Secondary` and
198
+ must include an up arrow icon on the right side.
214
199
 
215
200
  <Canvas>
216
201
  <Story name="Patterns">
217
- <Button
218
- buttonType={ButtonTypes.Primary}
219
- attributes={{
220
- style: {
221
- backgroundColor: getCSSVariable("--section-books-and-more-primary"),
222
- },
223
- }}
224
- >
225
- Donate to this library
226
- </Button>
227
- <br />
228
- <Button buttonType={ButtonTypes.Secondary}>
229
- Back to Top
230
- <Icon
231
- name={IconNames.arrow}
232
- decorative={true}
233
- iconRotation={IconRotationTypes.rotate180}
234
- modifiers={["small", "icon-right"]}
235
- />
236
- </Button>
202
+ <ButtonGroup>
203
+ <Button buttonType={ButtonTypes.Callout}>Donate to this library</Button>
204
+ <Button buttonType={ButtonTypes.Secondary}>
205
+ Back to Top
206
+ <Icon
207
+ name={IconNames.Arrow}
208
+ iconRotation={IconRotationTypes.Rotate180}
209
+ size={IconSizes.Small}
210
+ className="right"
211
+ align={IconAlign.Right}
212
+ />
213
+ </Button>
214
+ </ButtonGroup>
237
215
  </Story>
238
216
  </Canvas>
239
217
 
240
218
  ## Other Examples
241
219
 
242
- Modifying the `buttonType` prop:
220
+ The different `ButtonTypes` modified by the `buttonType` prop:
243
221
 
244
222
  <Canvas>
245
- <Button buttonType={ButtonTypes.Primary}>Primary</Button>
246
- <Button buttonType={ButtonTypes.Secondary}>Secondary</Button>
247
- <Button buttonType={ButtonTypes.Pill}>Pill</Button>
248
- <Button buttonType={ButtonTypes.Link}>Link</Button>
223
+ <DSProvider>
224
+ <ButtonGroup>
225
+ <Button buttonType={ButtonTypes.Primary}>Primary</Button>
226
+ <Button buttonType={ButtonTypes.Secondary}>Secondary</Button>
227
+ <Button buttonType={ButtonTypes.Callout}>Callout</Button>
228
+ <Button buttonType={ButtonTypes.Pill}>Pill</Button>
229
+ <Button buttonType={ButtonTypes.Link}>Link</Button>
230
+ </ButtonGroup>
231
+ </DSProvider>
249
232
  </Canvas>
250
233
 
251
234
  Modifying the `disabled` prop:
252
235
 
253
236
  <Canvas>
254
- <Button disabled={false}>Enabled</Button>
255
- <Button disabled={true}>Disabled</Button>
237
+ <DSProvider>
238
+ <ButtonGroup>
239
+ <Button disabled={false}>Enabled</Button>
240
+ <Button disabled={true}>Disabled</Button>
241
+ </ButtonGroup>
242
+ </DSProvider>
256
243
  </Canvas>
@@ -6,7 +6,8 @@ import renderer from "react-test-renderer";
6
6
 
7
7
  import Button from "./Button";
8
8
  import Icon from "../Icons/Icon";
9
- import { IconNames } from "../Icons/IconTypes";
9
+ import { IconAlign, IconNames, IconSizes } from "../Icons/IconTypes";
10
+ import { ButtonTypes } from "./ButtonTypes";
10
11
 
11
12
  describe("Button Accessibility", () => {
12
13
  it("passes axe accessibility test", async () => {
@@ -79,39 +80,92 @@ describe("rendering content from its children prop", () => {
79
80
  it("should render element children", () => {
80
81
  const { container } = render(
81
82
  <Button id="button3" onClick={onClick}>
82
- <em>I'm a em element</em>
83
+ <em>I'm an em element</em>
83
84
  </Button>
84
85
  );
85
- expect(screen.getByText(/a em element/i)).toBeInTheDocument();
86
+ expect(screen.getByText(/an em element/i)).toBeInTheDocument();
86
87
  expect(container.querySelector("em")).toBeInTheDocument();
87
88
  });
88
89
  });
89
90
 
90
91
  describe("padding for icon only button", () => {
91
- it("button has proper padding for icon only button", () => {
92
+ it("button has proper child svg for the icon only button", () => {
92
93
  const onClick = jest.fn();
93
94
  const { container } = render(
94
95
  <Button id="button" onClick={onClick} type="button">
95
96
  <Icon
96
- name={IconNames.check}
97
- decorative={true}
98
- modifiers={["small", "icon-left"]}
97
+ align={IconAlign.Left}
98
+ name={IconNames.Check}
99
+ size={IconSizes.Small}
99
100
  />
100
101
  </Button>
101
102
  );
102
- expect(container.querySelector(".button--icon-only")).toBeInTheDocument();
103
+ expect(container.querySelector(".button svg")).toBeInTheDocument();
103
104
  });
104
105
  });
105
106
 
106
107
  describe("Button Snapshot", () => {
107
108
  it("Renders the UI snapshot correctly", () => {
108
- const tree = renderer
109
+ const primary = renderer
109
110
  .create(
110
111
  <Button id="button" onClick={jest.fn()}>
111
- Submit
112
+ Primary
112
113
  </Button>
113
114
  )
114
115
  .toJSON();
115
- expect(tree).toMatchSnapshot();
116
+ const secondary = renderer
117
+ .create(
118
+ <Button
119
+ id="button"
120
+ onClick={jest.fn()}
121
+ buttonType={ButtonTypes.Secondary}
122
+ >
123
+ Seconday
124
+ </Button>
125
+ )
126
+ .toJSON();
127
+ const callout = renderer
128
+ .create(
129
+ <Button
130
+ id="button"
131
+ onClick={jest.fn()}
132
+ buttonType={ButtonTypes.Callout}
133
+ >
134
+ Callout
135
+ </Button>
136
+ )
137
+ .toJSON();
138
+ const pill = renderer
139
+ .create(
140
+ <Button id="button" onClick={jest.fn()} buttonType={ButtonTypes.Pill}>
141
+ Pill
142
+ </Button>
143
+ )
144
+ .toJSON();
145
+ const link = renderer
146
+ .create(
147
+ <Button id="button" onClick={jest.fn()} buttonType={ButtonTypes.Link}>
148
+ Link
149
+ </Button>
150
+ )
151
+ .toJSON();
152
+ const searchBar = renderer
153
+ .create(
154
+ <Button
155
+ id="button"
156
+ onClick={jest.fn()}
157
+ buttonType={ButtonTypes.SearchBar}
158
+ >
159
+ SearchBar
160
+ </Button>
161
+ )
162
+ .toJSON();
163
+
164
+ expect(primary).toMatchSnapshot();
165
+ expect(secondary).toMatchSnapshot();
166
+ expect(callout).toMatchSnapshot();
167
+ expect(pill).toMatchSnapshot();
168
+ expect(link).toMatchSnapshot();
169
+ expect(searchBar).toMatchSnapshot();
116
170
  });
117
171
  });
@@ -1,13 +1,19 @@
1
1
  import * as React from "react";
2
+ import {
3
+ Button as ChakraButton,
4
+ ButtonGroup,
5
+ useStyleConfig,
6
+ } from "@chakra-ui/react";
7
+
2
8
  import bem from "../../utils/bem";
3
9
  import { ButtonTypes } from "./ButtonTypes";
4
10
  import Icon from "../Icons/Icon";
5
11
 
12
+ type ButtonElementType = "submit" | "button" | "reset";
13
+
6
14
  interface ButtonProps {
7
15
  /** Additional attributes passed to the button */
8
16
  attributes?: { [key: string]: any };
9
- /** BlockName for use with BEM. See how to work with blockNames and BEM here: http://getbem.com/introduction/ */
10
- blockName?: string;
11
17
  /** The kind of button assigned through the `ButtonTypes` enum */
12
18
  buttonType?: ButtonTypes;
13
19
  /** Additional className for use with BEM. See how to work with blockNames and BEM here: http://getbem.com/introduction/ */
@@ -16,84 +22,82 @@ interface ButtonProps {
16
22
  disabled?: boolean;
17
23
  /** ID that other components can cross reference for accessibility purposes */
18
24
  id?: string;
19
- /** Modifiers array for use with BEM. See how to work with modifiers and BEM here: http://getbem.com/introduction/ */
20
- modifiers?: string[];
21
25
  /** Trigger the Button's action through the `mouseDown` event handler instead of `onClick`. `false` by default. */
22
26
  mouseDown?: boolean;
23
27
  /** The action to perform on the `<button>`'s onClick function */
24
28
  onClick?: (event: React.MouseEvent | React.KeyboardEvent) => void;
25
29
  /** The html button attribute */
26
- type?: "submit" | "button" | "reset";
30
+ type?: ButtonElementType;
27
31
  }
28
32
 
29
- /** Renders a simple `button` element with custom classes and modifiers. */
30
- export default class Button extends React.Component<ButtonProps, any> {
31
- static defaultProps = {
32
- mouseDown: false,
33
- };
34
-
35
- constructor(props: ButtonProps) {
36
- super(props);
37
- }
38
-
39
- render(): JSX.Element {
40
- const {
41
- attributes,
42
- blockName,
43
- buttonType,
44
- children,
45
- className,
46
- disabled,
47
- id,
48
- modifiers = [],
49
- mouseDown,
50
- onClick,
51
- type = "submit",
52
- } = this.props;
53
-
54
- const buttonModifiers = modifiers ? modifiers : [];
55
- if (!buttonModifiers.find((modifier) => modifier === buttonType)) {
56
- buttonModifiers.push(buttonType);
57
- }
58
-
59
- const baseClass = "button";
33
+ // Used to map between ButtonTypes enum values and Chakra variant options.
34
+ const variantMap = {};
35
+ for (const type in ButtonTypes) {
36
+ variantMap[ButtonTypes[type]] = ButtonTypes[type];
37
+ }
60
38
 
61
- const btnCallback = mouseDown
62
- ? { onMouseDown: onClick }
63
- : { onClick: onClick };
39
+ /**
40
+ * Map the ButtonType to the Button Chakra theme variant object. If a wrong
41
+ * value is passed (typically in non-Typescript scenarios), then the default
42
+ * is the "primary" variant.
43
+ */
44
+ const getVariant = (buttonType) =>
45
+ variantMap[buttonType] || ButtonTypes.Primary;
64
46
 
65
- let childCount = 0;
66
- let hasIcon = false;
47
+ /** Renders a simple `button` element with custom classes and modifiers. */
48
+ function Button(props: React.PropsWithChildren<ButtonProps>) {
49
+ const {
50
+ attributes,
51
+ buttonType,
52
+ children,
53
+ className = "",
54
+ disabled,
55
+ id,
56
+ mouseDown = false,
57
+ onClick,
58
+ type = "button",
59
+ } = props;
60
+ const baseClass = "button";
61
+ const btnCallback = mouseDown ? { onMouseDown: onClick } : { onClick };
62
+ let childCount = 0;
63
+ let hasIcon = false;
64
+ let variant;
65
+ let styles;
67
66
 
68
- React.Children.map(children, (child: React.ReactElement) => {
69
- childCount++;
70
- if (child !== undefined && child !== null) {
71
- if (
72
- child.type === Icon ||
73
- (child.props && child.props.mdxType === "Icon")
74
- ) {
75
- hasIcon = true;
76
- }
67
+ React.Children.map(children, (child: React.ReactElement) => {
68
+ childCount++;
69
+ if (child !== undefined && child !== null) {
70
+ if (
71
+ child.type === Icon ||
72
+ (child.props && child.props.mdxType === "Icon")
73
+ ) {
74
+ hasIcon = true;
77
75
  }
78
- });
79
-
80
- if (childCount === 1 && hasIcon) {
81
- buttonModifiers.push("icon-only");
82
76
  }
77
+ });
83
78
 
84
- return (
85
- <button
86
- id={id}
87
- className={`${baseClass} ${bem(baseClass, buttonModifiers, blockName, [
88
- className,
89
- ])}`}
90
- type={type}
91
- disabled={disabled}
92
- {...attributes}
93
- {...btnCallback}
94
- >
95
- {children}
96
- </button>
97
- );
79
+ if (childCount === 1 && hasIcon) {
80
+ variant = "icon-only";
81
+ } else {
82
+ variant = getVariant(buttonType);
98
83
  }
84
+
85
+ styles = useStyleConfig("Button", { variant });
86
+
87
+ return (
88
+ <ChakraButton
89
+ id={id}
90
+ className={bem(baseClass, [], "", [className])}
91
+ type={type}
92
+ disabled={disabled}
93
+ __css={styles}
94
+ {...attributes}
95
+ {...btnCallback}
96
+ >
97
+ {children}
98
+ </ChakraButton>
99
+ );
99
100
  }
101
+
102
+ export { ButtonGroup };
103
+ export default Button;
@@ -1,6 +1,8 @@
1
1
  export enum ButtonTypes {
2
- Primary = "filled",
3
- Secondary = "outline",
2
+ Primary = "primary",
3
+ Secondary = "secondary",
4
+ Callout = "callout",
4
5
  Pill = "pill",
5
6
  Link = "link",
7
+ SearchBar = "searchBar",
6
8
  }