@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,13 +3,13 @@ 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 Icon from "./Icon";
12
11
  import {
12
+ IconAlign,
13
13
  IconNames,
14
14
  LogoNames,
15
15
  IconColors,
@@ -33,6 +33,11 @@ import { getCategory } from "../../utils/componentCategories";
33
33
  },
34
34
  jest: ["Icon.test.tsx"],
35
35
  }}
36
+ argTypes={{
37
+ children: { table: { disable: true } },
38
+ className: { table: { disable: true } },
39
+ id: { table: { disable: true } },
40
+ }}
36
41
  />
37
42
 
38
43
  # Icon
@@ -40,89 +45,97 @@ import { getCategory } from "../../utils/componentCategories";
40
45
  | Component Version | DS Version |
41
46
  | ----------------- | ---------- |
42
47
  | Added | `0.0.4` |
43
- | Latest | `0.24.1` |
48
+ | Latest | `0.25.1` |
44
49
 
45
50
  <Description of={Icon} />
46
51
 
47
- <Preview withToolbar style={{ backgroundColor: "#fafafa" }}>
52
+ <Canvas withToolbar>
48
53
  <Story
49
54
  name="Icon Props Control"
50
55
  args={{
51
- name: "check",
52
- color: IconColors.ui_black,
53
- size: IconSizes.xlarge,
54
- iconRotation: IconRotationTypes.rotate0,
56
+ align: "None",
57
+ color: "UiBlack",
55
58
  decorative: true,
56
- titleText: "An example icon",
59
+ iconRotation: "Rotate0",
60
+ name: "Check",
61
+ size: "ExtraLarge",
57
62
  }}
