@nypl/design-system-react-components 0.25.12 → 0.25.13

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 (194) hide show
  1. package/CHANGELOG.md +63 -1
  2. package/dist/components/Accordion/Accordion.d.ts +5 -3
  3. package/dist/components/Accordion/AccordionTypes.d.ts +5 -0
  4. package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +3 -3
  5. package/dist/components/Breadcrumbs/BreadcrumbsTypes.d.ts +1 -1
  6. package/dist/components/Card/Card.d.ts +11 -20
  7. package/dist/components/Checkbox/Checkbox.d.ts +1 -1
  8. package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +4 -2
  9. package/dist/components/Heading/Heading.d.ts +4 -4
  10. package/dist/components/Heading/HeadingTypes.d.ts +1 -1
  11. package/dist/components/Hero/Hero.d.ts +7 -4
  12. package/dist/components/Icons/IconTypes.d.ts +1 -0
  13. package/dist/components/Image/Image.d.ts +25 -7
  14. package/dist/components/Image/ImageTypes.d.ts +4 -4
  15. package/dist/components/Logo/LogoTypes.d.ts +2 -2
  16. package/dist/components/Notification/Notification.d.ts +4 -4
  17. package/dist/components/Radio/Radio.d.ts +1 -1
  18. package/dist/components/RadioGroup/RadioGroup.d.ts +4 -2
  19. package/dist/components/Select/Select.d.ts +2 -2
  20. package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +4 -3
  21. package/dist/components/SkeletonLoader/SkeletonLoaderTypes.d.ts +0 -4
  22. package/dist/components/StructuredContent/StructuredContent.d.ts +9 -22
  23. package/dist/components/Tabs/Tabs.d.ts +3 -3
  24. package/dist/components/Template/Template.d.ts +13 -5
  25. package/dist/components/Text/Text.d.ts +3 -3
  26. package/dist/components/Text/TextTypes.d.ts +1 -1
  27. package/dist/components/TextInput/TextInput.d.ts +2 -2
  28. package/dist/components/Toggle/Toggle.d.ts +6 -7
  29. package/dist/components/Toggle/{ToggleSizes.d.ts → ToggleTypes.d.ts} +1 -1
  30. package/dist/design-system-react-components.cjs.development.js +505 -422
  31. package/dist/design-system-react-components.cjs.development.js.map +1 -1
  32. package/dist/design-system-react-components.cjs.production.min.js +1 -1
  33. package/dist/design-system-react-components.cjs.production.min.js.map +1 -1
  34. package/dist/design-system-react-components.esm.js +514 -435
  35. package/dist/design-system-react-components.esm.js.map +1 -1
  36. package/dist/helpers/enums.d.ts +4 -0
  37. package/dist/index.d.ts +7 -8
  38. package/dist/theme/components/accordion.d.ts +7 -12
  39. package/dist/theme/components/breadcrumb.d.ts +3 -0
  40. package/dist/theme/components/card.d.ts +4 -4
  41. package/dist/theme/components/checkbox.d.ts +1 -0
  42. package/dist/theme/components/checkboxGroup.d.ts +3 -1
  43. package/dist/theme/components/global.d.ts +2 -1
  44. package/dist/theme/components/hero.d.ts +1 -1
  45. package/dist/theme/components/image.d.ts +1 -1
  46. package/dist/theme/components/notification.d.ts +4 -4
  47. package/dist/theme/components/pagination.d.ts +2 -5
  48. package/dist/theme/components/radio.d.ts +1 -0
  49. package/dist/theme/components/radioGroup.d.ts +3 -1
  50. package/dist/theme/components/select.d.ts +3 -0
  51. package/dist/theme/components/toggle.d.ts +13 -1
  52. package/package.json +1 -1
  53. package/src/components/AccessibilityGuide/SkipNavigation.stories.mdx +34 -0
  54. package/src/components/Accordion/Accordion.stories.mdx +150 -66
  55. package/src/components/Accordion/Accordion.test.tsx +44 -17
  56. package/src/components/Accordion/Accordion.tsx +50 -20
  57. package/src/components/Accordion/AccordionTypes.tsx +5 -0
  58. package/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap +244 -2
  59. package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +17 -15
  60. package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +6 -6
  61. package/src/components/Breadcrumbs/Breadcrumbs.tsx +6 -6
  62. package/src/components/Breadcrumbs/BreadcrumbsTypes.tsx +1 -1
  63. package/src/components/Card/Card.stories.mdx +236 -165
  64. package/src/components/Card/Card.test.tsx +36 -18
  65. package/src/components/Card/Card.tsx +84 -59
  66. package/src/components/Card/__snapshots__/Card.test.tsx.snap +25 -65
  67. package/src/components/Chakra/Center.stories.mdx +2 -2
  68. package/src/components/Checkbox/Checkbox.stories.mdx +13 -1
  69. package/src/components/Checkbox/Checkbox.test.tsx +58 -2
  70. package/src/components/Checkbox/Checkbox.tsx +6 -1
  71. package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +76 -0
  72. package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +73 -9
  73. package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +79 -9
  74. package/src/components/CheckboxGroup/CheckboxGroup.tsx +10 -7
  75. package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +169 -0
  76. package/src/components/ComponentWrapper/ComponentWrapper.tsx +1 -1
  77. package/src/components/DatePicker/DatePicker.test.tsx +5 -2
  78. package/src/components/DatePicker/DatePicker.tsx +5 -2
  79. package/src/components/Form/Form.stories.mdx +47 -9
  80. package/src/components/Form/Form.test.tsx +1 -1
  81. package/src/components/Form/Form.tsx +3 -1
  82. package/src/components/Grid/SimpleGrid.stories.mdx +53 -35
  83. package/src/components/Grid/SimpleGrid.test.tsx +15 -9
  84. package/src/components/Heading/Heading.stories.mdx +21 -23
  85. package/src/components/Heading/Heading.test.tsx +7 -7
  86. package/src/components/Heading/Heading.tsx +10 -14
  87. package/src/components/Heading/HeadingTypes.tsx +1 -1
  88. package/src/components/Heading/__snapshots__/Heading.test.tsx.snap +1 -1
  89. package/src/components/Hero/Hero.stories.mdx +27 -27
  90. package/src/components/Hero/Hero.test.tsx +113 -58
  91. package/src/components/Hero/Hero.tsx +43 -20
  92. package/src/components/HorizontalRule/HorizontalRule.test.tsx +6 -4
  93. package/src/components/HorizontalRule/HorizontalRule.tsx +3 -2
  94. package/src/components/Icons/Icon.stories.mdx +50 -18
  95. package/src/components/Icons/Icon.test.tsx +13 -2
  96. package/src/components/Icons/Icon.tsx +11 -6
  97. package/src/components/Icons/IconTypes.tsx +1 -0
  98. package/src/components/Image/Image.stories.mdx +133 -68
  99. package/src/components/Image/Image.test.tsx +32 -48
  100. package/src/components/Image/Image.tsx +46 -26
  101. package/src/components/Image/ImageTypes.ts +4 -4
  102. package/src/components/Image/__snapshots__/Image.test.tsx.snap +60 -13
  103. package/src/components/Link/Link.tsx +8 -1
  104. package/src/components/List/List.stories.mdx +1 -1
  105. package/src/components/List/List.test.tsx +7 -4
  106. package/src/components/List/List.tsx +7 -4
  107. package/src/components/Logo/Logo.stories.mdx +13 -13
  108. package/src/components/Logo/Logo.test.tsx +12 -2
  109. package/src/components/Logo/Logo.tsx +10 -5
  110. package/src/components/Logo/LogoTypes.tsx +1 -1
  111. package/src/components/Notification/Notification.stories.mdx +5 -5
  112. package/src/components/Notification/Notification.tsx +10 -10
  113. package/src/components/Pagination/Pagination.stories.mdx +4 -3
  114. package/src/components/Pagination/Pagination.test.tsx +30 -2
  115. package/src/components/Pagination/Pagination.tsx +6 -3
  116. package/src/components/ProgressIndicator/ProgressIndicator.stories.mdx +1 -1
  117. package/src/components/ProgressIndicator/ProgressIndicator.test.tsx +6 -2
  118. package/src/components/ProgressIndicator/ProgressIndicator.tsx +3 -1
  119. package/src/components/Radio/Radio.stories.mdx +13 -1
  120. package/src/components/Radio/Radio.test.tsx +56 -2
  121. package/src/components/Radio/Radio.tsx +6 -1
  122. package/src/components/Radio/__snapshots__/Radio.test.tsx.snap +61 -0
  123. package/src/components/RadioGroup/RadioGroup.stories.mdx +73 -9
  124. package/src/components/RadioGroup/RadioGroup.test.tsx +72 -7
  125. package/src/components/RadioGroup/RadioGroup.tsx +10 -7
  126. package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +140 -0
  127. package/src/components/SearchBar/SearchBar.stories.mdx +1 -1
  128. package/src/components/SearchBar/SearchBar.tsx +3 -3
  129. package/src/components/Select/Select.stories.mdx +26 -16
  130. package/src/components/Select/Select.test.tsx +1 -36
  131. package/src/components/Select/Select.tsx +4 -16
  132. package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +12 -14
  133. package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +6 -8
  134. package/src/components/SkeletonLoader/SkeletonLoader.tsx +5 -7
  135. package/src/components/SkeletonLoader/SkeletonLoaderTypes.tsx +0 -5
  136. package/src/components/Slider/Slider.stories.mdx +41 -8
  137. package/src/components/Slider/Slider.tsx +4 -4
  138. package/src/components/StatusBadge/StatusBadge.test.tsx +3 -1
  139. package/src/components/StatusBadge/StatusBadge.tsx +1 -1
  140. package/src/components/StructuredContent/StructuredContent.stories.mdx +103 -54
  141. package/src/components/StructuredContent/StructuredContent.test.tsx +129 -102
  142. package/src/components/StructuredContent/StructuredContent.tsx +43 -53
  143. package/src/components/StyleGuide/ColorCard.tsx +3 -3
  144. package/src/components/StyleGuide/Typography.stories.mdx +17 -12
  145. package/src/components/Table/Table.test.tsx +1 -1
  146. package/src/components/Table/Table.tsx +3 -1
  147. package/src/components/Tabs/Tabs.stories.mdx +8 -8
  148. package/src/components/Tabs/Tabs.test.tsx +13 -11
  149. package/src/components/Tabs/Tabs.tsx +18 -15
  150. package/src/components/Template/Template.stories.mdx +62 -25
  151. package/src/components/Template/Template.test.tsx +35 -5
  152. package/src/components/Template/Template.tsx +26 -13
  153. package/src/components/Template/__snapshots__/Template.test.tsx.snap +4 -2
  154. package/src/components/Text/Text.stories.mdx +13 -15
  155. package/src/components/Text/Text.test.tsx +6 -15
  156. package/src/components/Text/Text.tsx +7 -12
  157. package/src/components/Text/TextTypes.tsx +1 -1
  158. package/src/components/TextInput/TextInput.stories.mdx +9 -9
  159. package/src/components/TextInput/TextInput.test.tsx +28 -27
  160. package/src/components/TextInput/TextInput.tsx +4 -4
  161. package/src/components/Toggle/Toggle.stories.mdx +12 -22
  162. package/src/components/Toggle/Toggle.test.tsx +15 -2
  163. package/src/components/Toggle/Toggle.tsx +8 -9
  164. package/src/components/Toggle/{ToggleSizes.tsx → ToggleTypes.tsx} +1 -1
  165. package/src/components/Toggle/__snapshots__/Toggle.test.tsx.snap +64 -0
  166. package/src/components/VideoPlayer/VideoPlayer.test.tsx +18 -6
  167. package/src/components/VideoPlayer/VideoPlayer.tsx +14 -7
  168. package/src/docs/{Intro.stories.mdx → Welcome.stories.mdx} +5 -9
  169. package/src/{components/Card/CardTypes.tsx → helpers/enums.ts} +2 -2
  170. package/src/hooks/tests/useNYPLTheme.test.tsx +1 -1
  171. package/src/hooks/useCarouselStyles.stories.mdx +10 -0
  172. package/src/hooks/useNYPLTheme.ts +1 -1
  173. package/src/index.ts +7 -14
  174. package/src/theme/components/accordion.ts +7 -12
  175. package/src/theme/components/breadcrumb.ts +3 -0
  176. package/src/theme/components/card.ts +29 -20
  177. package/src/theme/components/checkboxGroup.ts +3 -1
  178. package/src/theme/components/global.ts +4 -3
  179. package/src/theme/components/hero.ts +1 -1
  180. package/src/theme/components/icon.ts +5 -2
  181. package/src/theme/components/image.ts +1 -1
  182. package/src/theme/components/list.ts +1 -1
  183. package/src/theme/components/notification.ts +5 -5
  184. package/src/theme/components/pagination.ts +2 -5
  185. package/src/theme/components/progressIndicator.ts +3 -3
  186. package/src/theme/components/radioGroup.ts +3 -1
  187. package/src/theme/components/select.ts +6 -0
  188. package/src/theme/components/toggle.ts +26 -3
  189. package/src/utils/componentCategories.ts +27 -19
  190. package/dist/components/Card/CardTypes.d.ts +0 -4
  191. package/dist/components/CheckboxGroup/CheckboxGroupLayoutTypes.d.ts +0 -4
  192. package/dist/components/RadioGroup/RadioGroupLayoutTypes.d.ts +0 -4
  193. package/src/components/CheckboxGroup/CheckboxGroupLayoutTypes.tsx +0 -4
  194. package/src/components/RadioGroup/RadioGroupLayoutTypes.tsx +0 -4
