@nypl/design-system-react-components 0.25.0 → 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 (236) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/components/Accordion/Accordion.d.ts +14 -14
  3. package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +11 -14
  4. package/dist/components/Breadcrumbs/BreadcrumbsTypes.d.ts +6 -0
  5. package/dist/components/Button/ButtonTypes.d.ts +2 -1
  6. package/dist/components/Card/Card.d.ts +1 -1
  7. package/dist/components/Card/CardTypes.d.ts +2 -2
  8. package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +43 -0
  9. package/dist/components/CheckboxGroup/CheckboxGroupLayoutTypes.d.ts +4 -0
  10. package/dist/components/DatePicker/DatePicker.d.ts +3 -3
  11. package/dist/components/Form/Form.d.ts +13 -8
  12. package/dist/components/Form/FormTypes.d.ts +2 -8
  13. package/dist/components/Grid/GridTypes.d.ts +9 -0
  14. package/dist/components/Grid/SimpleGrid.d.ts +14 -0
  15. package/dist/components/Heading/Heading.d.ts +4 -4
  16. package/dist/components/Hero/Hero.d.ts +19 -14
  17. package/dist/components/Hero/HeroTypes.d.ts +10 -5
  18. package/dist/components/Icons/Icon.d.ts +13 -16
  19. package/dist/components/Icons/IconTypes.d.ts +78 -64
  20. package/dist/components/Label/Label.d.ts +5 -17
  21. package/dist/components/Link/Link.d.ts +8 -12
  22. package/dist/components/SearchBar/SearchBar.d.ts +45 -27
  23. package/dist/components/Select/Select.d.ts +32 -35
  24. package/dist/components/Select/SelectTypes.d.ts +4 -0
  25. package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +1 -1
  26. package/dist/components/SkeletonLoader/SkeletonLoaderTypes.d.ts +2 -2
  27. package/dist/components/StatusBadge/StatusBadge.d.ts +8 -6
  28. package/dist/components/StatusBadge/StatusBadgeTypes.d.ts +5 -0
  29. package/dist/components/Template/Template.d.ts +91 -0
  30. package/dist/components/Text/Text.d.ts +16 -0
  31. package/dist/components/Text/TextTypes.d.ts +6 -0
  32. package/dist/components/TextInput/TextInput.d.ts +32 -31
  33. package/dist/components/TextInput/TextInputTypes.d.ts +5 -0
  34. package/dist/design-system-react-components.cjs.development.js +2597 -1170
  35. package/dist/design-system-react-components.cjs.development.js.map +1 -1
  36. package/dist/design-system-react-components.cjs.production.min.js +1 -1
  37. package/dist/design-system-react-components.cjs.production.min.js.map +1 -1
  38. package/dist/design-system-react-components.esm.js +2580 -1173
  39. package/dist/design-system-react-components.esm.js.map +1 -1
  40. package/dist/index.d.ts +8 -1
  41. package/dist/styles.css +1 -1
  42. package/dist/theme/components/accordion.d.ts +25 -0
  43. package/dist/theme/components/breadcrumb.d.ts +90 -0
  44. package/dist/theme/components/button.d.ts +17 -7
  45. package/dist/theme/components/checkbox.d.ts +7 -7
  46. package/dist/theme/components/customCheckboxGroup.d.ts +18 -0
  47. package/dist/theme/components/customRadioGroup.d.ts +4 -3
  48. package/dist/theme/components/global.d.ts +55 -0
  49. package/dist/theme/components/globalMixins.d.ts +15 -0
  50. package/dist/theme/components/heading.d.ts +50 -20
  51. package/dist/theme/components/hero.d.ts +492 -0
  52. package/dist/theme/components/icon.d.ts +13 -0
  53. package/dist/theme/components/label.d.ts +16 -0
  54. package/dist/theme/components/link.d.ts +45 -0
  55. package/dist/theme/components/radio.d.ts +8 -7
  56. package/dist/theme/components/searchBar.d.ts +20 -0
  57. package/dist/theme/components/select.d.ts +58 -0
  58. package/dist/theme/components/statusBadge.d.ts +25 -0
  59. package/dist/theme/components/tabs.d.ts +9 -9
  60. package/dist/theme/components/template.d.ts +105 -0
  61. package/dist/theme/components/text.d.ts +20 -0
  62. package/dist/theme/components/textInput.d.ts +105 -0
  63. package/dist/theme/foundations/global.d.ts +3 -0
  64. package/dist/theme/foundations/shadows.d.ts +4 -0
  65. package/dist/utils/utils.d.ts +6 -0
  66. package/package.json +3 -2
  67. package/src/components/Accordion/Accordion.stories.mdx +227 -33
  68. package/src/components/Accordion/Accordion.test.tsx +135 -19
  69. package/src/components/Accordion/Accordion.tsx +81 -56
  70. package/src/components/Autosuggest/Autosuggest.stories.mdx +1 -1
  71. package/src/components/Autosuggest/Autosuggest.stories.tsx +1 -1
  72. package/src/components/Autosuggest/_Autosuggest.scss +2 -2
  73. package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +46 -52
  74. package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +31 -25
  75. package/src/components/Breadcrumbs/Breadcrumbs.tsx +71 -73
  76. package/src/components/Breadcrumbs/BreadcrumbsTypes.tsx +6 -0
  77. package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +100 -0
  78. package/src/components/Button/Button.stories.mdx +31 -27
  79. package/src/components/Button/Button.test.tsx +17 -5
  80. package/src/components/Button/ButtonTypes.tsx +1 -0
  81. package/src/components/Button/_Button.scss +3 -27
  82. package/src/components/Button/__snapshots__/Button.test.tsx.snap +11 -0
  83. package/src/components/Card/Card.stories.mdx +24 -20
  84. package/src/components/Card/Card.test.tsx +13 -19
  85. package/src/components/Card/Card.tsx +1 -1
  86. package/src/components/Card/CardTypes.tsx +2 -2
  87. package/src/components/Card/_Card.scss +1 -1
  88. package/src/components/CardEdition/CardEdition.stories.tsx +11 -6
  89. package/src/components/CardEdition/CardEdition.test.tsx +23 -31
  90. package/src/components/CardEdition/_CardEdition.scss +2 -2
  91. package/src/components/Chakra/Center.stories.mdx +31 -14
  92. package/src/components/Chakra/Grid.stories.mdx +79 -0
  93. package/src/components/Chakra/Stack.stories.mdx +4 -4
  94. package/src/components/Checkbox/Checkbox.tsx +9 -12
  95. package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +2 -5
  96. package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +249 -0
  97. package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +345 -0
  98. package/src/components/CheckboxGroup/CheckboxGroup.tsx +148 -0
  99. package/src/components/CheckboxGroup/CheckboxGroupLayoutTypes.tsx +4 -0
  100. package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +1360 -0
  101. package/src/components/DatePicker/DatePicker.test.tsx +4 -4
  102. package/src/components/DatePicker/DatePicker.tsx +13 -13
  103. package/src/components/DatePicker/_DatePicker.scss +1 -0
  104. package/src/components/Form/Form.stories.mdx +46 -21
  105. package/src/components/Form/Form.test.tsx +58 -45
  106. package/src/components/Form/Form.tsx +49 -21
  107. package/src/components/Form/FormTypes.tsx +3 -8
  108. package/src/components/Form/__snapshots__/Form.test.tsx.snap +24 -14
  109. package/src/components/Grid/GridTypes.tsx +9 -0
  110. package/src/components/Grid/SimpleGrid.stories.mdx +275 -0
  111. package/src/components/Grid/SimpleGrid.test.tsx +66 -0
  112. package/src/components/Grid/SimpleGrid.tsx +37 -0
  113. package/src/components/Grid/__snapshots__/SimpleGrid.test.tsx.snap +8 -0
  114. package/src/components/Heading/Heading.stories.mdx +1 -0
  115. package/src/components/Heading/Heading.tsx +12 -6
  116. package/src/components/HelperErrorText/_HelperErrorText.scss +1 -1
  117. package/src/components/Hero/Hero.stories.mdx +188 -121
  118. package/src/components/Hero/Hero.test.tsx +537 -107
  119. package/src/components/Hero/Hero.tsx +79 -92
  120. package/src/components/Hero/HeroTypes.tsx +17 -5
  121. package/src/components/Hero/__snapshots__/Hero.test.tsx.snap +307 -0
  122. package/src/components/HorizontalRule/_HorizontalRule.scss +1 -1
  123. package/src/components/Icons/Icon.stories.mdx +83 -74
  124. package/src/components/Icons/Icon.test.tsx +30 -22
  125. package/src/components/Icons/Icon.tsx +63 -61
  126. package/src/components/Icons/IconTypes.tsx +80 -64
  127. package/src/components/Input/_Input.scss +2 -2
  128. package/src/components/Label/Label.stories.mdx +28 -7
  129. package/src/components/Label/Label.test.tsx +43 -12
  130. package/src/components/Label/Label.tsx +21 -34
  131. package/src/components/Label/__snapshots__/Label.test.tsx.snap +41 -0
  132. package/src/components/Link/Link.stories.mdx +41 -41
  133. package/src/components/Link/Link.test.tsx +33 -44
  134. package/src/components/Link/Link.tsx +114 -100
  135. package/src/components/List/List.stories.mdx +0 -2
  136. package/src/components/List/List.stories.tsx +5 -5
  137. package/src/components/List/_List.scss +3 -3
  138. package/src/components/Modal/_Modal.scss +1 -1
  139. package/src/components/Notification/Notification.stories.mdx +12 -1
  140. package/src/components/Notification/Notification.test.tsx +3 -16
  141. package/src/components/Notification/Notification.tsx +9 -10
  142. package/src/components/Notification/_Notification.scss +4 -4
  143. package/src/components/Pagination/Pagination.test.tsx +16 -10
  144. package/src/components/RadioGroup/RadioGroup.stories.mdx +1 -1
  145. package/src/components/RadioGroup/RadioGroup.tsx +2 -10
  146. package/src/components/SearchBar/SearchBar.Test.tsx +151 -16
  147. package/src/components/SearchBar/SearchBar.stories.mdx +189 -219
  148. package/src/components/SearchBar/SearchBar.tsx +151 -46
  149. package/src/components/Select/Select.stories.mdx +188 -170
  150. package/src/components/Select/Select.test.tsx +125 -380
  151. package/src/components/Select/Select.tsx +118 -165
  152. package/src/components/Select/SelectTypes.tsx +4 -0
  153. package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +13 -25
  154. package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +7 -7
  155. package/src/components/SkeletonLoader/SkeletonLoader.tsx +4 -2
  156. package/src/components/SkeletonLoader/SkeletonLoaderTypes.tsx +2 -2
  157. package/src/components/SkeletonLoader/_SkeletonLoader.scss +3 -3
  158. package/src/components/StatusBadge/StatusBadge.stories.mdx +91 -0
  159. package/src/components/StatusBadge/StatusBadge.test.tsx +35 -7
  160. package/src/components/StatusBadge/StatusBadge.tsx +24 -25
  161. package/src/components/StatusBadge/StatusBadgeTypes.tsx +5 -0
  162. package/src/components/StatusBadge/__snapshots__/StatusBadge.test.tsx.snap +28 -0
  163. package/src/components/StyleGuide/Bidirectionality.stories.mdx +16 -16
  164. package/src/components/StyleGuide/Buttons.stories.mdx +15 -15
  165. package/src/components/StyleGuide/Colors.stories.mdx +336 -0
  166. package/src/components/StyleGuide/Iconography.stories.mdx +88 -90
  167. package/src/components/StyleGuide/UIDocCard.tsx +1 -1
  168. package/src/components/Tabs/Tabs.tsx +7 -9
  169. package/src/components/Template/Template.stories.mdx +574 -0
  170. package/src/components/Template/Template.test.tsx +124 -0
  171. package/src/components/Template/Template.tsx +226 -0
  172. package/src/components/Text/Text.stories.mdx +70 -0
  173. package/src/components/Text/Text.test.tsx +63 -0
  174. package/src/components/Text/Text.tsx +55 -0
  175. package/src/components/Text/TextTypes.tsx +6 -0
  176. package/src/components/Text/__snapshots__/Text.test.tsx.snap +33 -0
  177. package/src/components/TextInput/TextInput.stories.mdx +89 -90
  178. package/src/components/TextInput/TextInput.test.tsx +65 -86
  179. package/src/components/TextInput/TextInput.tsx +101 -95
  180. package/src/components/TextInput/TextInputTypes.tsx +6 -0
  181. package/src/components/VideoPlayer/_VideoPlayer.scss +1 -1
  182. package/src/docs/Chakra.stories.mdx +4 -4
  183. package/src/docs/Intro.stories.mdx +15 -13
  184. package/src/index.ts +20 -0
  185. package/src/styles/01-colors/_colors-brand.scss +6 -0
  186. package/src/styles/01-colors/_colors-utility.scss +14 -12
  187. package/src/styles/base/_04-base.scss +2 -1
  188. package/src/styles/base/_place-holder.scss +1 -1
  189. package/src/styles.scss +10 -12
  190. package/src/theme/components/accordion.ts +30 -0
  191. package/src/theme/components/breadcrumb.ts +77 -0
  192. package/src/theme/components/button.ts +77 -63
  193. package/src/theme/components/checkbox.ts +15 -27
  194. package/src/theme/components/customCheckboxGroup.ts +12 -0
  195. package/src/theme/components/customRadioGroup.ts +4 -10
  196. package/src/theme/components/global.ts +71 -0
  197. package/src/theme/components/globalMixins.ts +16 -0
  198. package/src/theme/components/heading.ts +15 -8
  199. package/src/theme/components/hero.ts +239 -0
  200. package/src/theme/components/icon.ts +79 -0
  201. package/src/theme/components/label.ts +17 -0
  202. package/src/theme/components/link.ts +47 -0
  203. package/src/theme/components/radio.ts +20 -31
  204. package/src/theme/components/searchBar.ts +21 -0
  205. package/src/theme/components/select.ts +50 -0
  206. package/src/theme/components/statusBadge.ts +27 -0
  207. package/src/theme/components/tabs.ts +72 -69
  208. package/src/theme/components/template.ts +114 -0
  209. package/src/theme/components/text.ts +31 -0
  210. package/src/theme/components/textInput.ts +61 -0
  211. package/src/theme/foundations/colors.ts +29 -13
  212. package/src/theme/foundations/global.ts +3 -0
  213. package/src/theme/foundations/shadows.ts +5 -0
  214. package/src/theme/index.ts +37 -7
  215. package/src/utils/componentCategories.ts +8 -2
  216. package/src/utils/utils.ts +13 -0
  217. package/dist/components/Accordion/Accordion.stories.d.ts +0 -6
  218. package/dist/components/StatusBadge/StatusBadge.stories.d.ts +0 -8
  219. package/dist/components/StyleGuide/Colors.stories.d.ts +0 -25
  220. package/dist/components/Template/Template.stories.d.ts +0 -30
  221. package/src/components/Accordion/Accordion.stories.tsx +0 -66
  222. package/src/components/Accordion/_Accordion.scss +0 -81
  223. package/src/components/Breadcrumbs/_Breadcrumbs.scss +0 -97
  224. package/src/components/Form/_Form.scss +0 -67
  225. package/src/components/Hero/_Hero.scss +0 -256
  226. package/src/components/Icons/_Icons.scss +0 -116
  227. package/src/components/Label/_Label.scss +0 -22
  228. package/src/components/Link/_Link.scss +0 -73
  229. package/src/components/SearchBar/_SearchBar.scss +0 -16
  230. package/src/components/Select/_Select.scss +0 -82
  231. package/src/components/StatusBadge/StatusBadge.stories.tsx +0 -34
  232. package/src/components/StatusBadge/_StatusBadge.scss +0 -23
  233. package/src/components/StyleGuide/Colors.stories.tsx +0 -289
  234. package/src/components/Template/Template.stories.tsx +0 -86
  235. package/src/components/Template/_Template.scss +0 -63
  236. package/src/components/TextInput/_TextInput.scss +0 -59