58
63
  argTypes={{
59
- color: {
64
+ align: {
60
65
  control: {
61
66
  type: "select",
62
- options: IconColors,
63
67
  },
68
+ options: Object.keys(IconAlign),
64
69
  },
65
- size: {
70
+ color: {
66
71
  control: {
67
72
  type: "select",
68
- options: IconSizes,
69
73
  },
74
+ options: Object.keys(IconColors),
70
75
  },
71
76
  iconRotation: {
72
77
  control: {
73
78
  type: "select",
74
- options: IconRotationTypes,
75
79
  },
80
+ options: Object.keys(IconRotationTypes),
76
81
  },
77
- blockName: {
78
- table: {
79
- disable: true,
82
+ name: {
83
+ control: {
84
+ type: "select",
80
85
  },
86
+ options: Object.keys(IconNames),
81
87
  },
82
- modifiers: {
83
- table: {
84
- disable: true,
88
+ size: {
89
+ control: {
90
+ type: "select",
85
91
  },
92
+ options: Object.keys(IconSizes),
86
93
  },
87
94
  }}
88
95
  >
89
- {(args) => <Icon {...args} />}
96
+ {(args) => (
97
+ <Icon
98
+ align={IconAlign[args.align]}
99
+ color={IconColors[args.color]}
100
+ iconRotation={IconRotationTypes[args.iconRotation]}
101
+ name={IconNames[args.name]}
102
+ size={IconSizes[args.size]}
103
+ />
104
+ )}
90
105
  </Story>
91
- </Preview>
106
+ </Canvas>
92
107
 
93
108
  <ArgsTable story="Icon Props Control" />
94
109
 
95
- export const iconRow = (icon, opts = {}) => {
110
+ export const iconRow = (icon, iconType = IconNames, opts = {}) => {
96
111
  // We'll use this setup function to render all the icons in a list item.
97
112
  // Some icons display better with a dark background.
98
113
  const styles = { padding: "1rem" };
99
114
  const {
100
- size = IconSizes.large,
101
- iconRotation = IconRotationTypes.rotate0,
102
- color = IconColors.ui_black,
115
+ size = IconSizes.Large,
116
+ iconRotation = IconRotationTypes.Rotate0,
117
+ color = IconColors.UiBlack,
103
118
  displayValue = icon,
104
119
  } = opts;
105
120
  let key = icon;
106
- if (icon.indexOf("_negative") !== -1) {
121
+ if (icon.indexOf("Negative") !== -1 || color.indexOf("white") !== -1) {
107
122
  styles.backgroundColor = "#000";
108
- styles.display = "inline-block";
109
123
  }
110
124
  // The following is just to fix duplicate React key issues.
111
- if (iconRotation !== IconRotationTypes.rotate0) {
125
+ if (iconRotation !== IconRotationTypes.Rotate0) {
112
126
  key += `-${iconRotation}`;
113
127
  }
114
- if (color !== IconColors.ui_black) {
128
+ if (color !== IconColors.UiBlack) {
115
129
  key += `-${color}`;
116
130
  }
117
- if (size !== IconSizes.large) {
131
+ if (size !== IconSizes.Large) {
118
132
  key += `-${size}`;
119
133
  }
120
134
  return (
121
135
  <li key={key} style={{ marginBottom: "var(--space-s)" }}>
122
136
  <span style={styles}>
123
137
  <Icon
124
- name={icon}
125
- decorative={true}
138
+ name={iconType[icon]}
126
139
  size={size}
127
140
  iconRotation={iconRotation}
128
141
  color={color}
@@ -138,33 +151,33 @@ export const rotations = [];
138
151
  export const colors = [];
139
152
  export const sizes = [];
140
153
  for (const icon in IconNames) {
141
- icons.push(iconRow(icon));
154
+ icons.push(iconRow(icon, IconNames));
142
155
  }
143
156
  for (const logo in LogoNames) {
144
- logos.push(iconRow(logo, { iconSize: IconSizes.xlarge }));
157
+ logos.push(iconRow(logo, LogoNames, { iconSize: IconSizes.ExtraLarge }));
145
158
  }
146
159
  for (const iconRotation in IconRotationTypes) {
147
160
  rotations.push(
148
- iconRow(IconNames.arrow, {
149
- size: IconSizes.large,
161
+ iconRow("Arrow", IconNames, {
162
+ size: IconSizes.Large,
150
163
  iconRotation: IconRotationTypes[iconRotation],
151
- displayValue: IconRotationTypes[iconRotation],
164
+ displayValue: iconRotation,
152
165
  })
153
166
  );
154
167
  }
155
168
  for (const iconColor in IconColors) {
156
169
  colors.push(
157
- iconRow(IconNames.download, {
170
+ iconRow("Download", IconNames, {
158
171
  color: IconColors[iconColor],
159
- displayValue: IconColors[iconColor],
172
+ displayValue: iconColor,
160
173
  })
161
174
  );
162
175
  }
163
176
  for (const iconSize in IconSizes) {
164
177
  sizes.push(
165
- iconRow(IconNames.arrow, {
178
+ iconRow("Arrow", IconNames, {
166
179
  size: IconSizes[iconSize],
167
- displayValue: IconSizes[iconSize],
180
+ displayValue: iconSize,
168
181
  })
169
182
  );
170
183
  }
@@ -179,59 +192,51 @@ Passing an `iconRotation` prop with a value from `IconRotationTypes` allows
179
192
  the icon to be rotated when it is rendered. The `IconRotationTypes` enum
180
193
  can be found in `src/components/Icons/IconTypes.tsx`.
181
194
 
182
- ```js
195
+ ```jsx
183
196
  // Example
184
- <Icon
185
- name={IconNames.arrow}
186
- decorative={true}
187
- iconRotation={IconRotationTypes.rotate180}
188
- />
197
+ <Icon name={IconNames.Arrow} iconRotation={IconRotationTypes.Rotate180} />
189
198
  ```
190
199
 
191
- <Preview>
200
+ <Canvas>
192
201
  <Story name="Rotation Types">{allIconsType(rotations)}</Story>
193
- </Preview>
202
+ </Canvas>
194
203
 
195
204
  ## IconColors Types
196
205
 
197
206
  Update an SVG icon by passing a `color` prop with a value from `IconColors`.
198
- The `IconColors` enum can be found in`src/components/Icons/IconTypes.tsx`.
207
+ The `IconColors` enum can be found in `src/components/Icons/IconTypes.tsx`.
199
208
 
200
- ```js
209
+ ```jsx
201
210
  // Example
202
- <Icon
203
- name={IconNames.speaker_notes}
204
- decorative={true}
205
- color={IconColors.brand_primary}
206
- />
211
+ <Icon name={IconNames.Speaker_notes} color={IconColors.BrandPrimary} />
207
212
  ```
208
213
 
209
- <Preview>
214
+ <Canvas>
210
215
  <Story name="Color Types">{allIconsType(colors)}</Story>
211
- </Preview>
216
+ </Canvas>
212
217
 
213
218
  ## IconSizes Types
214
219
 
215
220
  Update an SVG icon by passing a `size` prop with a value from `IconSizes`.
216
221
  The `IconSizes` enum can be found in`src/components/Icons/IconTypes.tsx`.
217
222
 
218
- ```js
223
+ ```jsx
219
224
  // Example
220
- <Icon name={IconNames.clock} decorative={true} size={IconSizes.xxlarge} />
225
+ <Icon name={IconNames.Clock} size={IconSizes.ExtraExtraLarge} />
221
226
  ```
222
227
 
223
- <Preview>
228
+ <Canvas>
224
229
  <Story name="Sizes Types">{allIconsType(sizes)}</Story>
225
- </Preview>
230
+ </Canvas>
226
231
 
227
232
  ## All Display Icons
228
233
 
229
234
  The following icons are for generic purposes. All the available logo names can
230
235
  be found in the `IconNames` enum in `src/components/Icons/IconTypes.tsx`.
231
236
 
232
- <Preview withToolbar>
237
+ <Canvas withToolbar>
233
238
  <Story name="All Display Icons">{allIconsType(icons)}</Story>
234
- </Preview>
239
+ </Canvas>
235
240
 
236
241
  ## All Logo Icons
237
242
 
@@ -241,28 +246,32 @@ The following icons are meant to be used for logos for different libraries
241
246
  and products. All the available logo names can
242
247
  be found in the `LogoNames` enum in `src/components/Icons/IconTypes.tsx`.
243
248
 
244
- <Preview withToolbar>
249
+ <Canvas withToolbar>
245
250
  <Story name="All Logo Icons">{allIconsType(logos)}</Story>
246
- </Preview>
251
+ </Canvas>
247
252
 
248
253
  ## Custom Icons
249
254
 
250
255
  If you'd like to pass a custom svg to your application, you can pass it a
251
256
  child to the `Icon` component.
252
257
 
253
- ```js
254
- <Icon {...args}>
255
- <svg ...><!-- the direct svg here --></svg>
258
+ ```jsx
259
+ <Icon {...props}>
260
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 750 750" fill="#6BE9D8">
261
+ <g>
262
+ <path d="M709.9 399.9c-4.5-145.7-115.8-169.6-151.1-170.3-4.2-.1-6.7-4.9-4.2-8.4L632 110.6c3.4-4.8 2.4-11.7-2.3-15.3-15.9-12-36.3-21.4-60.3-28.8-4.3-1.3-8.6 2-8.5 6.5 1.2 50.5-27.6 114.3-36.5 132.9-1 2-3.9 1.9-4.8-.1C485.1 124 397.7 95.1 327.9 104.4c-71.3 9.5-101.6 26.5-163.5 96.6-61.9 70.1-80.2 260.7-82.1 309.4C80.4 559 40 617.1 40 617.1c154 81.4 340.9 68.2 402.2 61.9 44.4-4.6 68.5-21.8 78.5-30.9 2.5-2.3 1.4-6.6-2-7.3-73.8-15.7-80.7-37.2-94.8-63.5-14.5-27.1 8.2-135.7 104.2-108.6 79.6 22.5 51.5 114.9 39.6 145.8-1.4 3.7 2.4 7.3 6 5.6 34-16.5 140.5-79.5 136.2-220.2zM234.7 181.3c17.7-17 69-56.7 167.1-38 99.8 18.9 98.5 109.5 80.4 141.7-2.3 4.1-7 4.5-8.8.1-11.1-27.7-45.5-97.4-112-108-61.8-9.8-105.6 1.7-124.2 8.3-2.5.8-4.4-2.3-2.5-4.1zm-60.2 72l16.9-27.4c5.1-8.3 13.2-14.3 22.6-16.6 16.3-4.1 33-6.9 49.5-8.9 40.3-4.8 79.4-2.1 116.7 15.1 17.4 8 33.6 18.2 46.1 32.9 11.4 13.4 19 29.6 23.7 46.5 1.8 6.3 3.2 12.8 4.3 19.3.6 3.2-.1 6.6-1.7 9.4l-15.8 27.1c-1.7 3-6.1 2.4-7.1-.9-6.7-22-17.9-43.9-32.8-61-12.6-14.4-29.1-23.5-46.1-31.6-12.2-5.8-24.9-10.5-38-13.6-35.3-8.4-71.9-4.4-106.3 5.9-9.2 2.8-18.3 5.9-27.2 9.5-2.3.9-4.9-.7-5.2-3.2-.2-1 0-1.8.4-2.5zm-21.9 64.2l11.7-40.8c1.2-4.3 5-7.5 9.5-7.9l5.2-.5s87.8-25.9 160.4 9.8c56.9 28 68.3 78.8 70.5 99.5.6 5.5-1.4 11-5.3 14.8L389 407.5c-3.8 3.7-10.2 2.2-12-2.8-6-17.2-13.8-34.1-23.5-49.3-5.8-9.1-12.7-18.3-21.6-24.6-16.2-11.5-36.5-19.2-55.7-23.9-14.4-3.6-29.3-4.8-44.1-3.8-12.9.8-25.6 3.2-38 6.7-7.2 2-14.3 4.4-21.3 7.1-3.8 1.5-7.6 3-11.3 4.7-.6.2-1.9.7-3.4 1.3-3.2 1.1-6.5-2-5.5-5.4zM410 465.8c4.4 2 5.8 7.5 3 11.4l-14.8 20.7c-3.5 4.9-9.9 6.6-15.4 4.3l-25.5-10.9c-4.5-1.9-5.5-7.8-1.9-11.1l17.3-15.7c5.8-5.7 14.6-9.1 22-5.8l15.3 7.1zm-270.3-96.3l4.5-23.6c1.2-6.5 5.7-11.9 11.8-14.3 15.7-6.2 50.5-14.3 109.2-.1 62.6 15.1 83.4 66.2 90 91.6 2.2 8.5-.7 17.5-7.5 23.1l-13.4 11.1c-4.2 3.4-10.5 1.5-12-3.7-5.3-18.5-21.2-54.5-66.1-73.7-45.5-19.5-88.3-9.3-107.8-2.6-4.8 1.5-9.7-2.8-8.7-7.8zm-4.4 29.7c.1-5.4 4.2-9.9 9.6-10.6 30.7-3.8 127.8-7.6 155.8 89.7 1.6 5.4-.5 11.3-5.2 14.4l-15.1 10.1c-5 3.4-11.9 1.2-14-4.5-9.5-26-40.2-85.6-119.7-68.3-6.2 1.3-12-3.4-11.9-9.7l.5-21.1zm-9.1 72.9l3.3-19.1c1.4-8.3 9-14.1 17.4-13.1 21.2 2.4 60.2 11.5 85.5 44.9 5.8 7.7 9.2 16.8 10 26.4l.3 3.4c.6 7.1-2.7 14-8.7 18l-12.1 8.2c-4.4 3-10.5 1.2-12.6-3.7l-8.2-24.4c-3.5-10.4-11-19.1-20.8-24.1l-11.1-5.6c-6.7-3.4-14.2-5-21.7-4.5l-14.8.9c-4 .2-7.1-3.4-6.5-7.3zm-15.5 55.7l9.4-30.7c1.8-5.9 8-9.2 13.9-7.4 18.3 5.6 53.5 21.9 54.3 65.2 0 2.7-1.3 5.1-3.6 6.4-8.5 4.9-26.8 12.9-27.8 12-1.2-1.1.8-42.6-39.7-37.7-1.2.1-2.5-.1-3.6-.7-2.5-1.3-3.8-4.3-2.9-7.1zm63.8 100.5c-1.1 6.4-7.4 10.5-13.7 8.9l-85.5-21.9c-3.9-1-5.7-5.5-3.6-8.9l31.4-51.7c1.8-3 5.5-4.5 8.9-3.4 8.3 2.6 22.4 9 24.4 23.2.6 4.3-.9 8.7-4 11.8-1.4 1.4-3 2.5-4.8 3.2l-26.8 10.4c-2.1.8-2.6 3.5-1 5 .6.5 1.3.8 2.1.8l19.5-.2c3.7 0 7.4-.4 11.1-1 12.8-2.1 47-5 42 23.8zm72.1 12.7c-2.3 2.8-5 5.9-8.8 6.3-1.5.2-2.9 0-4.4-.2-1.5-.2-2.9-.2-4.4-.3l-10.5-.9c-3.8-.3-7.5-.7-11.3-1.2-2.9-.3-5.8-.7-8.6-1.2-4-.7-6.6-4.7-5.4-8.6 2.5-8.6 4.2-23.7-8.4-37.6-2-2.2-1.4-5.8 1.2-7.3l24.8-14.1c3.6-2.1 8-2.1 11.6-.1 8.2 4.5 22.3 14.1 29 28.8 5.4 12.1 3.4 26.2-4.8 36.4zm67 3.1c-4.2 4.1-9.8 6.5-15.7 6.8l-24.2 1.1c-4.2.2-7.1-4.2-5.3-8 8.1-17 20.6-55.5-19.4-76.9-3-1.6-3.3-5.9-.4-7.8l15.3-10.2c4.7-3.2 10.8-3.5 15.8-.7 22.8 12.3 80.6 50.2 33.9 95.7zm118.2-5.2c3.5 2.7 1.6 8.2-2.8 8.3l-77.5.8c-4.8.1-8.1-5-6-9.3 30.8-64.1-17.7-97.3-37.5-107.6-3.5-1.8-4-6.7-.9-9.1l9.6-7.7c7.2-5.7 16.7-7.7 25.6-5.4 14.1 3.7 26.1 11.8 33.7 18 5.4 4.4 8.6 10.9 8.8 17.9.9 51.1 29.9 80.9 47 94.1zm76.6-205c-12.4 0-36.1 1.2-52.5 10.2-4.7 2.6-10.2 3.1-15.4 1.7l-26.8-7.4c-4-1.1-5.6-5.9-3-9.2l14.9-18.8c5.2-7.1 13-11.6 21.6-10.2 17.4 2.9 46.3 10.1 63.6 27.4 2.6 2.3 1 6.3-2.4 6.3zm115 112c-1.7 2.2-5 2.2-6.8 0l-.1-.1c-1.8-2.3-7.3-138.3-146.4-168.7-5.4-1.2-7.7-7.5-4.3-11.9l19.6-25.6c4.6-6 12.2-8.9 19.7-7.5 28.1 5.5 95.7 25.7 120.5 96.6 29.5 84.5 13.9 96.8-2.2 117.2zm46.4-88.4c-.8 4.1-6.6 4.2-7.5.1-9.8-43.6-44.3-150.3-147.6-150.8-4.4 0-7.2-4.8-5-8.6l17.6-31.4c4.4-7.9 19.3-9.1 28.1-7 41.1 9.9 143 47.6 114.4 197.7z" />
263
+ </g>
264
+ </svg>
256
265
  </Icon>
257
266
  ```
258
267
 
259
- <Preview>
268
+ <Canvas>
260
269
  <Story
261
270
  name="Custom Icons"
262
271
  args={{
263
- color: IconColors.ui_black,
264
- size: IconSizes.xxxlarge,
265
- iconRotation: IconRotationTypes.rotate0,
272
+ color: IconColors.UiBlack,
273
+ size: IconSizes.ExtraExtraExtraLarge,
274
+ iconRotation: IconRotationTypes.Rotate0,
266
275
  decorative: true,
267
276
  }}
268
277
  >
@@ -280,4 +289,4 @@ child to the `Icon` component.
280
289
  </Icon>
281
290
  )}
282
291
  </Story>
283
- </Preview>
292
+ </Canvas>
@@ -7,38 +7,46 @@ import { IconNames } from "./IconTypes";
7
7
 
8
8
  describe("Icon Accessibility", () => {
9
9
  it("passes axe accessibility test", async () => {
10
- const { container } = render(
11
- <Icon name={IconNames.download} decorative={true} />
12
- );
10
+ const { container } = render(<Icon name={IconNames.Download} />);
13
11
  expect(await axe(container)).toHaveNoViolations();
14
12
  });
15
13
  });
16
14
 
17
15
  describe("Icon", () => {
18
- it("throws an error if both name and children are passed to Icon", () => {
19
- expect(() =>
20
- render(
21
- <Icon name={IconNames.download} decorative={true}>
22
- <svg viewBox="0 0 24 14" xmlns="http://www.w3.org/2000/svg">
23
- <path
24
- fillRule="evenodd"
25
- clipRule="evenodd"
26
- d="M10.526 12.871L.263 1.676 1.737.324 12 11.52 22.263.324l1.474 1.352L13.474 12.87a2 2 0 01-2.948 0z"
27
- />
28
- </svg>
29
- </Icon>
30
- )
31
- ).toThrowError("Icon accepts either a name or children, not both");
16
+ it("consoles a warning if both name and children are passed to Icon", () => {
17
+ const warn = jest.spyOn(console, "warn");
18
+ render(
19
+ <Icon name={IconNames.Download} decorative={true}>
20
+ <svg viewBox="0 0 24 14" xmlns="http://www.w3.org/2000/svg">
21
+ <path
22
+ fillRule="evenodd"
23
+ clipRule="evenodd"
24
+ d="M10.526 12.871L.263 1.676 1.737.324 12 11.52 22.263.324l1.474 1.352L13.474 12.87a2 2 0 01-2.948 0z"
25
+ />
26
+ </svg>
27
+ </Icon>
28
+ );
29
+ expect(warn).toHaveBeenCalledWith(
30
+ "Icon accepts either a `name` prop or an `svg` element child, not both."
31
+ );
32
+ });
33
+
34
+ it("consoles a warning if both name and children are not passed", () => {
35
+ const warn = jest.spyOn(console, "warn");
36
+ render(<Icon />);
37
+ expect(warn).toHaveBeenCalledWith(
38
+ "Pass an icon `name` prop or an SVG child to `Icon` to ensure an icon appears."
39
+ );
32
40
  });
33
41
 
34
42
  it("renders an icon based on the icon `name` prop", () => {
35
- const utils = render(<Icon name={IconNames.download} decorative={true} />);
36
- expect(utils.container.querySelector(".icon")).toBeInTheDocument();
43
+ const { container } = render(<Icon name={IconNames.Download} />);
44
+ expect(container.querySelector("svg")).toBeInTheDocument();
37
45
  });
38
46
 
39
47
  it("renders an icon based on the child", () => {
40
- const utils = render(
41
- <Icon decorative={true}>
48
+ const { container } = render(
49
+ <Icon>
42
50
  <svg viewBox="0 0 24 14" xmlns="http://www.w3.org/2000/svg">
43
51
  <path
44
52
  fillRule="evenodd"
@@ -48,6 +56,6 @@ describe("Icon", () => {
48
56
  </svg>
49
57
  </Icon>
50
58
  );
51
- expect(utils.container.querySelector(".icon")).toBeInTheDocument();
59
+ expect(container.querySelector("svg")).toBeInTheDocument();
52
60
  });
53
61
  });
@@ -1,39 +1,38 @@
1
- /* eslint-disable camelcase */
2
1
  import * as React from "react";
3
- import bem from "../../utils/bem";
4
- import generateUUID from "../../helpers/generateUUID";
2
+ import { Icon as ChakraIcon, Box, useStyleConfig } from "@chakra-ui/react";
5
3
 
4
+ import generateUUID from "../../helpers/generateUUID";
6
5
  import {
7
- IconRotationTypes,
8
- IconNames,
9
- LogoNames,
6
+ IconAlign,
10
7
  IconColors,
8
+ IconNames,
9
+ IconRotationTypes,
11
10
  IconSizes,
11
+ IconTypes,
12
+ LogoNames,
12
13
  } from "./IconTypes";
13
-
14
14
  import iconSvgs from "./IconSvgs";
15
15
 
16
16
  export interface IconProps {
17
- /** Additional attributes to pass to the `<svg>` tag. */
18
- attributes?: { [key: string]: any };
19
- /** BlockName for use with BEM. See how to work with blockNames and BEM here: http://getbem.com/introduction/ */
20
- blockName?: string;
21
- /** Modifiers array for use with BEM. See how to work with modifiers and BEM here: http://getbem.com/introduction/ */
22
- modifiers?: string[];
17
+ /** Aligns the icon. */
18
+ align?: IconAlign;
23
19
  /** className that appears in addition to "icon" */
24
20
  className?: string;
25
- /** Icons designated as decorative will be ignored by screenreaders */
21
+ /** Overrides default icon color (black). */
22
+ color?: IconColors;
23
+ /** Icons designated as decorative will be ignored by screenreaders. True
24
+ * by default. */
26
25
  decorative?: boolean;
27
- /** This text will be added as a child `<title>` element inside the `<svg>` tag. It is recommended to do this for increased accessibility. */
28
- titleText?: string;
29
26
  /** Rotates the icon clockwise in increments of 90deg */
30
27
  iconRotation?: IconRotationTypes;
31
- /** Overrides default icon color (black). */
32
- color?: IconColors;
33
- /** Sets the icon size. */
34
- size?: IconSizes;
28
+ /** ID that other components can cross reference for accessibility purposes */
29
+ id?: string;
35
30
  /** The name of the icon you want to use. */
36
31
  name?: IconNames | LogoNames;
32
+ /** Sets the icon size. */
33
+ size?: IconSizes;
34
+ /** Sets the icon variant type. */
35
+ type?: IconTypes;
37
36
  }
38
37
 
39
38
  /**
@@ -41,63 +40,66 @@ export interface IconProps {
41
40
  */
42
41
  export default function Icon(props: React.PropsWithChildren<IconProps>) {
43
42
  const {
44
- blockName,
45
- decorative = false,
43
+ align = "none",
44
+ children,
46
45
  className,
47
- titleText,
48
- iconRotation,
49
- color,
50
- size,
51
- modifiers = [],
46
+ color = IconColors.UiBlack,
47
+ decorative = true,
48
+ iconRotation = IconRotationTypes.Rotate0,
49
+ id = generateUUID(),
52
50
  name,
53
- children,
54
- attributes = [],
51
+ size = IconSizes.Medium,
52
+ type = IconTypes.Default,
55
53
  } = props;
56
-
57
- if (iconRotation) {
58
- modifiers.push(iconRotation);
59
- }
60
-
61
- if (color) {
62
- modifiers.push(color);
63
- }
64
-
65
- if (size) {
66
- modifiers.push(size);
67
- }
68
-
69
- const iconID = generateUUID();
54
+ const styles = useStyleConfig("Icon", {
55
+ align,
56
+ color,
57
+ iconRotation,
58
+ size,
59
+ variant: type,
60
+ });
70
61
  const iconProps = {
71
- className: bem("icon", modifiers, blockName, [className]),
72
- id: iconID,
73
- role: "img",
74
- title: titleText || null,
75
62
  "aria-hidden": decorative,
76
- ...attributes,
63
+ className,
64
+ id,
65
+ role: "img",
77
66
  };
78
-
79
- // Apply icon props to SVG that was passed as a child.
80
- const renderChildren = () =>
81
- React.Children.map(children, (child) =>
82
- React.cloneElement(child as JSX.Element, { ...iconProps })
83
- );
67
+ let childSVG = null;
84
68
 
85
69
  // Component prop validation
86
70
  if (name && children) {
87
- throw new Error("Icon accepts either a name or children, not both");
71
+ console.warn(
72
+ "Icon accepts either a `name` prop or an `svg` element child, not both."
73
+ );
74
+ return null;
88
75
  } else if (!name && !children) {
89
76
  console.warn(
90
- "Pass a name or any children to Icon to ensure an icon appears"
77
+ "Pass an icon `name` prop or an SVG child to `Icon` to ensure an icon appears."
91
78
  );
79
+ return null;
92
80
  }
93
81
 
94
82
  // The user wants to render an existing icon. Load the icon and render it
95
- // as a component. Otherwise, we're just going to render the children that
96
- // were passed to this component.
83
+ // as a component through Chakra's Icon component. Otherwise, we're going to
84
+ // render the SVG child with NYPL-theme styling.
97
85
  if (name) {
98
- const SvgComponent = iconSvgs[name];
99
- return <SvgComponent {...iconProps} />;
86
+ const SvgComponent: any = iconSvgs[name];
87
+ return <ChakraIcon as={SvgComponent} {...iconProps} __css={styles} />;
88
+ }
89
+
90
+ // If no `name` prop was passed, we expect a child SVG element to be passed.
91
+ // Apply icon props to the SVG child.
92
+ if (
93
+ (children as JSX.Element).type === "svg" ||
94
+ (children as JSX.Element).props.type === "svg" ||
95
+ (children as JSX.Element).props.mdxType === "svg"
96
+ ) {
97
+ childSVG = React.cloneElement(children as JSX.Element, {
98
+ ...iconProps,
99
+ });
100
+ } else {
101
+ console.warn("You must pass an `svg` element to the `Icon` component.");
100
102
  }
101
103
 
102
- return <>{renderChildren()}</>;
104
+ return <Box __css={styles}>{childSVG}</Box>;
103
105
  }