@nypl/design-system-react-components 0.25.8 → 0.25.9

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 (250) hide show
  1. package/CHANGELOG.md +45 -1
  2. package/README.md +1 -1
  3. package/dist/components/Button/Button.d.ts +6 -6
  4. package/dist/components/Button/ButtonTypes.d.ts +0 -1
  5. package/dist/components/Card/Card.d.ts +6 -4
  6. package/dist/components/Checkbox/Checkbox.d.ts +3 -2
  7. package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +3 -2
  8. package/dist/components/ComponentWrapper/ComponentWrapper.d.ts +8 -2
  9. package/dist/components/DatePicker/DatePicker.d.ts +3 -2
  10. package/dist/components/Form/Form.d.ts +2 -2
  11. package/dist/components/Heading/Heading.d.ts +7 -3
  12. package/dist/components/Heading/HeadingTypes.d.ts +6 -6
  13. package/dist/components/HelperErrorText/HelperErrorText.d.ts +5 -2
  14. package/dist/components/HorizontalRule/HorizontalRule.d.ts +2 -2
  15. package/dist/components/Icons/Icon.d.ts +4 -4
  16. package/dist/components/Icons/IconSvgs.d.ts +0 -21
  17. package/dist/components/Icons/IconTypes.d.ts +0 -23
  18. package/dist/components/Image/Image.d.ts +11 -3
  19. package/dist/components/Logo/Logo.d.ts +28 -0
  20. package/dist/components/Logo/LogoSvgs.d.ts +18 -0
  21. package/dist/components/Logo/LogoTypes.d.ts +30 -0
  22. package/dist/components/Modal/Modal.d.ts +0 -4
  23. package/dist/components/Notification/Notification.d.ts +2 -2
  24. package/dist/components/Placeholder/Placeholder.d.ts +3 -5
  25. package/dist/components/Radio/Radio.d.ts +6 -5
  26. package/dist/components/RadioGroup/RadioGroup.d.ts +3 -2
  27. package/dist/components/SearchBar/SearchBar.d.ts +10 -2
  28. package/dist/components/Select/Select.d.ts +3 -2
  29. package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +8 -4
  30. package/dist/components/Slider/Slider.d.ts +3 -2
  31. package/dist/components/StatusBadge/StatusBadge.d.ts +2 -1
  32. package/dist/components/StructuredContent/StructuredContent.d.ts +41 -0
  33. package/dist/components/StructuredContent/StructuredContentTypes.d.ts +5 -0
  34. package/dist/components/Table/Table.d.ts +23 -0
  35. package/dist/components/Template/Template.d.ts +8 -3
  36. package/dist/components/Text/Text.d.ts +2 -2
  37. package/dist/components/TextInput/TextInput.d.ts +4 -3
  38. package/dist/components/Toggle/Toggle.d.ts +3 -2
  39. package/dist/components/VideoPlayer/VideoPlayer.d.ts +14 -5
  40. package/dist/design-system-react-components.cjs.development.js +5630 -5692
  41. package/dist/design-system-react-components.cjs.development.js.map +1 -1
  42. package/dist/design-system-react-components.cjs.production.min.js +1 -1
  43. package/dist/design-system-react-components.cjs.production.min.js.map +1 -1
  44. package/dist/design-system-react-components.esm.js +4304 -4362
  45. package/dist/design-system-react-components.esm.js.map +1 -1
  46. package/dist/index.d.ts +6 -4
  47. package/dist/styles.css +2 -2
  48. package/dist/theme/components/button.d.ts +0 -12
  49. package/dist/theme/components/card.d.ts +14 -2
  50. package/dist/theme/components/customTable.d.ts +47 -0
  51. package/dist/theme/components/fieldset.d.ts +2 -2
  52. package/dist/theme/components/global.d.ts +1 -1
  53. package/dist/theme/components/heading.d.ts +4 -0
  54. package/dist/theme/components/label.d.ts +1 -1
  55. package/dist/theme/components/link.d.ts +14 -1
  56. package/dist/theme/components/list.d.ts +0 -2
  57. package/dist/theme/components/logo.d.ts +4 -0
  58. package/dist/theme/components/searchBar.d.ts +7 -13
  59. package/dist/theme/components/select.d.ts +1 -0
  60. package/dist/theme/components/structuredContent.d.ts +33 -0
  61. package/dist/theme/components/template.d.ts +10 -10
  62. package/dist/theme/components/textInput.d.ts +2 -0
  63. package/dist/theme/components/toggle.d.ts +8 -5
  64. package/dist/utils/utils.d.ts +10 -0
  65. package/package.json +1 -2
  66. package/src/__tests__/utils/utils.test.ts +23 -1
  67. package/src/components/Accordion/Accordion.stories.mdx +14 -12
  68. package/src/components/Autosuggest/Autosuggest.stories.mdx +2 -1
  69. package/src/components/Autosuggest/Autosuggest.stories.tsx +24 -48
  70. package/src/components/Autosuggest/_Autosuggest.scss +2 -6
  71. package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +30 -11
  72. package/src/components/Button/Button.stories.mdx +93 -48
  73. package/src/components/Button/Button.test.tsx +0 -12
  74. package/src/components/Button/Button.tsx +7 -7
  75. package/src/components/Button/ButtonTypes.tsx +0 -1
  76. package/src/components/Button/__snapshots__/Button.test.tsx.snap +0 -12
  77. package/src/components/Card/Card.stories.mdx +186 -71
  78. package/src/components/Card/Card.test.tsx +45 -22
  79. package/src/components/Card/Card.tsx +17 -5
  80. package/src/components/Card/__snapshots__/Card.test.tsx.snap +8 -2
  81. package/src/components/Chakra/Box.stories.mdx +3 -3
  82. package/src/components/Chakra/Center.stories.mdx +5 -5
  83. package/src/components/Chakra/Grid.stories.mdx +3 -3
  84. package/src/components/Chakra/Stack.stories.mdx +2 -2
  85. package/src/components/Checkbox/Checkbox.stories.mdx +37 -15
  86. package/src/components/Checkbox/Checkbox.tsx +13 -8
  87. package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +48 -16
  88. package/src/components/CheckboxGroup/CheckboxGroup.tsx +14 -10
  89. package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +6 -3
  90. package/src/components/ComponentWrapper/ComponentWrapper.test.tsx +151 -0
  91. package/src/components/ComponentWrapper/ComponentWrapper.tsx +36 -23
  92. package/src/components/ComponentWrapper/__snapshots__/ComponentWrapper.test.tsx.snap +85 -0
  93. package/src/components/DatePicker/DatePicker.stories.mdx +63 -18
  94. package/src/components/DatePicker/DatePicker.tsx +10 -6
  95. package/src/components/DatePicker/__snapshots__/DatePicker.test.tsx.snap +36 -18
  96. package/src/components/Fieldset/Fieldset.stories.mdx +19 -8
  97. package/src/components/Form/Form.stories.mdx +49 -41
  98. package/src/components/Form/Form.tsx +5 -4
  99. package/src/components/Grid/SimpleGrid.stories.mdx +26 -26
  100. package/src/components/Heading/Heading.stories.mdx +59 -23
  101. package/src/components/Heading/Heading.test.tsx +82 -18
  102. package/src/components/Heading/Heading.tsx +31 -31
  103. package/src/components/Heading/HeadingTypes.tsx +6 -6
  104. package/src/components/Heading/__snapshots__/Heading.test.tsx.snap +71 -0
  105. package/src/components/HelperErrorText/HelperErrorText.stories.mdx +55 -27
  106. package/src/components/HelperErrorText/HelperErrorText.test.tsx +42 -15
  107. package/src/components/HelperErrorText/HelperErrorText.tsx +24 -24
  108. package/src/components/HelperErrorText/__snapshots__/HelperErrorText.test.tsx.snap +41 -4
  109. package/src/components/Hero/Hero.stories.mdx +72 -53
  110. package/src/components/HorizontalRule/HorizontalRule.stories.mdx +9 -8
  111. package/src/components/HorizontalRule/HorizontalRule.tsx +2 -4
  112. package/src/components/Icons/Icon.stories.mdx +77 -76
  113. package/src/components/Icons/Icon.tsx +4 -5
  114. package/src/components/Icons/IconSvgs.tsx +0 -42
  115. package/src/components/Icons/IconTypes.tsx +0 -24
  116. package/src/components/Image/Image.stories.mdx +66 -18
  117. package/src/components/Image/Image.tsx +21 -10
  118. package/src/components/Label/Label.stories.mdx +20 -19
  119. package/src/components/Link/Link.stories.mdx +102 -51
  120. package/src/components/Link/Link.test.tsx +38 -8
  121. package/src/components/Link/Link.tsx +19 -12
  122. package/src/components/Link/__snapshots__/Link.test.tsx.snap +60 -0
  123. package/src/components/List/List.stories.mdx +36 -24
  124. package/src/components/Logo/Logo.stories.mdx +220 -0
  125. package/src/components/Logo/Logo.test.tsx +98 -0
  126. package/src/components/Logo/Logo.tsx +97 -0
  127. package/src/components/Logo/LogoSvgs.tsx +34 -0
  128. package/src/components/Logo/LogoTypes.tsx +32 -0
  129. package/src/components/Logo/__snapshots__/Logo.test.tsx.snap +71 -0
  130. package/src/components/Modal/Modal.stories.mdx +20 -5
  131. package/src/components/Modal/Modal.tsx +2 -8
  132. package/src/components/Notification/Notification.stories.mdx +61 -38
  133. package/src/components/Notification/Notification.tsx +9 -4
  134. package/src/components/Notification/__snapshots__/Notification.test.tsx.snap +4 -0
  135. package/src/components/Pagination/Pagination.stories.mdx +17 -6
  136. package/src/components/Pagination/Pagination.tsx +1 -1
  137. package/src/components/Placeholder/Placeholder.tsx +7 -14
  138. package/src/components/ProgressIndicator/ProgressIndicator.stories.mdx +72 -43
  139. package/src/components/Radio/Radio.stories.mdx +39 -19
  140. package/src/components/Radio/Radio.tsx +13 -9
  141. package/src/components/RadioGroup/RadioGroup.stories.mdx +50 -16
  142. package/src/components/RadioGroup/RadioGroup.tsx +15 -11
  143. package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +6 -3
  144. package/src/components/SearchBar/SearchBar.Test.tsx +58 -10
  145. package/src/components/SearchBar/SearchBar.stories.mdx +109 -30
  146. package/src/components/SearchBar/SearchBar.tsx +53 -32
  147. package/src/components/Select/Select.stories.mdx +48 -14
  148. package/src/components/Select/Select.tsx +16 -10
  149. package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +50 -16
  150. package/src/components/SkeletonLoader/SkeletonLoader.tsx +8 -4
  151. package/src/components/Slider/Slider.stories.mdx +72 -22
  152. package/src/components/Slider/Slider.tsx +15 -10
  153. package/src/components/Slider/__snapshots__/Slider.test.tsx.snap +60 -30
  154. package/src/components/StatusBadge/StatusBadge.stories.mdx +33 -18
  155. package/src/components/StatusBadge/StatusBadge.tsx +2 -1
  156. package/src/components/StructuredContent/StructuredContent.stories.mdx +427 -0
  157. package/src/components/StructuredContent/StructuredContent.test.tsx +376 -0
  158. package/src/components/StructuredContent/StructuredContent.tsx +153 -0
  159. package/src/components/StructuredContent/StructuredContentTypes.tsx +5 -0
  160. package/src/components/StructuredContent/__snapshots__/StructuredContent.test.tsx.snap +283 -0
  161. package/src/components/StyleGuide/Bidirectionality.stories.mdx +32 -83
  162. package/src/components/StyleGuide/Breakpoints.stories.mdx +1 -11
  163. package/src/components/StyleGuide/Buttons.stories.mdx +3 -18
  164. package/src/components/StyleGuide/ColorCard.tsx +1 -2
  165. package/src/components/StyleGuide/Colors.stories.mdx +3 -11
  166. package/src/components/StyleGuide/DesignTokens.stories.mdx +3 -8
  167. package/src/components/StyleGuide/Forms.stories.mdx +2 -10
  168. package/src/components/StyleGuide/Iconography.stories.mdx +8 -34
  169. package/src/components/StyleGuide/Spacing.stories.mdx +3 -14
  170. package/src/components/StyleGuide/Typography.stories.mdx +64 -76
  171. package/src/components/Table/Table.stories.mdx +66 -0
  172. package/src/components/Table/Table.test.tsx +60 -0
  173. package/src/components/Table/Table.tsx +116 -0
  174. package/src/components/Tabs/Tabs.stories.mdx +19 -13
  175. package/src/components/Tabs/Tabs.test.tsx +1 -1
  176. package/src/components/Template/Template.stories.mdx +56 -47
  177. package/src/components/Template/Template.test.tsx +65 -5
  178. package/src/components/Template/Template.tsx +35 -5
  179. package/src/components/Template/__snapshots__/Template.test.tsx.snap +76 -0
  180. package/src/components/Text/Text.stories.mdx +33 -11
  181. package/src/components/Text/Text.tsx +2 -2
  182. package/src/components/TextInput/TextInput.stories.mdx +84 -17
  183. package/src/components/TextInput/TextInput.test.tsx +96 -0
  184. package/src/components/TextInput/TextInput.tsx +12 -8
  185. package/src/components/TextInput/__snapshots__/TextInput.test.tsx.snap +240 -0
  186. package/src/components/Toggle/Toggle.stories.mdx +33 -9
  187. package/src/components/Toggle/Toggle.tsx +14 -9
  188. package/src/components/VideoPlayer/VideoPlayer.stories.mdx +64 -14
  189. package/src/components/VideoPlayer/VideoPlayer.tsx +17 -7
  190. package/src/components/VideoPlayer/__snapshots__/VideoPlayer.test.tsx.snap +12 -6
  191. package/src/docs/Chakra.stories.mdx +5 -8
  192. package/src/docs/Intro.stories.mdx +2 -2
  193. package/src/index.ts +5 -4
  194. package/src/styles/base/_03-base.scss +1 -1
  195. package/src/styles/base/_place-holder.scss +7 -7
  196. package/src/styles.scss +1 -5
  197. package/src/theme/components/breadcrumb.ts +3 -3
  198. package/src/theme/components/button.ts +5 -12
  199. package/src/theme/components/card.ts +5 -2
  200. package/src/theme/components/checkbox.ts +1 -1
  201. package/src/theme/components/customTable.ts +50 -0
  202. package/src/theme/components/datePicker.ts +1 -1
  203. package/src/theme/components/global.ts +6 -6
  204. package/src/theme/components/heading.ts +13 -11
  205. package/src/theme/components/helperErrorText.ts +1 -1
  206. package/src/theme/components/image.ts +1 -1
  207. package/src/theme/components/link.ts +17 -5
  208. package/src/theme/components/list.ts +1 -3
  209. package/src/theme/components/logo.ts +54 -0
  210. package/src/theme/components/notification.ts +1 -1
  211. package/src/theme/components/searchBar.ts +7 -13
  212. package/src/theme/components/select.ts +1 -0
  213. package/src/theme/components/statusBadge.ts +1 -1
  214. package/src/theme/components/structuredContent.ts +54 -0
  215. package/src/theme/components/template.ts +10 -10
  216. package/src/theme/components/text.ts +6 -6
  217. package/src/theme/components/textInput.ts +1 -0
  218. package/src/theme/components/toggle.ts +9 -5
  219. package/src/theme/components/videoPlayer.ts +0 -2
  220. package/src/theme/foundations/global.ts +2 -2
  221. package/src/theme/foundations/typography.ts +84 -12
  222. package/src/theme/index.ts +6 -0
  223. package/src/utils/componentCategories.ts +1 -1
  224. package/src/utils/utils.ts +17 -0
  225. package/dist/__tests__/utils/bem.test.d.ts +0 -1
  226. package/dist/components/CardEdition/CardEdition.d.ts +0 -21
  227. package/dist/components/CardEdition/CardEdition.stories.d.ts +0 -27
  228. package/dist/components/Input/Input.d.ts +0 -36
  229. package/dist/components/Input/Input.stories.d.ts +0 -29
  230. package/dist/components/Input/InputTypes.d.ts +0 -6
  231. package/dist/components/StyleGuide/UIDocCard.d.ts +0 -11
  232. package/dist/helpers/CSSVariablesHelper.d.ts +0 -3
  233. package/dist/helpers/getCSSVariable.d.ts +0 -1
  234. package/dist/interfaces.d.ts +0 -3
  235. package/dist/utils/bem.d.ts +0 -1
  236. package/src/__tests__/utils/bem.test.ts +0 -37
  237. package/src/components/CardEdition/CardEdition.stories.tsx +0 -122
  238. package/src/components/CardEdition/CardEdition.test.tsx +0 -395
  239. package/src/components/CardEdition/CardEdition.tsx +0 -60
  240. package/src/components/CardEdition/_CardEdition.scss +0 -137
  241. package/src/components/Input/Input.stories.tsx +0 -133
  242. package/src/components/Input/Input.test.tsx +0 -266
  243. package/src/components/Input/Input.tsx +0 -81
  244. package/src/components/Input/InputTypes.tsx +0 -8
  245. package/src/components/Input/_Input.scss +0 -78
  246. package/src/components/StyleGuide/UIDocCard.tsx +0 -36
  247. package/src/helpers/CSSVariablesHelper.tsx +0 -34
  248. package/src/helpers/getCSSVariable.tsx +0 -5
  249. package/src/interfaces.ts +0 -3
  250. package/src/utils/bem.ts +0 -44