@@ -3,16 +3,16 @@ 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
10
  import Breadcrumbs from "./Breadcrumbs";
11
+ import { ColorVariants } from "./BreadcrumbsTypes";
12
+ import DSProvider from "../../theme/provider";
12
13
  import Heading from "../Heading/Heading";
13
14
  import { HeadingLevels } from "../Heading/HeadingTypes";
14
15
  import Link from "../Link/Link";
15
- import sections from "../../utils/siteSections";
16
16
  import { getCategory } from "../../utils/componentCategories";
17
17
 
18
18
  <Meta
@@ -23,14 +23,13 @@ import { getCategory } from "../../utils/componentCategories";
23
23
  design: {
24
24
  type: "figma",
25
25
  url:
26
- "https://www.figma.com/file/qShodlfNCJHb8n03IFyApM/Master?node-id=11895%3A547",
26
+ "https://www.figma.com/file/qShodlfNCJHb8n03IFyApM/Main?node-id=10766%3A1031",
27
27
  },
28
28
  jest: ["Breadcrumbs.test.tsx"],
29
29
  }}
30
30
  argTypes={{
31
- blockName: { table: { disable: true } },
31
+ id: { table: { disable: true } },
32
32
  className: { table: { disable: true } },
33
- modifiers: { table: { disable: true } },
34
33
  }}