@@ -8,14 +8,11 @@ import {
8
8
  import { withDesign } from "storybook-addon-designs";
9
9
 
10
10
  import Text from "./Text";
11
- import { TextDisplaySizes } from "./TextTypes";
11
+ import { TextSizes } from "./TextTypes";
12
12
  import { getCategory } from "../../utils/componentCategories";
13
13
  import { getStorybookEnumValues } from "../../utils/utils";
14
14
 
15
- export const enumValues = getStorybookEnumValues(
16
- TextDisplaySizes,
17
- "TextDisplaySizes"
18
- );
15
+ export const enumValues = getStorybookEnumValues(TextSizes, "TextSizes");
19
16
 
20
17
  <Meta
21
18
  title={getCategory("Text")}
@@ -29,14 +26,14 @@ export const enumValues = getStorybookEnumValues(
29
26
  }}
30
27
  argTypes={{
31
28
  className: { control: false },
32
- displaySize: {
33
- control: { type: "select" },
34
- options: enumValues.options,
35
- table: { defaultValue: { summary: "TextDisplaySizes.Default" } },
36
- },
37
29
  isBold: { table: { defaultValue: { summary: false } } },
38
30
  isItalic: { table: { defaultValue: { summary: false } } },
39
31
  noSpace: { table: { defaultValue: { summary: false } } },
32
+ size: {
33
+ control: { type: "select" },
34
+ options: enumValues.options,
35
+ table: { defaultValue: { summary: "TextSizes.Default" } },
36
+ },
40
37
  }}