@@ -1,67 +1,67 @@
1
- // MT-82, MT 225, etc
1
+ import { Heading as ChakraHeading, useStyleConfig } from "@chakra-ui/react";
2
2
  import * as React from "react";
3
- import {
4
- Box,
5
- Heading as ChakraHeading,
6
- Link as ChakraLink,
7
- useStyleConfig,
8
- } from "@chakra-ui/react";
9
3
 
10
4
  import { HeadingDisplaySizes, HeadingLevels } from "./HeadingTypes";
5
+ import Link from "../Link/Link";
6
+ import { getVariant } from "../../utils/utils";
7
+ import generateUUID from "../../helpers/generateUUID";
11
8
 
12
9
  export interface HeadingProps {
13
10
  /** Optionally pass in additional Chakra-based styles. */
14
11
  additionalStyles?: { [key: string]: any };
15
12
  /** Optional className that appears in addition to `heading` */
16
13
  className?: string;
17
- /** Optional size used to override the default styles of the semantic HTML `<h>` elements */
14
+ /** Optional size used to override the default styles of the semantic HTM
15
+ * `<h>` elements */
18
16
  displaySize?: HeadingDisplaySizes;
19
17
  /** Optional ID that other components can cross reference for accessibility purposes */
20
18
  id?: string;
21
- /** Optional number 1-6 used to create the `<h*>` tag; if prop is not passed, `Heading` will default to `<h2>` */
19
+ /** Optional number 1-6 used to create the `<h*>` tag; if prop is not passed,
20
+ * `Heading` will default to `<h2>` */
22
21
  level?: HeadingLevels;
23
22
  /** Inner text of the `<h*>` element */
24
23
  text?: string;
25
- /** Optional URL that header points to; when `url` prop is passed to `Heading`, a child `<a>` element is created and the heading text becomes an active link */
24
+ /** Optional URL that header points to; when `url` prop is passed to
25
+ * `Heading`, a child `<a>` element is created and the heading text becomes
26
+ * an active link */
26
27
  url?: string;
27
28
  /** Optional className for the URL when the `url` prop is passed */
28
29
  urlClass?: string;
29
30
  }