35
34
  />
36
35
 
@@ -39,72 +38,63 @@ import { getCategory } from "../../utils/componentCategories";
39
38
  | Component Version | DS Version |
40
39
  | ----------------- | ---------- |
41
40
  | Added | `0.0.3` |
42
- | Latest | `0.23.0` |
41
+ | Latest | `0.25.1` |
43
42
 
44
43
  <Description of={Breadcrumbs} />
45
44
 
46
45
  The `Breadcrumbs` component is a navigation element that provides a breadcrumb path that reflects the site structure and allows a user to navigate to any page available in the breadcrumb hierarchy.
47
46
 
48
- <Preview withToolbar>
47
+ <Canvas withToolbar>
49
48
  <Story
50
- name="Basic"
49
+ name="Breadcrumbs Props"
51
50
  args={{
52
- breadcrumbs: [
51
+ breadcrumbsData: [
53
52
  { url: "#", text: "Parent" },
54
53
  { url: "#", text: "Child" },
55
54
  { url: "#", text: "Grandchild" },
56
55
  ],
56
+ id: "init-breadcrumbs",
57
57
  }}
58
58
  >
59
59
  {(args) => <Breadcrumbs {...args} />}
60
60
  </Story>
61
- </Preview>
61
+ </Canvas>
62
62
 
63
- <ArgsTable story="Basic" />
63
+ <ArgsTable story="Breadcrumbs Props" />
64
64
 
65
65
  ### Long Titles
66
66
 
67
67
  <Canvas>
68
- <Breadcrumbs
69
- breadcrumbs={[
70
- { url: "#", text: "Parent with a Long Name" },
71
- { url: "#", text: "Child with an Even Longer Name" },
72
- {
73
- url: "#",
74
- text: "Grandchild with an Exceptionally Long Name",
75
- },
76
- {
77
- url: "#",
78
- text:
79
- "Great-Grandchild with the Longest Name That Will Wrap onto the Second Line of the Breadcrumb Component Under the Right Circumstances",
80
- },
81
- ]}
82
- />
68
+ <DSProvider>
69
+ <Breadcrumbs
70
+ breadcrumbsData={[
71
+ { url: "#", text: "Parent with a Long Name" },
72
+ { url: "#", text: "Child with an Even Longer Name" },
73
+ {
74
+ url: "#",
75
+ text: "Grandchild with an Exceptionally Long Name",
76
+ },
77
+ {
78
+ url: "#",
79
+ text:
80
+ "Great-Grandchild with the Longest Name That Will Wrap onto the Second Line of the Breadcrumb Component Under the Right Circumstances",
81
+ },
82
+ ]}
83
+ />
84
+ </DSProvider>
83
85
  </Canvas>
84
86
 
85
87
  ## Color Variations
86
88
 
87
- The `Breadcrumbs` component background color will match the secondary section color of the website section it is placed into. See more about brand colors <Link href="?path=/story/colors--colors-brand">here</Link>.
89
+ The `Breadcrumbs` component background color can be set using the `colorVariant` prop and the `ColorVariants` enum. If the `colorVariant` prop is omitted, the default background color is `black`.
88
90
 
89
- <Preview>
90
- <Story
91
- name="Color Variations"
92
- args={{
93
- breadcrumbs: [
94
- { url: "#", text: "Parent" },
95
- { url: "#", text: "Child" },
96
- {
97
- url: "#",
98
- text: "Grandchild",
99
- },
100
- ],
101
- }}
102
- >
91
+ <Canvas>
92
+ <Story name="Color Variations" args={{}}>
103
93
  {(args) => (
104
94
  <div className="nypl--books-and-more">
105
95
  <Heading level={HeadingLevels.Three}>Books and More</Heading>
106
96
  <Breadcrumbs
107
- breadcrumbs={[
97
+ breadcrumbsData={[
108
98
  { url: "#", text: "Parent" },
109
99
  { url: "#", text: "Child" },
110
100
  {
@@ -112,17 +102,18 @@ The `Breadcrumbs` component background color will match the secondary section co
112
102
  text: "Grandchild",
113
103
  },
114
104
  ]}
105
+ colorVariant={ColorVariants.BooksAndMore}
115
106
  />
116
107
  </div>
117
108
  )}
118
109
  </Story>
119
- </Preview>
110
+ </Canvas>
120
111
 
121
112
  <Canvas>
122
- <div className="nypl--locations">
113
+ <DSProvider>
123
114
  <Heading level={HeadingLevels.Three}>Locations</Heading>
124
115
  <Breadcrumbs
125
- breadcrumbs={[
116
+ breadcrumbsData={[
126
117
  { url: "#", text: "Parent" },
127
118
  { url: "#", text: "Child" },
128
119
  {
@@ -130,15 +121,16 @@ The `Breadcrumbs` component background color will match the secondary section co
130
121
  text: "Grandchild",
131
122
  },
132
123
  ]}
124
+ colorVariant={ColorVariants.Locations}
133
125
  />
134
- </div>
126
+ </DSProvider>
135
127
  </Canvas>
136
128
 
137
129
  <Canvas>
138
- <div className="nypl--research">
130
+ <DSProvider>
139
131
  <Heading level={HeadingLevels.Three}>Research</Heading>
140
132
  <Breadcrumbs
141
- breadcrumbs={[
133
+ breadcrumbsData={[
142
134
  { url: "#", text: "Parent" },
143
135
  { url: "#", text: "Child" },
144
136
  {
@@ -146,15 +138,16 @@ The `Breadcrumbs` component background color will match the secondary section co
146
138
  text: "Grandchild",
147
139
  },
148
140
  ]}
141
+ colorVariant={ColorVariants.Research}
149
142
  />
150
- </div>
143
+ </DSProvider>
151
144
  </Canvas>
152
145
 
153
146
  <Canvas>
154
- <div className="nypl--whats-on">
147
+ <DSProvider>
155
148
  <Heading level={HeadingLevels.Three}>What's On</Heading>
156
149
  <Breadcrumbs
157
- breadcrumbs={[
150
+ breadcrumbsData={[
158
151
  { url: "#", text: "Parent" },
159
152
  { url: "#", text: "Child" },
160
153
  {
@@ -162,6 +155,7 @@ The `Breadcrumbs` component background color will match the secondary section co
162
155
  text: "Grandchild",
163
156
  },
164
157
  ]}
158
+ colorVariant={ColorVariants.WhatsOn}
165
159
  />
166
- </div>
160
+ </DSProvider>
167
161
  </Canvas>
@@ -1,62 +1,68 @@
1
1
  import * as React from "react";
2
2
  import { render, screen } from "@testing-library/react";
3
+ import renderer from "react-test-renderer";
3
4
  import { axe } from "jest-axe";
4
5
 
5
6
  import Breadcrumbs from "./Breadcrumbs";
6
7
 
7
8
  describe("Breadcrumbs Accessibility", () => {
8
- const breadcrumbString = [
9
+ const breadcrumbsData = [
9
10
  { url: "#string1", text: "string1" },
10
11
  { url: "#string2", text: "string2" },
11
12
  ];
12
13
  it("passes axe accessibility test", async () => {
13
14
  const { container } = render(
14
- <Breadcrumbs breadcrumbs={breadcrumbString} />
15
+ <Breadcrumbs breadcrumbsData={breadcrumbsData} />
15
16
  );
16
17
  expect(await axe(container)).toHaveNoViolations();
17
18
  });
18
19
  });
19
20
 
20
- describe("Breadcrumbs", () => {
21
- const breadcrumbString = [
21
+ describe("Breadcrumbs Snapshot", () => {
22
+ it("Renders the UI snapshot correctly", () => {
23
+ const breadcrumbsData = [
24
+ { url: "#string1", text: "string1" },
25
+ { url: "#string2", text: "string2" },
26
+ { url: "#string3", text: "string3" },
27
+ ];
28
+
29
+ const breadcrumbsSnapshot = renderer
30
+ .create(
31
+ <Breadcrumbs id="breadcrumbs-test" breadcrumbsData={breadcrumbsData} />
32
+ )
33
+ .toJSON();
34
+
35
+ expect(breadcrumbsSnapshot).toMatchSnapshot();
36
+ });
37
+ });
38
+
39
+ describe("Breadcrumbs Testing", () => {
40
+ const breadcrumbsData = [
22
41
  { url: "#string1", text: "string1" },
23
42
  { url: "#string2", text: "string2" },
24
- ];
25
- const breadcrumbComponent = [
26
- <a key="link1" href="#component1">
27
- <span>component1</span>
28
- </a>,
29
- <a key="link2" href="#component2">
30
- component2
31
- </a>,
43
+ { url: "#string3", text: "string3" },
32
44
  ];
33
45
 
34
46
  it("Renders a tag with custom text", () => {
35
- render(<Breadcrumbs breadcrumbs={breadcrumbString} />);
47
+ render(<Breadcrumbs breadcrumbsData={breadcrumbsData} />);
36
48
 
49
+ // The last breadcrumb (the active page) is not a link.
37
50
  expect(screen.getAllByRole("link")).toHaveLength(2);
38
51
  expect(screen.getAllByRole("link")[0]).toHaveTextContent("string1");
39
52
  expect(screen.getAllByRole("link")[1]).toHaveTextContent("string2");
40
- });
41
-
42
- it("Renders breadcrumb when passed components", () => {
43
- render(<Breadcrumbs breadcrumbs={breadcrumbComponent} />);
44
-
45
- expect(screen.getAllByRole("link")).toHaveLength(2);
46
- expect(screen.getAllByRole("link")[0]).toHaveTextContent("component1");
47
- expect(screen.getAllByRole("link")[1]).toHaveTextContent("component2");
53
+ expect(screen.getByText(/string3/)).toBeInTheDocument();
48
54
  });
49
55
 
50
56
  it("Renders icon", () => {
51
57
  const { container } = render(
52
- <Breadcrumbs breadcrumbs={breadcrumbComponent} />
58
+ <Breadcrumbs breadcrumbsData={breadcrumbsData} />
53
59
  );
54
- expect(container.querySelector(".breadcrumbs__icon")).toBeInTheDocument();
60
+ expect(container.querySelector(".breadcrumbs-icon")).toBeInTheDocument();
55
61
  });
56
62
 
57
63
  it("Throws error when nothing is passed into Breadcrumb", () => {
58
- expect(() => render(<Breadcrumbs breadcrumbs={[]} />)).toThrowError(
59
- "Breadcrumbs must contain a set of links. Breadcrumbs currently empty"
64
+ expect(() => render(<Breadcrumbs breadcrumbsData={[]} />)).toThrowError(
65
+ "You must use the `breadcrumbsData` prop to pass a data object to the Breadcrumbs component. That prop is current empty."
60
66
  );
61
67
  });
62
68
  });
@@ -1,92 +1,90 @@
1
1
  import * as React from "react";
2
- import bem from "../../utils/bem";
3
- import Icon from "../Icons/Icon";
4
- import { IconNames } from "../Icons/IconTypes";
2
+ import {
3
+ Breadcrumb as ChakraBreadcrumb,
4
+ BreadcrumbItem,
5
+ BreadcrumbLink,
6
+ useStyleConfig,
7
+ } from "@chakra-ui/react";
5
8
 
6
- type breadcrumb = { url: string; text: string };
9
+ import generateUUID from "../../helpers/generateUUID";
10
+ import { ColorVariants } from "./BreadcrumbsTypes";
11
+ import Icon from "../Icons/Icon";
12
+ import {
13
+ IconNames,
14
+ IconRotationTypes,
15
+ IconSizes,
16
+ IconTypes,
17
+ } from "../Icons/IconTypes";
18
+ import { getVariant } from "../../utils/utils";
7
19
 
8
- function isTextBreadcrumb(obj: breadcrumb | JSX.Element): obj is breadcrumb {
9
- return typeof (obj as breadcrumb).url === "string";
20
+ export interface BreadcrumbsDataProps {
21
+ url: string;
22
+ text: string | React.ReactNode;
10
23
  }
11
24
 
12
25
  export interface BreadcrumbProps {
13
- /** BlockName for use with BEM. See how to work with blockNames and BEM here: http://getbem.com/introduction/ */
14
- blockName?: string;
15
26
  /** Breadcrumb links as an array */
16
- breadcrumbs: breadcrumb[] | JSX.Element[];
27
+ breadcrumbsData: BreadcrumbsDataProps[];
17
28
  /** className you can add in addition to 'input' */
18
29
  className?: string;
19
- /** Modifiers array for use with BEM. See how to work with modifiers and BEM here: http://getbem.com/introduction/ */
20
- modifiers?: string[];
30
+ /** ID that other components can cross reference for accessibility purposes */
31
+ id?: string;
32
+ /** Used to control how the `Hero` component will be rendered. */
33
+ colorVariant?: ColorVariants;
21
34
  }
22
35
 
23
- export default class Breadcrumbs extends React.Component<BreadcrumbProps, any> {
24
- static defaultProps = {};
25
-
26
- constructor(props: BreadcrumbProps) {
27
- super(props);
36
+ const getElementsFromData = (data, breadcrumbsID) => {
37
+ if (!data?.length) {
38
+ return {};
28
39
  }
29
40
 
30
- render(): JSX.Element {
31
- const { breadcrumbs, className, blockName, modifiers } = this.props;
32
-
33
- const baseClass = "breadcrumbs";
41
+ const breadcrumbItems = data.map((breadcrumbData, index) => (
42
+ <BreadcrumbItem
43
+ key={index}
44
+ isCurrentPage={index === data.length - 1 ? true : false}
45
+ >
46
+ <BreadcrumbLink href={breadcrumbData.url}>
47
+ {index === data.length - 2 && (
48
+ <Icon
49
+ name={IconNames.Arrow}
50
+ size={IconSizes.Small}
51
+ iconRotation={IconRotationTypes.Rotate90}
52
+ id={`${breadcrumbsID}__backarrow`}
53
+ className="breadcrumbs-icon"
54
+ type={IconTypes.Breadcrumbs}
55
+ />
56
+ )}
57
+ <span className="breadcrumb-label">{breadcrumbData.text}</span>
58
+ </BreadcrumbLink>
59
+ </BreadcrumbItem>
60
+ ));
34
61
 
35
- const breadcrumbItems = [];
62
+ return breadcrumbItems;
63
+ };
36
64
 
37
- if (!breadcrumbs || breadcrumbs.length === 0) {
38
- throw new Error(
39
- "Breadcrumbs must contain a set of links. Breadcrumbs currently empty"
40
- );
41
- }
42
- breadcrumbs.forEach((item: breadcrumb | JSX.Element, index: number) => {
43
- const last = index === breadcrumbs.length - 1;
44
- let linkComponent: string | JSX.Element;
65
+ function Breadcrumbs(props: React.PropsWithChildren<BreadcrumbProps>) {
66
+ const {
67
+ breadcrumbsData,
68
+ className,
69
+ colorVariant,
70
+ id = generateUUID(),
71
+ } = props;
72
+ const variant = getVariant(colorVariant, ColorVariants);
45
73
 
46
- if (isTextBreadcrumb(item)) {
47
- linkComponent = item.url ? (
48
- <a href={item.url} className={bem("link", [], baseClass)}>
49
- {item.text}
50
- </a>
51
- ) : (
52
- item.text
53
- );
54
- } else {
55
- const props = {
56
- className: bem("link", [], baseClass),
57
- };
58
- linkComponent = React.createElement(
59
- item.type,
60
- { ...props, ...item.props },
61
- item.props.children
62
- );
63
- }
64
- breadcrumbItems.push(
65
- <li
66
- key={`${baseClass}-${index}`}
67
- className={bem("item", [], baseClass)}
68
- >
69
- {last && (
70
- <Icon
71
- name={IconNames.arrow}
72
- blockName={baseClass}
73
- modifiers={["small"]}
74
- decorative={true}
75
- />
76
- )}
77
- {linkComponent}
78
- </li>
79
- );
80
- });
81
-
82
- return (
83
- <nav
84
- className={bem(baseClass, modifiers, blockName, [className])}
85
- role="navigation"
86
- aria-label="Breadcrumbs"
87
- >
88
- <ul className={bem("list", [], baseClass)}>{breadcrumbItems}</ul>
89
- </nav>
74
+ if (!breadcrumbsData || breadcrumbsData.length === 0) {
75
+ throw new Error(
76
+ "You must use the `breadcrumbsData` prop to pass a data object to the Breadcrumbs component. That prop is current empty."
90
77
  );
91
78
  }
79
+
80
+ const styles = useStyleConfig("Breadcrumb", { variant });
81
+ const breadcrumbItems = getElementsFromData(breadcrumbsData, id);
82
+
83
+ return (
84
+ <ChakraBreadcrumb className={className} __css={styles} id={id}>
85
+ {breadcrumbItems}
86
+ </ChakraBreadcrumb>
87
+ );
92
88
  }
89
+
90
+ export default Breadcrumbs;
@@ -0,0 +1,6 @@
1
+ export enum ColorVariants {
2
+ BooksAndMore = "booksAndMore",
3
+ Locations = "locations",
4
+ Research = "research",
5
+ WhatsOn = "whatsOn",
6
+ }
@@ -0,0 +1,100 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Breadcrumbs Snapshot Renders the UI snapshot correctly 1`] = `
4
+ <nav
5
+ aria-label="breadcrumb"
6
+ className="chakra-breadcrumb css-0"
7
+ id="breadcrumbs-test"
8
+ >
9
+ <ol
10
+ className="chakra-breadcrumb__list css-0"
11
+ >
12
+ <li
13
+ className="chakra-breadcrumb__list-item css-18biwo"
14
+ >
15
+ <a
16
+ className="chakra-breadcrumb__link css-0"
17
+ href="#string1"
18
+ >
19
+ <span
20
+ className="breadcrumb-label"
21
+ >
22
+ string1
23
+ </span>
24
+ </a>
25
+ <span
26
+ className="css-t4q1nq"
27
+ role="presentation"
28
+ >
29
+ /
30
+ </span>
31
+ </li>
32
+ <li
33
+ className="chakra-breadcrumb__list-item css-18biwo"
34
+ >
35
+ <a
36
+ className="chakra-breadcrumb__link css-0"
37
+ href="#string2"
38
+ >
39
+ <svg
40
+ aria-hidden={true}
41
+ className="chakra-icon breadcrumbs-icon css-onkibi"
42
+ focusable={false}
43
+ id="breadcrumbs-test__backarrow"
44
+ role="img"
45
+ viewBox="0 0 24 24"
46
+ >
47
+ <g
48
+ stroke="currentColor"
49
+ strokeWidth="1.5"
50
+ >
51
+ <path
52
+ d="M9,9a3,3,0,1,1,4,2.829,1.5,1.5,0,0,0-1,1.415V14.25"
53
+ fill="none"
54
+ strokeLinecap="round"
55
+ />
56
+ <path
57
+ d="M12,17.25a.375.375,0,1,0,.375.375A.375.375,0,0,0,12,17.25h0"
58
+ fill="currentColor"
59
+ strokeLinecap="round"
60
+ />
61
+ <circle
62
+ cx="12"
63
+ cy="12"
64
+ fill="none"
65
+ r="11.25"
66
+ strokeMiterlimit="10"
67
+ />
68
+ </g>
69
+ </svg>
70
+ <span
71
+ className="breadcrumb-label"
72
+ >
73
+ string2
74
+ </span>
75
+ </a>
76
+ <span
77
+ className="css-t4q1nq"
78
+ role="presentation"
79
+ >
80
+ /
81
+ </span>
82
+ </li>
83
+ <li
84
+ className="chakra-breadcrumb__list-item css-18biwo"
85
+ >
86
+ <span
87
+ aria-current="page"
88
+ className="chakra-breadcrumb__link css-0"
89
+ href="#string3"
90
+ >
91
+ <span
92
+ className="breadcrumb-label"
93
+ >
94
+ string3
95
+ </span>
96
+ </span>
97
+ </li>
98
+ </ol>
99
+ </nav>
100
+ `;