41
38
  />
42
39
 
@@ -45,18 +42,19 @@ export const enumValues = getStorybookEnumValues(
45
42
  | Component Version | DS Version |
46
43
  | ----------------- | ---------- |
47
44
  | Added | `0.25.1` |
48
- | Latest | `0.25.1` |
45
+ | Latest | `0.25.13` |
49
46
 
50
47
  <Description of={Text} />
51
48
 
52
- The `Text` component renders a basic `<p>` element. As its name indicates, the `displaySize` prop controls the size of the text rendered in the component.
49
+ The `Text` component renders a basic `<p>` element. As its name indicates, the
50
+ `size` prop controls the size of the text rendered in the component.
53
51
 
54
52
  <Canvas withToolbar>
55
53
  <Story
56
54
  name="Text"
57
55
  args={{
58
56
  className: undefined,
59
- displaySize: "TextDisplaySizes.Default",
57
+ size: "TextSizes.Default",
60
58
  isBold: false,
61
59
  isItalic: false,
62
60
  noSpace: false,
@@ -64,7 +62,7 @@ The `Text` component renders a basic `<p>` element. As its name indicates, the `
64
62
  >
65
63
  {(args) => (
66
64
  <>
67
- <Text {...args} displaySize={enumValues.getValue(args.displaySize)}>
65
+ <Text {...args} size={enumValues.getValue(args.size)}>
68
66
  Animal Crossing[a] is a social simulation video game series developed
69
67
  and published by Nintendo. The series was conceptualized and created
70
68
  by Katsuya Eguchi and Hisashi Nogami. In Animal Crossing, the player
@@ -74,7 +72,7 @@ The `Text` component renders a basic `<p>` element. As its name indicates, the `
74
72
  open-ended gameplay and use of the video game console's internal clock
75
73
  and calendar to simulate real passage of time.
76
74
  </Text>
77
- <Text {...args} displaySize={enumValues.getValue(args.displaySize)}>
75
+ <Text {...args} size={enumValues.getValue(args.size)}>
78
76
  Since its initial release in 2001, five Animal Crossing games have
79
77
  been released worldwide, one each for the Nintendo 64/iQue Player
80
78
  (enhanced and reissued for the GameCube), Nintendo DS, Wii, Nintendo
@@ -4,7 +4,7 @@ import { axe } from "jest-axe";
4
4
  import renderer from "react-test-renderer";
5
5
 
6
6
  import Text from "./Text";
7
- import { TextDisplaySizes } from "./TextTypes";
7
+ import { TextSizes } from "./TextTypes";
8
8
 
9
9
  describe("Text Accessibility", () => {
10
10
  it("passes axe accessibility test", async () => {
@@ -25,7 +25,8 @@ describe("Text", () => {
25
25
  const warn = jest.spyOn(console, "warn");
26
26
  render(<Text></Text>);
27
27
  expect(warn).toHaveBeenCalledWith(
28
- "The Text component has no children and will not render correctly."
28
+ "NYPL Reservoir Text: No children were passed and the `Text` component " +
29
+ "will not render correctly."
29
30
  );
30
31
  });
31
32
 
@@ -35,24 +36,14 @@ describe("Text", () => {
35
36
  .toJSON();
36
37
  const caption = renderer
37
38
  .create(
38
- <Text displaySize={TextDisplaySizes.Caption}>
39
- Animal Crossing is all that!
40
- </Text>
39
+ <Text size={TextSizes.Caption}>Animal Crossing is all that!</Text>
41
40
  )
42
41
  .toJSON();
43
42
  const tag = renderer
44
- .create(
45
- <Text displaySize={TextDisplaySizes.Tag}>
46
- Animal Crossing is all that!
47
- </Text>
48
- )
43
+ .create(<Text size={TextSizes.Tag}>Animal Crossing is all that!</Text>)
49
44
  .toJSON();
50
45
  const mini = renderer
51
- .create(
52
- <Text displaySize={TextDisplaySizes.Mini}>
53
- Animal Crossing is all that!
54
- </Text>
55
- )
46
+ .create(<Text size={TextSizes.Mini}>Animal Crossing is all that!</Text>)
56
47
  .toJSON();
57
48
 
58
49
  expect(defaultText).toMatchSnapshot();
@@ -1,37 +1,31 @@
1
1
  import * as React from "react";
2
2
  import { Text as ChakraText, useStyleConfig } from "@chakra-ui/react";
3
- import { TextDisplaySizes } from "./TextTypes";
3
+ import { TextSizes } from "./TextTypes";
4
4
  import { getVariant } from "../../utils/utils";
5
5
 
6
6
  export interface TextProps {
7
7
  /** Additional class name to render in the `Text` component. */
8
8
  className?: string;
9
- /** Optional prop to control the text styling */
10
- displaySize?: TextDisplaySizes;
11
9
  /** Optional prop used to show bolded text */
12
10
  isBold?: boolean;
13
11
  /** Optional prop used to show itlicized text */
14
12
  isItalic?: boolean;
15
13
  /** Optional prop used to remove default spacing */
16
14
  noSpace?: boolean;
15
+ /** Optional prop to control the text styling */
16
+ size?: TextSizes;
17
17
  }
18
18
 
19
19
  function Text(props: React.PropsWithChildren<TextProps>) {
20
20
  const {
21
21
  children,
22
22
  className = "",
23
- displaySize = TextDisplaySizes.Default,
24
23
  isBold,
25
24
  isItalic,
26
25
  noSpace,
26
+ size = TextSizes.Default,
27
27
  } = props;
28
-
29
- let variant = getVariant(
30
- displaySize,
31
- TextDisplaySizes,
32
- TextDisplaySizes.Default
33
- );
34
-
28
+ const variant = getVariant(size, TextSizes, TextSizes.Default);
35
29
  const styles = useStyleConfig("Text", {
36
30
  variant,
37
31
  isBold,
@@ -41,7 +35,8 @@ function Text(props: React.PropsWithChildren<TextProps>) {
41
35
 
42
36
  if (!children) {
43
37
  console.warn(
44
- "The Text component has no children and will not render correctly."
38
+ "NYPL Reservoir Text: No children were passed and the `Text` component " +
39
+ "will not render correctly."
45
40
  );
46
41
  }
47
42
 
@@ -1,4 +1,4 @@
1
- export enum TextDisplaySizes {
1
+ export enum TextSizes {
2
2
  Default = "default",
3
3
  Caption = "caption",
4
4
  Tag = "tag",
@@ -43,16 +43,16 @@ export const enumValues = getStorybookEnumValues(
43
43
  showLabel: { table: { defaultValue: { summary: true } } },
44
44
  showOptReqLabel: { table: { defaultValue: { summary: true } } },
45
45
  step: { table: { defaultValue: { summary: 1 } } },
46
+ textInputType: {
47
+ control: false,
48
+ table: { defaultValue: { summary: "TextInputVariants.Default" } },
49
+ },
46
50
  type: {
47
51
  control: { type: "select" },
48
52
  table: { defaultValue: { summary: "TextInputTypes.text" } },
49
53
  options: enumValues.options,
50
54
  },
51
55
  value: { control: false },
52
- variantType: {
53
- control: false,
54
- table: { defaultValue: { summary: "TextInputVariants.Default" } },
55
- },
56
56
  }}
57
57
  />
58
58
 
@@ -61,7 +61,7 @@ export const enumValues = getStorybookEnumValues(
61
61
  | Component Version | DS Version |
62
62
  | ----------------- | ---------- |
63
63
  | Added | `0.22.0` |
64
- | Latest | `0.25.11` |
64
+ | Latest | `0.25.13` |
65
65
 
66
66
  <Description of={TextInput} />
67
67
 
@@ -95,7 +95,7 @@ is left blank, a value will be generated for you.
95
95
  step: 1,
96
96
  type: "TextInputTypes.text",
97
97
  value: undefined,
98
- variantType: TextInputVariants.Default,
98
+ textInputType: TextInputVariants.Default,
99
99
  }}
100
100
  >
101
101
  {(args) => <TextInput {...args} type={enumValues.getValue(args.type)} />}
@@ -206,8 +206,8 @@ helperText={<>Choose <b>wisely!</b></>}
206
206
  ## Textarea
207
207
 
208
208
  The TextInput component includes a multiline `textarea` form field. To render a
209
- `textarea` element, pass `TextInputTypes.textarea` for the `type` prop. All the
210
- variations described above are available for the `textarea` option.
209
+ `textarea` element, pass `TextInputTypes.textarea` for the `type` prop.
210
+ All the variations described above are available for the `textarea` option.
211
211
 
212
212
  <Canvas withToolbar>
213
213
  <Story
@@ -226,7 +226,7 @@ variations described above are available for the `textarea` option.
226
226
  }}
227
227
  argTypes={{
228
228
  type: { control: false },
229
- variantType: { control: false },
229
+ textInputType: { control: false },
230
230
  }}
231
231
  >
232
232
  {(args) => <TextInput {...args} />}
@@ -12,11 +12,11 @@ describe("TextInput Accessibility", () => {
12
12
  it("passes axe accessibility test for the input element", async () => {
13
13
  const { container } = render(
14
14
  <TextInput
15
- labelText="Custom input label"
16
15
  isRequired
16
+ labelText="Custom input label"
17
+ onChange={jest.fn()}
17
18
  placeholder="Input Placeholder"
18
19
  type={TextInputTypes.text}
19
- onChange={jest.fn()}
20
20
  />
21
21
  );
22
22
  expect(await axe(container)).toHaveNoViolations();
@@ -25,11 +25,11 @@ describe("TextInput Accessibility", () => {
25
25
  it("passes axe accessibility test for the textarea element", async () => {
26
26
  const { container } = render(
27
27
  <TextInput
28
- labelText="Custom textarea label"
29
28
  isRequired
29
+ labelText="Custom textarea label"
30
+ onChange={jest.fn()}
30
31
  placeholder="Input Placeholder"
31
32
  type={TextInputTypes.textarea}
32
- onChange={jest.fn()}
33
33
  />
34
34
  );
35
35
  expect(await axe(container)).toHaveNoViolations();
@@ -46,13 +46,13 @@ describe("TextInput", () => {
46
46
  changeHandler = jest.fn();
47
47
  utils = render(
48
48
  <TextInput
49
+ attributes={{ onFocus: focusHandler }}
49
50
  id="myTextInput"
50
- labelText="Custom Input Label"
51
51
  isRequired
52
+ labelText="Custom Input Label"
53
+ onChange={changeHandler}
52
54
  placeholder="Input Placeholder"
53
55
  type={TextInputTypes.text}
54
- attributes={{ onFocus: focusHandler }}
55
- onChange={changeHandler}
56
56
  />
57
57
  );
58
58
  });
@@ -73,13 +73,13 @@ describe("TextInput", () => {
73
73
  it("renders 'Optional' along with the label text", () => {
74
74
  utils.rerender(
75
75
  <TextInput
76
+ attributes={{ onFocus: focusHandler }}
76
77
  id="myTextInput"
77
- labelText="Custom Input Label"
78
78
  isRequired={false}
79
+ labelText="Custom Input Label"
80
+ onChange={changeHandler}
79
81
  placeholder="Input Placeholder"
80
82
  type={TextInputTypes.text}
81
- attributes={{ onFocus: focusHandler }}
82
- onChange={changeHandler}
83
83
  />
84
84
  );
85
85
 
@@ -90,14 +90,14 @@ describe("TextInput", () => {
90
90
  it("does not render 'Required' along with the label text", () => {
91
91
  utils.rerender(
92
92
  <TextInput
93
+ attributes={{ onFocus: focusHandler }}
93
94
  id="myTextInput"
94
- labelText="Custom Input Label"
95
95
  isRequired
96
- showOptReqLabel={false}
96
+ labelText="Custom Input Label"
97
+ onChange={changeHandler}
97
98
  placeholder="Input Placeholder"
99
+ showOptReqLabel={false}
98
100
  type={TextInputTypes.text}
99
- attributes={{ onFocus: focusHandler }}
100
- onChange={changeHandler}
101
101
  />
102
102
  );
103
103
 
@@ -145,11 +145,11 @@ describe("Renders TextInput with auto-generated ID, hidden label and visible hel
145
145
  generateUUIDSpy = jest.spyOn(generateUUID, "default");
146
146
  render(
147
147
  <TextInput
148
- labelText="Custom Input Label"
149
- showLabel={false}
150
148
  helperText="Custom Helper Text"
151
149
  isRequired
150
+ labelText="Custom Input Label"
152
151
  placeholder="Input Placeholder"
152
+ showLabel={false}
153
153
  type={TextInputTypes.text}
154
154
  />
155
155
  );
@@ -185,12 +185,12 @@ describe("TextInput shows error state", () => {
185
185
  beforeEach(() => {
186
186
  const utils = render(
187
187
  <TextInput
188
- id="myTextInputError"
189
- labelText="Custom Input Label"
190
188
  helperText="Custom Helper Text"
189
+ id="myTextInputError"
191
190
  invalidText="Custom Error Text"
192
- placeholder="Input Placeholder"
193
191
  isInvalid
192
+ labelText="Custom Input Label"
193
+ placeholder="Input Placeholder"
194
194
  type={TextInputTypes.text}
195
195
  />
196
196
  );
@@ -214,14 +214,14 @@ describe("TextInput shows error state", () => {
214
214
  it("does not render the invalid text when 'showHelperInvalidText' is set to false", () => {
215
215
  rerender(
216
216
  <TextInput
217
- id="myTextInputError"
218
- labelText="Custom Input Label"
219
217
  helperText="Custom Helper Text"
218
+ id="myTextInputError"
220
219
  invalidText="Custom Error Text"
220
+ isInvalid
221
+ labelText="Custom Input Label"
221
222
  placeholder="Input Placeholder"
222
223
  showHelperInvalidText={false}
223
224
  type={TextInputTypes.text}
224
- isInvalid
225
225
  />
226
226
  );
227
227
  expect(screen.queryByText("Custom Helper Text")).not.toBeInTheDocument();
@@ -241,16 +241,16 @@ describe("Renders HTML attributes passed through the `attributes` prop", () => {
241
241
  beforeEach(() => {
242
242
  render(
243
243
  <TextInput
244
- id="inputID-attributes"
245
- labelText="Input Label"
246
- placeholder="Input Placeholder"
247
- type={TextInputTypes.text}
248
244
  attributes={{
249
245
  onChange: onChangeSpy,
250
246
  onBlur: onBlurSpy,
251
247
  maxLength: 10,
252
248
  tabIndex: 0,
253
249
  }}
250
+ id="inputID-attributes"
251
+ labelText="Input Label"
252
+ placeholder="Input Placeholder"
253
+ type={TextInputTypes.text}
254
254
  />
255
255
  );
256
256
  });
@@ -336,9 +336,9 @@ describe("Hidden input", () => {
336
336
  it("does not show the helper text", () => {
337
337
  render(
338
338
  <TextInput
339
+ helperText="Helper Text"
339
340
  id="inputID-hidden"
340
341
  labelText="Hidden Input Label"
341
- helperText="Helper Text"
342
342
  type={TextInputTypes.hidden}
343
343
  value="hidden"
344
344
  />
@@ -449,6 +449,7 @@ describe("UI Snapshots", () => {
449
449
  expect(errorState).toMatchSnapshot();
450
450
  expect(disabledState).toMatchSnapshot();
451
451
  });
452
+
452
453
  it("renders the textarea UI snapshot correctly", () => {
453
454
  const basicTextarea = renderer
454
455
  .create(
@@ -61,12 +61,12 @@ export interface InputProps {
61
61
  showOptReqLabel?: boolean;
62
62
  /** The amount to increase or decrease when using the number type. */
63
63
  step?: number;
64
+ /** FOR INTERNAL DS USE ONLY: the input variant to display. */
65
+ textInputType?: TextInputVariants;
64
66
  /** HTML Input types as defined by MDN: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input */
65
67
  type?: TextInputTypes;
66
68
  /** Populates the value of the input/textarea elements */
67
69
  value?: string;
68
- /** FOR INTERNAL DS USE ONLY: the input variant to display. */
69
- variantType?: TextInputVariants;
70
70
  }
71
71
 
72
72
  /**
@@ -101,11 +101,11 @@ const TextInput = React.forwardRef<TextInputRefType, InputProps>(
101
101
  showLabel = true,
102
102
  showOptReqLabel = true,
103
103
  step = 1,
104
+ textInputType = TextInputVariants.Default,
104
105
  type = TextInputTypes.text,
105
106
  value,
106
- variantType = TextInputVariants.Default,
107
107
  } = props;
108
- const styles = useMultiStyleConfig("TextInput", { variant: variantType });
108
+ const styles = useMultiStyleConfig("TextInput", { variant: textInputType });
109
109
  const finalStyles = { ...styles, ...additionalStyles };
110
110
  const isTextArea = type === TextInputTypes.textarea;
111
111
  const isHidden = type === TextInputTypes.hidden;
@@ -11,7 +11,7 @@ import { withDesign } from "storybook-addon-designs";
11
11
  import Heading from "../Heading/Heading";
12
12
  import SimpleGrid from "../Grid/SimpleGrid";
13
13
  import Toggle from "./Toggle";
14
- import { ToggleSizes } from "./ToggleSizes";
14
+ import { ToggleSizes } from "./ToggleTypes";
15
15
  import { getCategory } from "../../utils/componentCategories";
16
16
  import DSProvider from "../../theme/provider";
17
17
  import { getStorybookEnumValues } from "../../utils/utils";
@@ -43,7 +43,7 @@ export const sizeEnumValues = getStorybookEnumValues(
43
43
  size: {
44
44
  control: {
45
45
  type: "select",
46
- table: { defaultValue: { summary: "ToggleSizes.Large" } },
46
+ table: { defaultValue: { summary: "ToggleSizes.Default" } },
47
47
  options: sizeEnumValues.options,
48
48
  },
49
49
  },
@@ -55,7 +55,7 @@ export const sizeEnumValues = getStorybookEnumValues(
55
55
  | Component Version | DS Version |
56
56
  | ----------------- | ---------- |
57
57
  | Added | `0.25.8` |
58
- | Latest | `0.25.12` |
58
+ | Latest | `0.25.13` |
59
59
 
60
60
  <Description of={Toggle} />
61
61
 
@@ -98,9 +98,9 @@ The Toggle component label should clarify the action being performed. Labels sho
98
98
  <DSProvider>
99
99
  <SimpleGrid columns="2">
100
100
  <VStack align="left" spacing="s">
101
- <Heading level={3}>Large</Heading>
102
- <Toggle size={ToggleSizes.Large} defaultChecked={true} labelText="On" />
103
- <Toggle size={ToggleSizes.Large} labelText="Off" />
101
+ <Heading level={3}>Default</Heading>
102
+ <Toggle defaultChecked={true} labelText="On" />
103
+ <Toggle labelText="Off" />
104
104
  </VStack>
105
105
  <VStack align="left" spacing="s">
106
106
  <Heading level={3}>Small</Heading>
@@ -147,28 +147,18 @@ const onChange = (e) => {
147
147
  <SimpleGrid columns="3">
148
148
  <VStack align="left" spacing="s">
149
149
  <Heading level={3}>Default</Heading>
150
- <Toggle size={ToggleSizes.Large} defaultChecked={true} labelText="On" />
151
- <Toggle size={ToggleSizes.Large} labelText="Off" />
150
+ <Toggle defaultChecked={true} labelText="On" />
151
+ <Toggle labelText="Off" />
152
152
  </VStack>
153
153
  <VStack align="left" spacing="s">
154
154
  <Heading level={3}>Disabled</Heading>
155
- <Toggle
156
- size={ToggleSizes.Large}
157
- defaultChecked={true}
158
- isDisabled={true}
159
- labelText="On"
160
- />
161
- <Toggle size={ToggleSizes.Large} labelText="Off" isDisabled={true} />
155
+ <Toggle defaultChecked={true} isDisabled={true} labelText="On" />
156
+ <Toggle labelText="Off" isDisabled={true} />
162
157
  </VStack>
163
158
  <VStack align="left" spacing="s">
164
159
  <Heading level={3}>Error</Heading>
165
- <Toggle
166
- size={ToggleSizes.Large}
167
- defaultChecked={true}
168
- labelText="On"
169
- isInvalid={true}
170
- />
171
- <Toggle size={ToggleSizes.Large} labelText="Off" isInvalid={true} />
160
+ <Toggle defaultChecked={true} labelText="On" isInvalid={true} />
161
+ <Toggle labelText="Off" isInvalid={true} />
172
162
  </VStack>
173
163
  </SimpleGrid>
174
164
  </DSProvider>
@@ -1,10 +1,12 @@
1
- import * as React from "react";
2
1
  import { render, screen } from "@testing-library/react";
3
2
  import userEvent from "@testing-library/user-event";
4
3
  import { axe } from "jest-axe";
4
+ import * as React from "react";
5
5
  import renderer from "react-test-renderer";
6
- import * as generateUUID from "../../helpers/generateUUID";
6
+
7
7
  import Toggle from "./Toggle";
8
+ import { ToggleSizes } from "./ToggleTypes";
9
+ import * as generateUUID from "../../helpers/generateUUID";
8
10
 
9
11
  describe("Toggle Accessibility", () => {
10
12
  it("Passes axe accessibility test", async () => {
@@ -131,10 +133,21 @@ describe("Toggle", () => {
131
133
  const isDisabled = renderer
132
134
  .create(<Toggle id="Toggle-disabled" labelText="Test Label" isDisabled />)
133
135
  .toJSON();
136
+ const small = renderer
137
+ .create(
138
+ <Toggle
139
+ id="Toggle-disabled"
140
+ labelText="Test Label"
141
+ isDisabled
142
+ size={ToggleSizes.Small}
143
+ />
144
+ )
145
+ .toJSON();
134
146
 
135
147
  expect(primary).toMatchSnapshot();
136
148
  expect(isChecked).toMatchSnapshot();
137
149
  expect(isInvalid).toMatchSnapshot();
138
150
  expect(isDisabled).toMatchSnapshot();
151
+ expect(small).toMatchSnapshot();
139
152
  });
140
153
  });
@@ -9,7 +9,7 @@ import * as React from "react";
9
9
  import HelperErrorText, {
10
10
  HelperErrorTextType,
11
11
  } from "../HelperErrorText/HelperErrorText";
12
- import { ToggleSizes } from "./ToggleSizes";
12
+ import { ToggleSizes } from "./ToggleTypes";
13
13
  import generateUUID from "../../helpers/generateUUID";
14
14
 
15
15
  export interface ToggleProps {
@@ -33,20 +33,19 @@ export interface ToggleProps {
33
33
  /** Adds the 'disabled' and `aria-disabled` attributes to the input when true.
34
34
  * This also makes the text italic and color scheme gray. */
35
35
  isDisabled?: boolean;
36
- /** Adds the 'aria-invalid' attribute to the input when true. This also makes
37
- * the color theme "NYPL error" red for the button and text. */
36
+ /** Adds the 'aria-invalid' attribute to the input when true. */
38
37
  isInvalid?: boolean;
39
38
  /** Adds the 'required' attribute to the input when true. */
40
39
  isRequired?: boolean;
41
- /** The checkbox's label. This will serve as the text content for a `<label>`
40
+ /** The toggle's label. This will serve as the text content for a `<label>`
42
41
  * element if `showlabel` is true, or an "aria-label" if `showLabel` is false. */
43
42
  labelText: string;
44
- /** The name prop indicates into which group of checkboxes this checkbox
45
- * belongs. If none is specified, 'default' will be used */
43
+ /** The name prop indicates the `Toggle`'s form element name. If none is
44
+ * specified, 'default' will be used. */
46
45
  name?: string;
47
46
  /** The action to perform on the `<input>`'s onChange function */
48
47
  onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
49
- /** Offers the ability to hide the helper/invalid text. */
48
+ /** The size of the Toggle. Defaults to "large". */
50
49
  size?: ToggleSizes;
51
50
  }
52
51
 
@@ -72,7 +71,7 @@ const Toggle = React.forwardRef<HTMLInputElement, ToggleProps>(
72
71
  labelText,
73
72
  name,
74
73
  onChange = onChangeDefault,
75
- size = ToggleSizes.Large,
74
+ size = ToggleSizes.Default,
76
75
  } = props;
77
76
  const footnote: HelperErrorTextType = isInvalid ? invalidText : helperText;
78
77
  const ariaAttributes = {};
@@ -91,7 +90,7 @@ const Toggle = React.forwardRef<HTMLInputElement, ToggleProps>(
91
90
  isInvalid={isInvalid}
92
91
  isRequired={isRequired}
93
92
  ref={ref}
94
- size={size === ToggleSizes.Large ? "lg" : "sm"}
93
+ size={size === ToggleSizes.Default ? "lg" : "sm"}
95
94
  lineHeight="1.5"
96
95
  {...(isChecked !== undefined
97
96
  ? {
@@ -1,4 +1,4 @@
1
1
  export enum ToggleSizes {
2
- Large = "large",
2
+ Default = "default",
3
3
  Small = "small",
4
4
  }
@@ -253,3 +253,67 @@ exports[`Toggle Renders the UI snapshot correctly 4`] = `
253
253
  </label>
254
254
  </div>
255
255
  `;
256
+
257
+ exports[`Toggle Renders the UI snapshot correctly 5`] = `
258
+ <div
259
+ className="css-0"
260
+ >
261
+ <label
262
+ className="chakra-switch css-18x0has"
263
+ data-disabled=""
264
+ onClick={[Function]}
265
+ >
266
+ <input
267
+ aria-disabled={true}
268
+ aria-invalid={false}
269
+ aria-label="Test Label"
270
+ checked={false}
271
+ className="chakra-switch__input"
272
+ disabled={true}
273
+ id="Toggle-disabled"
274
+ name="default"
275
+ onBlur={[Function]}
276
+ onChange={[Function]}
277
+ onFocus={[Function]}
278
+ onKeyDown={[Function]}
279
+ onKeyUp={[Function]}
280
+ required={false}
281
+ style={
282
+ Object {
283
+ "border": "0px",
284
+ "clip": "rect(0px, 0px, 0px, 0px)",
285
+ "height": "1px",
286
+ "margin": "-1px",
287
+ "overflow": "hidden",
288
+ "padding": "0px",
289
+ "position": "absolute",
290
+ "whiteSpace": "nowrap",
291
+ "width": "1px",
292
+ }
293
+ }
294
+ type="checkbox"
295
+ />
296
+ <span
297
+ aria-hidden={true}
298
+ className="chakra-switch__track css-14qxnv8"
299
+ data-disabled=""
300
+ onMouseDown={[Function]}
301
+ onMouseEnter={[Function]}
302
+ onMouseLeave={[Function]}
303
+ onMouseUp={[Function]}
304
+ >
305
+ <span
306
+ className="chakra-switch__thumb css-0"
307
+ />
308
+ </span>
309
+ <span
310
+ className="chakra-switch__label css-1y8kf23"
311
+ data-disabled=""
312
+ onMouseDown={[Function]}
313
+ onTouchStart={[Function]}
314
+ >
315
+ Test Label
316
+ </span>
317
+ </label>
318
+ </div>
319
+ `;