30
31
 
31
- // Used to map between ButtonTypes enum values and Chakra variant options.
32
- const variantMap = {};
33
- for (const type in HeadingDisplaySizes) {
34
- variantMap[HeadingDisplaySizes[type]] = HeadingDisplaySizes[type];
35
- }
36
-
37
- /**
38
- * Map the HeadingDisplaySizes to the Heading Chakra theme variant object. If a wrong
39
- * value is passed (typically in non-Typescript scenarios), then the default
40
- * is "null" and displaySize is not envoked.
41
- */
42
- const getVariant = (displaySize) => variantMap[displaySize] || null;
32
+ /** Map the word heading level to the number heading level. The default is 2. */
33
+ const getMappedLevel = (level = HeadingLevels.Two) => {
34
+ const levelMap = {
35
+ one: 1,
36
+ two: 2,
37
+ three: 3,
38
+ four: 4,
39
+ five: 5,
40
+ six: 6,
41
+ };
42
+ return levelMap[level] || 2;
43
+ };
43
44
 
44
45
  function Heading(props: React.PropsWithChildren<HeadingProps>) {
45
46
  const {
46
47
  additionalStyles = {},
47
48
  className,
48
49
  displaySize,
49
- id,
50
+ id = generateUUID(),
50
51
  level = HeadingLevels.Two,
51
52
  text,
52
53
  url,
53
54
  urlClass,
54
55
  } = props;
55
- const variant = displaySize ? getVariant(displaySize) : `h${level}`;
56
+ const finalLevel = getMappedLevel(level);
57
+ const variant = displaySize
58
+ ? getVariant(displaySize, HeadingDisplaySizes)
59
+ : `h${finalLevel}`;
56
60
  const styles = useStyleConfig("Heading", { variant });
57
61
  // Combine native base styles with any additional styles.
58
62
  // This is used in the `Hero` and `Notification` components.
59
63
  const finalStyles = { ...styles, ...additionalStyles };
60
- const asHeading: any = `h${level}`;
61
-
62
- if (level < 1 || level > 6) {
63
- throw new Error("Heading only supports levels 1-6");
64
- }
64
+ const asHeading: any = `h${finalLevel}`;
65
65
 
66
66
  if (!props.children && !text) {
67
67
  throw new Error("Heading has no children, please pass prop: text");
@@ -80,9 +80,9 @@ function Heading(props: React.PropsWithChildren<HeadingProps>) {
80
80
 
81
81
  const contentToRender = props.children ? props.children : text;
82
82
  const content = url ? (
83
- <Box as={ChakraLink} href={url} className={urlClass}>
83
+ <Link className={urlClass} href={url} id={`${id}-link`}>
84
84
  {contentToRender}
85
- </Box>
85
+ </Link>
86
86
  ) : (
87
87
  contentToRender
88
88
  );
@@ -6,10 +6,10 @@ export enum HeadingDisplaySizes {
6
6
  }
7
7
 
8
8
  export enum HeadingLevels {
9
- One = 1,
10
- Two = 2,
11
- Three = 3,
12
- Four = 4,
13
- Five = 5,
14
- Six = 6,
9
+ One = "one",
10
+ Two = "two",
11
+ Three = "three",
12
+ Four = "four",
13
+ Five = "five",
14
+ Six = "six",
15
15
  }
@@ -0,0 +1,71 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Heading renders the UI snapshot correctly 1`] = `
4
+ <h1
5
+ className="chakra-heading css-0"
6
+ id="basic"
7
+ >
8
+ Heading text
9
+ </h1>
10
+ `;
11
+
12
+ exports[`Heading renders the UI snapshot correctly 2`] = `
13
+ <h1
14
+ className="chakra-heading css-0"
15
+ id="basicWithChildText"
16
+ >
17
+ Heading text
18
+ </h1>
19
+ `;
20
+
21
+ exports[`Heading renders the UI snapshot correctly 3`] = `
22
+ <h1
23
+ className="chakra-heading css-0"
24
+ id="customDisplaySize"
25
+ >
26
+ Heading with Secondary displaySize
27
+ </h1>
28
+ `;
29
+
30
+ exports[`Heading renders the UI snapshot correctly 4`] = `
31
+ <h6
32
+ className="chakra-heading css-0"
33
+ id="otherLevel"
34
+ >
35
+ Heading level six
36
+ </h6>
37
+ `;
38
+
39
+ exports[`Heading renders the UI snapshot correctly 5`] = `
40
+ <h1
41
+ className="chakra-heading css-0"
42
+ id="withLink"
43
+ >
44
+ <a
45
+ className="css-0"
46
+ href="fake-url"
47
+ id="withLink-link"
48
+ rel={null}
49
+ target={null}
50
+ >
51
+ Heading text is a link
52
+ </a>
53
+ </h1>
54
+ `;
55
+
56
+ exports[`Heading renders the UI snapshot correctly 6`] = `
57
+ <h1
58
+ className="chakra-heading css-0"
59
+ id="withCustomLink"
60
+ >
61
+ Part of the heading text is
62
+ <a
63
+ className="custom-link"
64
+ href="fake-url"
65
+ >
66
+ <span>
67
+ a link
68
+ </span>
69
+ </a>
70
+ </h1>
71
+ `;
@@ -1,13 +1,15 @@
1
1
  import {
2
- Meta,
3
- Story,
4
- Canvas,
5
2
  ArgsTable,
3
+ Canvas,
6
4
  Description,
7
- } from "@storybook/addon-docs/blocks";
5
+ Meta,
6
+ Story,
7
+ } from "@storybook/addon-docs";
8
8
  import { withDesign } from "storybook-addon-designs";
9
9
 
10
10
  import HelperErrorText from "./HelperErrorText";
11
+ import Link from "../Link/Link";
12
+ import Text from "../Text/Text";
11
13
  import { getCategory } from "../../utils/componentCategories";
12
14
  import DSProvider from "../../theme/provider";
13
15
 
@@ -23,10 +25,20 @@ import DSProvider from "../../theme/provider";
23
25
  jest: ["HelperErrorText.test.tsx"],
24
26
  }}
25
27
  argTypes={{
26
- ariaAtomic: { table: { disable: true } },
28
+ additionalStyles: { control: false },
29
+ ariaAtomic: {
30
+ control: false,
31
+ table: { defaultValue: { summary: true } },
32
+ },
33
+ ariaLive: {
34
+ table: { defaultValue: { summary: "polite" } },
35
+ },
27
36
  children: { table: { disable: true } },
28
- className: { table: { disable: true } },
29
- id: { table: { disable: true } },
37
+ className: { control: false },
38
+ id: { control: false },
39
+ isInvalid: {
40
+ table: { defaultValue: { summary: false } },
41
+ },
30
42
  }}
31
43
  />
32
44
 
@@ -35,41 +47,57 @@ import DSProvider from "../../theme/provider";
35
47
  | Component Version | DS Version |
36
48
  | ----------------- | ---------- |
37
49
  | Added | `0.0.10` |
38
- | Latest | `0.25.3` |
50
+ | Latest | `0.25.9` |
39
51
 
40
52
  <Description of={HelperErrorText} />
41
53
 
42
54
  <Canvas withToolbar>
43
55
  <Story
44
- name="Basic with Props"
56
+ name="HelperErrorText with Controls"
45
57
  args={{
58
+ additionalStyles: undefined,
59
+ ariaAtomic: undefined,
46
60
  ariaLive: "polite",
61
+ className: undefined,
62
+ id: "helperErrorText-id",
47
63
  isInvalid: false,
64
+ text: "This is the helper text!",
48
65
  }}
49
66
  >
50
67
  {(args) => (
51
- <HelperErrorText {...args}>
52
- {args.isInvalid
53
- ? "This is the error text :("
54
- : "This is the helper text!"}
55
- </HelperErrorText>
68
+ <HelperErrorText
69
+ {...args}
70
+ text={args.isInvalid ? "This is the error text :(" : args.text}
71
+ />
56
72
  )}
57
73
  </Story>
58
74
  </Canvas>
59
75
 
60
- <ArgsTable story="Basic with Props" />
76
+ <ArgsTable story="HelperErrorText with Controls" />
61
77
 
62
78
  ## With HTML Children
63
79
 
64
- The `HelperErrorText` component can take any React component or HTML element as
65
- its children.
80
+ The `HelperErrorText` component can render any React component or HTML element
81
+ through the `text` prop.
66
82
 
67
83
  <Canvas>
68
84
  <Story name="With HTML Children">
69
- <HelperErrorText>
70
- If you're unsure of your size, please view the{" "}
71
- <a href="#sizing-chart">Sizing Chart</a>.
72
- </HelperErrorText>
85
+ <HelperErrorText
86
+ text={
87
+ <>
88
+ This first example uses an HTML anchor element for{" "}
89
+ <a href="#">a link</a>.
90
+ </>
91
+ }
92
+ />
93
+ <HelperErrorText
94
+ text={
95
+ <Text>
96
+ This second example uses DS components, such as the{" "}
97
+ <Link href="#">`Link`</Link> component, and the `Text` component.
98
+ </Text>
99
+ }
100
+ />
73
101
  </Story>
74
102
  </Canvas>
75
103
 
@@ -80,7 +108,7 @@ NYPL "invalid" styling.
80
108
 
81
109
  <Canvas>
82
110
  <Story name="Invalid State">
83
- <HelperErrorText isInvalid>This is the error text :(</HelperErrorText>
111
+ <HelperErrorText isInvalid text="This is the error text :(" />
84
112
  </Story>
85
113
  </Canvas>
86
114
 
@@ -107,7 +135,7 @@ announced immediately.
107
135
 
108
136
  <Canvas>
109
137
  <Story
110
- name="With Aria Props"
138
+ name="With Aria Controls"
111
139
  args={{
112
140
  ariaAtomic: true,
113
141
  ariaLive: "polite",
@@ -115,10 +143,10 @@ announced immediately.
115
143
  }}
116
144
  >
117
145
  {(args) => (
118
- <HelperErrorText {...args}>
119
- Only invalid text can be read to screen readers with the appropriate
120
- aria-atomic and aria-live props.
121
- </HelperErrorText>
146
+ <HelperErrorText
147
+ {...args}
148
+ text="Only invalid text can be read to screen readers with the appropriate aria-atomic and aria-live props."
149
+ />
122
150
  )}
123
151
  </Story>
124
152
  </Canvas>
@@ -7,45 +7,51 @@ import HelperErrorText from "./HelperErrorText";
7
7
 
8
8
  describe("HelperErrorText Accessibility", () => {
9
9
  it("passes axe accessibility test", async () => {
10
- const { container } = render(<HelperErrorText>Text</HelperErrorText>);
10
+ const { container } = render(<HelperErrorText text="Text" />);
11
11
  expect(await axe(container)).toHaveNoViolations();
12
12
  });
13
13
  });
14
14
 
15
15
  describe("HelperErrorText", () => {
16
16
  it("renders the text passed", () => {
17
- render(<HelperErrorText>Text</HelperErrorText>);
17
+ render(<HelperErrorText text="Text" />);
18
18
  expect(screen.getByText("Text")).toBeInTheDocument();
19
19
  });
20
20
 
21
+ it("renders the text passed as an HTML string", () => {
22
+ render(<HelperErrorText text="<b>This text is bold</b>" />);
23
+ expect(screen.getByText("This text is bold")).toBeInTheDocument();
24
+ });
25
+
26
+ it("renders the text passed as HTML", () => {
27
+ render(<HelperErrorText text={<b>This text is bold</b>} />);
28
+ expect(screen.getByText("This text is bold")).toBeInTheDocument();
29
+ });
30
+
21
31
  it("renders the invalid state", () => {
22
- const utils = render(<HelperErrorText>Text</HelperErrorText>);
32
+ const utils = render(<HelperErrorText text="Text" />);
23
33
 
24
34
  // False by default. Note, this is a custom `data-*` attribute only used
25
35
  // for testing the invalid state.
26
36
  expect(screen.getByText("Text")).toHaveAttribute("data-isinvalid", "false");
27
37
 
28
- utils.rerender(<HelperErrorText isInvalid>Text</HelperErrorText>);
38
+ utils.rerender(<HelperErrorText isInvalid text="Text" />);
29
39
  expect(screen.getByText("Text")).toHaveAttribute("data-isinvalid", "true");
30
40
  });
31
41
 
32
42
  it("has aria-live and aria-atomic attributes when errored", () => {
33
- render(<HelperErrorText isInvalid>Text</HelperErrorText>);
43
+ render(<HelperErrorText isInvalid text="Text" />);
34
44
  expect(screen.getByText("Text")).toHaveAttribute("aria-live", "polite");
35
45
  expect(screen.getByText("Text")).toHaveAttribute("aria-atomic");
36
46
  });
37
47
 
38
48
  it("accepts an aria-atomic value of false", () => {
39
- const utils = render(
40
- <HelperErrorText isInvalid>Static Text</HelperErrorText>
41
- );
49
+ const utils = render(<HelperErrorText isInvalid text="Static Text" />);
42
50
  // The default is "true".
43
51
  expect(screen.getByText("Static Text")).toHaveAttribute("aria-atomic");
44
52
 
45
53
  utils.rerender(
46
- <HelperErrorText ariaAtomic={false} isInvalid>
47
- Static Text
48
- </HelperErrorText>
54
+ <HelperErrorText ariaAtomic={false} isInvalid text="Static Text" />
49
55
  );
50
56
  // But the prop accepts false in case only part of the helper text
51
57
  // should only be read instead of the whole region.
@@ -57,16 +63,37 @@ describe("HelperErrorText", () => {
57
63
 
58
64
  it("Renders the UI snapshot correctly", () => {
59
65
  const basic = renderer
60
- .create(<HelperErrorText id="basic">Text</HelperErrorText>)
66
+ .create(<HelperErrorText id="basic" text="Text" />)
61
67
  .toJSON();
62
68
  const invalid = renderer
69
+ .create(<HelperErrorText id="invalid" isInvalid text="Text" />)
70
+ .toJSON();
71
+ const withHTMLString = renderer
63
72
  .create(
64
- <HelperErrorText id="invalid" isInvalid>
65
- Text
66
- </HelperErrorText>
73
+ <HelperErrorText
74
+ id="invalid"
75
+ isInvalid
76
+ text="This helper text <b>contains HTML in the string</b>."
77
+ />
67
78
  )
68
79
  .toJSON();
80
+ const withHTMLElement = renderer
81
+ .create(
82
+ <HelperErrorText
83
+ id="invalid"
84
+ isInvalid
85
+ text={
86
+ <>
87
+ This helper text <b>contains HTML</b>.
88
+ </>
89
+ }
90
+ />
91
+ )
92
+ .toJSON();
93
+
69
94
  expect(basic).toMatchSnapshot();
70
95
  expect(invalid).toMatchSnapshot();
96
+ expect(withHTMLString).toMatchSnapshot();
97
+ expect(withHTMLElement).toMatchSnapshot();
71
98
  });
72
99
  });
@@ -4,6 +4,7 @@ import { Box, useStyleConfig } from "@chakra-ui/react";
4
4
  import generateUUID from "../../helpers/generateUUID";
5
5
 
6
6
  export type AriaLiveValues = "assertive" | "off" | "polite";
7
+ export type HelperErrorTextType = string | JSX.Element;
7
8
 
8
9
  interface HelperErrorTextProps {
9
10
  /** Optionally pass in additional Chakra-based styles. */
@@ -24,38 +25,37 @@ interface HelperErrorTextProps {
24
25
  id?: string;
25
26
  /** Toggles between helper and invalid styling. */
26
27
  isInvalid?: boolean;
28
+ /** The text to display. */
29
+ text: HelperErrorTextType;
27
30
  }
28
31
 
29
32
  /**
30
33
  * Helper or Error text for forms
31
34
  */
32
- export default function HelperErrorText(
33
- props: React.PropsWithChildren<HelperErrorTextProps>
34
- ) {
35
- const {
36
- additionalStyles = {},
37
- ariaAtomic = true,
38
- ariaLive = "polite",
39
- children,
40
- className = "",
41
- id = generateUUID(),
42
- isInvalid = false,
43
- } = props;
35
+ export default function HelperErrorText({
36
+ additionalStyles = {},
37
+ ariaAtomic = true,
38
+ ariaLive = "polite",
39
+ className = "",
40
+ id = generateUUID(),
41
+ isInvalid = false,
42
+ text,
43
+ }: HelperErrorTextProps) {
44
44
  // Only announce the text in the invalid state.
45
45
  const announceAriaLive = isInvalid;
46
46
  const styles = useStyleConfig("HelperErrorText", { isInvalid });
47
47
  const finalStyles = { ...styles, ...additionalStyles };
48
-
49
- return (
50
- <Box
51
- id={id}
52
- className={className}
53
- aria-atomic={ariaAtomic}
54
- data-isinvalid={isInvalid}
55
- aria-live={announceAriaLive ? ariaLive : "off"}
56
- __css={finalStyles}
57
- >
58
- {children}
59
- </Box>
48
+ const props = {
49
+ "aria-atomic": ariaAtomic,
50
+ "aria-live": announceAriaLive ? ariaLive : "off",
51
+ className,
52
+ "data-isinvalid": isInvalid,
53
+ id,
54
+ __css: finalStyles,
55
+ };
56
+ return typeof text === "string" ? (
57
+ <Box {...props} dangerouslySetInnerHTML={{ __html: text }} />
58
+ ) : (
59
+ <Box {...props}>{text}</Box>
60
60
  );
61
61
  }
@@ -5,14 +5,47 @@ exports[`HelperErrorText Renders the UI snapshot correctly 1`] = `
5
5
  aria-atomic={true}
6
6
  aria-live="off"
7
7
  className=" css-0"
8
+ dangerouslySetInnerHTML={
9
+ Object {
10
+ "__html": "Text",
11
+ }
12
+ }
8
13
  data-isinvalid={false}
9
14
  id="basic"
10
- >
11
- Text
12
- </div>
15
+ />
13
16
  `;
14
17
 
15
18
  exports[`HelperErrorText Renders the UI snapshot correctly 2`] = `
19
+ <div
20
+ aria-atomic={true}
21
+ aria-live="polite"
22
+ className=" css-0"
23
+ dangerouslySetInnerHTML={
24
+ Object {
25
+ "__html": "Text",
26
+ }
27
+ }
28
+ data-isinvalid={true}
29
+ id="invalid"
30
+ />
31
+ `;
32
+
33
+ exports[`HelperErrorText Renders the UI snapshot correctly 3`] = `
34
+ <div
35
+ aria-atomic={true}
36
+ aria-live="polite"
37
+ className=" css-0"
38
+ dangerouslySetInnerHTML={
39
+ Object {
40
+ "__html": "This helper text <b>contains HTML in the string</b>.",
41
+ }
42
+ }
43
+ data-isinvalid={true}
44
+ id="invalid"
45
+ />
46
+ `;
47
+
48
+ exports[`HelperErrorText Renders the UI snapshot correctly 4`] = `
16
49
  <div
17
50
  aria-atomic={true}
18
51
  aria-live="polite"
@@ -20,6 +53,10 @@ exports[`HelperErrorText Renders the UI snapshot correctly 2`] = `
20
53
  data-isinvalid={true}
21
54
  id="invalid"
22
55
  >
23
- Text
56
+ This helper text
57
+ <b>
58
+ contains HTML
59
+ </b>
60
+ .
24
61
  </div>
25
62
  `;