@nypl/design-system-react-components 0.25.13 → 0.27.0
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.
- package/CHANGELOG.md +85 -0
- package/README.md +10 -10
- package/dist/components/Accordion/Accordion.d.ts +1 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +1 -1
- package/dist/components/Button/Button.d.ts +2 -2
- package/dist/components/Card/Card.d.ts +11 -9
- package/dist/components/Checkbox/Checkbox.d.ts +2 -2
- package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +5 -4
- package/dist/components/ComponentWrapper/ComponentWrapper.d.ts +1 -1
- package/dist/components/DatePicker/DatePicker.d.ts +5 -6
- package/dist/components/Fieldset/Fieldset.d.ts +5 -6
- package/dist/components/Form/Form.d.ts +6 -6
- package/dist/components/Grid/GridTypes.d.ts +7 -7
- package/dist/components/Grid/SimpleGrid.d.ts +1 -1
- package/dist/components/Heading/Heading.d.ts +1 -1
- package/dist/components/HelperErrorText/HelperErrorText.d.ts +9 -8
- package/dist/components/Hero/Hero.d.ts +2 -1
- package/dist/components/HorizontalRule/HorizontalRule.d.ts +2 -10
- package/dist/components/Icons/Icon.d.ts +2 -1
- package/dist/components/Image/Image.d.ts +2 -2
- package/dist/components/Label/Label.d.ts +7 -4
- package/dist/components/Link/Link.d.ts +1 -1
- package/dist/components/List/List.d.ts +11 -11
- package/dist/components/List/ListTypes.d.ts +1 -1
- package/dist/components/Logo/Logo.d.ts +2 -1
- package/dist/components/Logo/LogoSvgs.d.ts +2 -0
- package/dist/components/Logo/LogoTypes.d.ts +2 -0
- package/dist/components/Modal/Modal.d.ts +28 -8
- package/dist/components/Notification/Notification.d.ts +4 -4
- package/dist/components/Pagination/Pagination.d.ts +2 -2
- package/dist/components/ProgressIndicator/ProgressIndicator.d.ts +3 -3
- package/dist/components/Radio/Radio.d.ts +4 -6
- package/dist/components/RadioGroup/RadioGroup.d.ts +12 -6
- package/dist/components/SearchBar/SearchBar.d.ts +4 -4
- package/dist/components/Select/Select.d.ts +10 -6
- package/dist/components/Select/SelectTypes.d.ts +4 -0
- package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +4 -3
- package/dist/components/Slider/Slider.d.ts +6 -4
- package/dist/components/StatusBadge/StatusBadge.d.ts +5 -1
- package/dist/components/StructuredContent/StructuredContent.d.ts +2 -2
- package/dist/components/Table/Table.d.ts +1 -1
- package/dist/components/Tabs/Tabs.d.ts +4 -3
- package/dist/components/Template/Template.d.ts +4 -3
- package/dist/components/Text/Text.d.ts +1 -1
- package/dist/components/TextInput/TextInput.d.ts +5 -5
- package/dist/components/Toggle/Toggle.d.ts +3 -4
- package/dist/components/VideoPlayer/VideoPlayer.d.ts +2 -1
- package/dist/design-system-react-components.cjs.development.js +1767 -1180
- package/dist/design-system-react-components.cjs.development.js.map +1 -1
- package/dist/design-system-react-components.cjs.production.min.js +1 -1
- package/dist/design-system-react-components.cjs.production.min.js.map +1 -1
- package/dist/design-system-react-components.esm.js +1774 -1188
- package/dist/design-system-react-components.esm.js.map +1 -1
- package/dist/hooks/useCarouselStyles.d.ts +3 -2
- package/dist/hooks/useNYPLTheme.d.ts +12 -0
- package/dist/index.d.ts +5 -2
- package/dist/styles.css +1 -1
- package/dist/theme/components/button.d.ts +10 -2
- package/dist/theme/components/card.d.ts +42 -22
- package/dist/theme/components/checkbox.d.ts +5 -4
- package/dist/theme/components/checkboxGroup.d.ts +1 -1
- package/dist/theme/components/componentWrapper.d.ts +2 -2
- package/dist/theme/components/customTable.d.ts +84 -1
- package/dist/theme/components/fieldset.d.ts +4 -14
- package/dist/theme/components/global.d.ts +23 -17
- package/dist/theme/components/heading.d.ts +53 -0
- package/dist/theme/components/helperErrorText.d.ts +1 -0
- package/dist/theme/components/hero.d.ts +20 -14
- package/dist/theme/components/label.d.ts +9 -10
- package/dist/theme/components/list.d.ts +99 -9
- package/dist/theme/components/radio.d.ts +6 -4
- package/dist/theme/components/radioGroup.d.ts +1 -1
- package/dist/theme/components/select.d.ts +28 -5
- package/dist/theme/components/skeletonLoader.d.ts +2 -2
- package/dist/theme/components/slider.d.ts +6 -3
- package/dist/theme/components/structuredContent.d.ts +197 -0
- package/dist/theme/components/textInput.d.ts +18 -6
- package/dist/theme/components/toggle.d.ts +7 -4
- package/dist/theme/foundations/global.d.ts +2 -0
- package/dist/theme/foundations/radii.d.ts +1 -0
- package/dist/theme/foundations/spacing.d.ts +46 -43
- package/package.json +17 -19
- package/src/components/Accordion/Accordion.stories.mdx +9 -9
- package/src/components/Accordion/Accordion.test.tsx +21 -0
- package/src/components/Accordion/Accordion.tsx +13 -9
- package/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap +276 -27
- package/src/components/Autosuggest/Autosuggest.stories.mdx +4 -3
- package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +21 -5
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +52 -31
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +8 -7
- package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +211 -12
- package/src/components/Button/Button.stories.mdx +87 -23
- package/src/components/Button/Button.test.tsx +25 -0
- package/src/components/Button/Button.tsx +18 -7
- package/src/components/Button/__snapshots__/Button.test.tsx.snap +27 -7
- package/src/components/Card/Card.stories.mdx +287 -194
- package/src/components/Card/Card.test.tsx +102 -0
- package/src/components/Card/Card.tsx +73 -32
- package/src/components/Card/__snapshots__/Card.test.tsx.snap +196 -36
- package/src/components/Chakra/Grid.stories.mdx +4 -4
- package/src/components/Checkbox/Checkbox.stories.mdx +62 -10
- package/src/components/Checkbox/Checkbox.test.tsx +32 -9
- package/src/components/Checkbox/Checkbox.tsx +20 -15
- package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +134 -7
- package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +65 -17
- package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +137 -81
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +31 -21
- package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +332 -97
- package/src/components/ComponentWrapper/ComponentWrapper.test.tsx +12 -0
- package/src/components/ComponentWrapper/ComponentWrapper.tsx +39 -41
- package/src/components/ComponentWrapper/__snapshots__/ComponentWrapper.test.tsx.snap +47 -34
- package/src/components/DatePicker/DatePicker.stories.mdx +63 -27
- package/src/components/DatePicker/DatePicker.test.tsx +89 -13
- package/src/components/DatePicker/DatePicker.tsx +62 -56
- package/src/components/DatePicker/_DatePicker.scss +71 -13
- package/src/components/DatePicker/__snapshots__/DatePicker.test.tsx.snap +250 -206
- package/src/components/Fieldset/Fieldset.stories.mdx +33 -3
- package/src/components/Fieldset/Fieldset.test.tsx +58 -28
- package/src/components/Fieldset/Fieldset.tsx +35 -30
- package/src/components/Fieldset/__snapshots__/Fieldset.test.tsx.snap +40 -19
- package/src/components/Form/Form.stories.mdx +72 -39
- package/src/components/Form/Form.test.tsx +58 -15
- package/src/components/Form/Form.tsx +89 -67
- package/src/components/Form/__snapshots__/Form.test.tsx.snap +83 -5
- package/src/components/Grid/GridTypes.tsx +7 -7
- package/src/components/Grid/SimpleGrid.stories.mdx +34 -6
- package/src/components/Grid/SimpleGrid.test.tsx +9 -0
- package/src/components/Grid/SimpleGrid.tsx +29 -20
- package/src/components/Grid/__snapshots__/SimpleGrid.test.tsx.snap +16 -1
- package/src/components/Heading/Heading.stories.mdx +36 -3
- package/src/components/Heading/Heading.test.tsx +10 -0
- package/src/components/Heading/Heading.tsx +56 -50
- package/src/components/Heading/__snapshots__/Heading.test.tsx.snap +26 -7
- package/src/components/HelperErrorText/HelperErrorText.stories.mdx +64 -42
- package/src/components/HelperErrorText/HelperErrorText.test.tsx +15 -0
- package/src/components/HelperErrorText/HelperErrorText.tsx +40 -35
- package/src/components/HelperErrorText/__snapshots__/HelperErrorText.test.tsx.snap +35 -4
- package/src/components/Hero/Hero.stories.mdx +125 -95
- package/src/components/Hero/Hero.test.tsx +33 -0
- package/src/components/Hero/Hero.tsx +135 -126
- package/src/components/Hero/__snapshots__/Hero.test.tsx.snap +89 -17
- package/src/components/HorizontalRule/HorizontalRule.stories.mdx +26 -4
- package/src/components/HorizontalRule/HorizontalRule.test.tsx +9 -19
- package/src/components/HorizontalRule/HorizontalRule.tsx +9 -26
- package/src/components/HorizontalRule/__snapshots__/HorizontalRule.test.tsx.snap +18 -5
- package/src/components/Icons/Icon.stories.mdx +31 -6
- package/src/components/Icons/Icon.test.tsx +38 -0
- package/src/components/Icons/Icon.tsx +93 -76
- package/src/components/Icons/__snapshots__/Icon.test.tsx.snap +129 -0
- package/src/components/Image/Image.stories.mdx +29 -5
- package/src/components/Image/Image.test.tsx +8 -0
- package/src/components/Image/Image.tsx +38 -26
- package/src/components/Image/__snapshots__/Image.test.tsx.snap +24 -8
- package/src/components/Label/Label.stories.mdx +42 -20
- package/src/components/Label/Label.test.tsx +42 -17
- package/src/components/Label/Label.tsx +22 -13
- package/src/components/Label/__snapshots__/Label.test.tsx.snap +19 -15
- package/src/components/Link/Link.stories.mdx +25 -15
- package/src/components/Link/Link.test.tsx +21 -22
- package/src/components/Link/Link.tsx +8 -8
- package/src/components/Link/__snapshots__/Link.test.tsx.snap +37 -11
- package/src/components/List/List.stories.mdx +75 -40
- package/src/components/List/List.test.tsx +67 -19
- package/src/components/List/List.tsx +38 -25
- package/src/components/List/ListTypes.tsx +1 -1
- package/src/components/List/__snapshots__/List.test.tsx.snap +110 -8
- package/src/components/Logo/Logo.stories.mdx +30 -6
- package/src/components/Logo/Logo.test.tsx +17 -0
- package/src/components/Logo/Logo.tsx +18 -6
- package/src/components/Logo/LogoSvgs.tsx +4 -0
- package/src/components/Logo/LogoTypes.tsx +2 -0
- package/src/components/Logo/__snapshots__/Logo.test.tsx.snap +73 -2
- package/src/components/Modal/Modal.stories.mdx +256 -136
- package/src/components/Modal/Modal.test.tsx +151 -9
- package/src/components/Modal/Modal.tsx +140 -20
- package/src/components/Modal/__snapshots__/Modal.test.tsx.snap +25 -0
- package/src/components/Notification/Notification.stories.mdx +25 -1
- package/src/components/Notification/Notification.test.tsx +23 -0
- package/src/components/Notification/Notification.tsx +46 -44
- package/src/components/Notification/__snapshots__/Notification.test.tsx.snap +158 -29
- package/src/components/Pagination/Pagination.stories.mdx +25 -6
- package/src/components/Pagination/Pagination.test.tsx +25 -0
- package/src/components/Pagination/Pagination.tsx +6 -6
- package/src/components/Pagination/__snapshots__/Pagination.test.tsx.snap +244 -27
- package/src/components/Placeholder/Placeholder.tsx +3 -1
- package/src/components/ProgressIndicator/ProgressIndicator.stories.mdx +76 -10
- package/src/components/ProgressIndicator/ProgressIndicator.test.tsx +81 -11
- package/src/components/ProgressIndicator/ProgressIndicator.tsx +17 -9
- package/src/components/ProgressIndicator/__snapshots__/ProgressIndicator.test.tsx.snap +101 -14
- package/src/components/Radio/Radio.stories.mdx +64 -12
- package/src/components/Radio/Radio.test.tsx +28 -8
- package/src/components/Radio/Radio.tsx +66 -63
- package/src/components/Radio/__snapshots__/Radio.test.tsx.snap +103 -6
- package/src/components/RadioGroup/RadioGroup.stories.mdx +224 -89
- package/src/components/RadioGroup/RadioGroup.test.tsx +122 -62
- package/src/components/RadioGroup/RadioGroup.tsx +106 -100
- package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +1236 -1020
- package/src/components/SearchBar/SearchBar.stories.mdx +101 -36
- package/src/components/SearchBar/{SearchBar.Test.tsx → SearchBar.test.tsx} +46 -4
- package/src/components/SearchBar/SearchBar.tsx +17 -8
- package/src/components/SearchBar/__snapshots__/SearchBar.test.tsx.snap +1039 -0
- package/src/components/Select/Select.stories.mdx +128 -49
- package/src/components/Select/Select.test.tsx +63 -16
- package/src/components/Select/Select.tsx +131 -92
- package/src/components/Select/SelectTypes.tsx +5 -0
- package/src/components/Select/__snapshots__/Select.test.tsx.snap +765 -425
- package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +42 -10
- package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +8 -0
- package/src/components/SkeletonLoader/SkeletonLoader.tsx +76 -72
- package/src/components/SkeletonLoader/__snapshots__/SkeletonLoader.test.tsx.snap +169 -10
- package/src/components/Slider/Slider.stories.mdx +91 -42
- package/src/components/Slider/Slider.test.tsx +65 -17
- package/src/components/Slider/Slider.tsx +26 -19
- package/src/components/Slider/__snapshots__/Slider.test.tsx.snap +403 -226
- package/src/components/StatusBadge/StatusBadge.stories.mdx +19 -1
- package/src/components/StatusBadge/StatusBadge.test.tsx +16 -0
- package/src/components/StatusBadge/StatusBadge.tsx +25 -20
- package/src/components/StatusBadge/__snapshots__/StatusBadge.test.tsx.snap +22 -3
- package/src/components/StructuredContent/StructuredContent.stories.mdx +131 -12
- package/src/components/StructuredContent/StructuredContent.test.tsx +34 -0
- package/src/components/StructuredContent/StructuredContent.tsx +80 -75
- package/src/components/StructuredContent/__snapshots__/StructuredContent.test.tsx.snap +102 -17
- package/src/components/StyleGuide/Bidirectionality.stories.mdx +5 -5
- package/src/components/StyleGuide/Breakpoints.stories.mdx +6 -6
- package/src/components/StyleGuide/Buttons.stories.mdx +2 -12
- package/src/components/StyleGuide/ColorCard.tsx +1 -1
- package/src/components/StyleGuide/Colors.stories.mdx +1 -2
- package/src/components/StyleGuide/DesignTokens.stories.mdx +56 -26
- package/src/components/StyleGuide/Forms.stories.mdx +27 -12
- package/src/components/StyleGuide/Iconography.stories.mdx +2 -12
- package/src/components/StyleGuide/Spacing.stories.mdx +80 -41
- package/src/components/StyleGuide/Typography.stories.mdx +30 -21
- package/src/components/Table/Table.stories.mdx +38 -11
- package/src/components/Table/Table.test.tsx +15 -0
- package/src/components/Table/Table.tsx +7 -7
- package/src/components/Table/__snapshots__/Table.test.tsx.snap +408 -5
- package/src/components/Tabs/Tabs.stories.mdx +52 -3
- package/src/components/Tabs/Tabs.test.tsx +16 -0
- package/src/components/Tabs/Tabs.tsx +10 -6
- package/src/components/Tabs/__snapshots__/Tabs.test.tsx.snap +394 -5
- package/src/components/Template/Template.stories.mdx +47 -43
- package/src/components/Template/Template.test.tsx +33 -0
- package/src/components/Template/Template.tsx +65 -60
- package/src/components/Template/__snapshots__/Template.test.tsx.snap +191 -20
- package/src/components/Text/Text.stories.mdx +20 -1
- package/src/components/Text/Text.test.tsx +12 -0
- package/src/components/Text/Text.tsx +6 -4
- package/src/components/Text/__snapshots__/Text.test.tsx.snap +21 -4
- package/src/components/TextInput/TextInput.stories.mdx +65 -19
- package/src/components/TextInput/TextInput.test.tsx +42 -28
- package/src/components/TextInput/TextInput.tsx +121 -113
- package/src/components/TextInput/__snapshots__/TextInput.test.tsx.snap +96 -73
- package/src/components/Toggle/Toggle.stories.mdx +80 -22
- package/src/components/Toggle/Toggle.test.tsx +27 -9
- package/src/components/Toggle/Toggle.tsx +22 -18
- package/src/components/Toggle/__snapshots__/Toggle.test.tsx.snap +128 -5
- package/src/components/VideoPlayer/VideoPlayer.stories.mdx +52 -4
- package/src/components/VideoPlayer/VideoPlayer.test.tsx +23 -0
- package/src/components/VideoPlayer/VideoPlayer.tsx +133 -126
- package/src/components/VideoPlayer/__snapshots__/VideoPlayer.test.tsx.snap +81 -39
- package/src/docs/Chakra.stories.mdx +50 -9
- package/src/docs/Welcome.stories.mdx +160 -41
- package/src/hooks/useCarouselStyles.stories.mdx +22 -2
- package/src/hooks/useCarouselStyles.ts +3 -2
- package/src/hooks/useNYPLTheme.stories.mdx +101 -0
- package/src/hooks/useNYPLTheme.ts +30 -6
- package/src/hooks/useWindowSize.stories.mdx +23 -0
- package/src/index.ts +5 -2
- package/src/styles/base/_place-holder.scss +1 -1
- package/src/styles.scss +0 -1
- package/src/theme/components/button.ts +15 -7
- package/src/theme/components/card.ts +30 -19
- package/src/theme/components/checkbox.ts +10 -8
- package/src/theme/components/checkboxGroup.ts +1 -1
- package/src/theme/components/componentWrapper.ts +2 -2
- package/src/theme/components/customTable.ts +39 -31
- package/src/theme/components/fieldset.ts +1 -2
- package/src/theme/components/global.ts +25 -20
- package/src/theme/components/heading.ts +1 -1
- package/src/theme/components/helperErrorText.ts +1 -0
- package/src/theme/components/hero.ts +13 -15
- package/src/theme/components/label.ts +4 -3
- package/src/theme/components/list.ts +73 -66
- package/src/theme/components/notification.ts +2 -2
- package/src/theme/components/radio.ts +9 -9
- package/src/theme/components/radioGroup.ts +1 -1
- package/src/theme/components/select.ts +31 -22
- package/src/theme/components/skeletonLoader.ts +3 -3
- package/src/theme/components/slider.ts +8 -7
- package/src/theme/components/statusBadge.ts +2 -2
- package/src/theme/components/structuredContent.ts +66 -1
- package/src/theme/components/tabs.ts +2 -2
- package/src/theme/components/template.ts +9 -9
- package/src/theme/components/textInput.ts +13 -12
- package/src/theme/components/toggle.ts +17 -10
- package/src/theme/components/videoPlayer.ts +1 -1
- package/src/theme/foundations/colors.ts +1 -1
- package/src/theme/foundations/radii.ts +1 -0
- package/src/theme/foundations/spacing.ts +70 -22
- package/src/theme/foundations/typography.ts +2 -2
- package/src/utils/componentCategories.ts +1 -2
- package/dist/components/SearchBar/SearchBar.Test.d.ts +0 -1
- package/dist/helpers/generateUUID.d.ts +0 -1
- package/src/components/Modal/_Modal.scss +0 -18
- package/src/helpers/generateUUID.tsx +0 -5
|
@@ -2,19 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
exports[`UI Snapshots renders the text input UI snapshot correctly 1`] = `
|
|
4
4
|
<div
|
|
5
|
-
className="css-
|
|
5
|
+
className="css-1xdhyk6"
|
|
6
6
|
>
|
|
7
7
|
<label
|
|
8
|
-
className="css-
|
|
8
|
+
className="css-1xdhyk6"
|
|
9
9
|
htmlFor="myTextInput"
|
|
10
10
|
id="myTextInput-label"
|
|
11
11
|
>
|
|
12
12
|
Custom Input Label
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
>
|
|
16
|
-
Required
|
|
17
|
-
</div>
|
|
13
|
+
<span>
|
|
14
|
+
(Required)
|
|
15
|
+
</span>
|
|
18
16
|
</label>
|
|
19
17
|
<input
|
|
20
18
|
aria-required={true}
|
|
@@ -33,19 +31,14 @@ exports[`UI Snapshots renders the text input UI snapshot correctly 1`] = `
|
|
|
33
31
|
|
|
34
32
|
exports[`UI Snapshots renders the text input UI snapshot correctly 2`] = `
|
|
35
33
|
<div
|
|
36
|
-
className="css-
|
|
34
|
+
className="css-1xdhyk6"
|
|
37
35
|
>
|
|
38
36
|
<label
|
|
39
|
-
className="css-
|
|
37
|
+
className="css-1xdhyk6"
|
|
40
38
|
htmlFor="myTextInput"
|
|
41
39
|
id="myTextInput-label"
|
|
42
40
|
>
|
|
43
41
|
Custom Input Label
|
|
44
|
-
<div
|
|
45
|
-
className="css-0"
|
|
46
|
-
>
|
|
47
|
-
Optional
|
|
48
|
-
</div>
|
|
49
42
|
</label>
|
|
50
43
|
<input
|
|
51
44
|
className="chakra-input css-0"
|
|
@@ -63,7 +56,7 @@ exports[`UI Snapshots renders the text input UI snapshot correctly 2`] = `
|
|
|
63
56
|
|
|
64
57
|
exports[`UI Snapshots renders the text input UI snapshot correctly 3`] = `
|
|
65
58
|
<div
|
|
66
|
-
className="css-
|
|
59
|
+
className="css-1xdhyk6"
|
|
67
60
|
>
|
|
68
61
|
<input
|
|
69
62
|
aria-label="Custom Input Label"
|
|
@@ -83,19 +76,17 @@ exports[`UI Snapshots renders the text input UI snapshot correctly 3`] = `
|
|
|
83
76
|
|
|
84
77
|
exports[`UI Snapshots renders the text input UI snapshot correctly 4`] = `
|
|
85
78
|
<div
|
|
86
|
-
className="css-
|
|
79
|
+
className="css-1xdhyk6"
|
|
87
80
|
>
|
|
88
81
|
<label
|
|
89
|
-
className="css-
|
|
82
|
+
className="css-1xdhyk6"
|
|
90
83
|
htmlFor="myTextInput"
|
|
91
84
|
id="myTextInput-label"
|
|
92
85
|
>
|
|
93
86
|
Custom Input Label
|
|
94
|
-
<
|
|
95
|
-
|
|
96
|
-
>
|
|
97
|
-
Required
|
|
98
|
-
</div>
|
|
87
|
+
<span>
|
|
88
|
+
(Required)
|
|
89
|
+
</span>
|
|
99
90
|
</label>
|
|
100
91
|
<input
|
|
101
92
|
aria-describedby="myTextInput-helperText"
|
|
@@ -111,40 +102,33 @@ exports[`UI Snapshots renders the text input UI snapshot correctly 4`] = `
|
|
|
111
102
|
type="text"
|
|
112
103
|
/>
|
|
113
104
|
<div
|
|
114
|
-
aria-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
className=" css-0"
|
|
121
|
-
dangerouslySetInnerHTML={
|
|
122
|
-
Object {
|
|
123
|
-
"__html": "Custom helper text",
|
|
124
|
-
}
|
|
105
|
+
aria-atomic={true}
|
|
106
|
+
aria-live="off"
|
|
107
|
+
className="css-1xdhyk6"
|
|
108
|
+
dangerouslySetInnerHTML={
|
|
109
|
+
Object {
|
|
110
|
+
"__html": "Custom helper text",
|
|
125
111
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
112
|
+
}
|
|
113
|
+
data-isinvalid={false}
|
|
114
|
+
id="myTextInput-helperText"
|
|
115
|
+
/>
|
|
130
116
|
</div>
|
|
131
117
|
`;
|
|
132
118
|
|
|
133
119
|
exports[`UI Snapshots renders the text input UI snapshot correctly 5`] = `
|
|
134
120
|
<div
|
|
135
|
-
className="css-
|
|
121
|
+
className="css-1xdhyk6"
|
|
136
122
|
>
|
|
137
123
|
<label
|
|
138
|
-
className="css-
|
|
124
|
+
className="css-1xdhyk6"
|
|
139
125
|
htmlFor="myTextInput"
|
|
140
126
|
id="myTextInput-label"
|
|
141
127
|
>
|
|
142
128
|
Custom Input Label
|
|
143
|
-
<
|
|
144
|
-
|
|
145
|
-
>
|
|
146
|
-
Required
|
|
147
|
-
</div>
|
|
129
|
+
<span>
|
|
130
|
+
(Required)
|
|
131
|
+
</span>
|
|
148
132
|
</label>
|
|
149
133
|
<input
|
|
150
134
|
aria-invalid={true}
|
|
@@ -160,40 +144,33 @@ exports[`UI Snapshots renders the text input UI snapshot correctly 5`] = `
|
|
|
160
144
|
type="text"
|
|
161
145
|
/>
|
|
162
146
|
<div
|
|
163
|
-
aria-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
className=" css-0"
|
|
170
|
-
dangerouslySetInnerHTML={
|
|
171
|
-
Object {
|
|
172
|
-
"__html": "There is an error related to this field.",
|
|
173
|
-
}
|
|
147
|
+
aria-atomic={true}
|
|
148
|
+
aria-live="polite"
|
|
149
|
+
className="css-1xdhyk6"
|
|
150
|
+
dangerouslySetInnerHTML={
|
|
151
|
+
Object {
|
|
152
|
+
"__html": "There is an error related to this field.",
|
|
174
153
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
154
|
+
}
|
|
155
|
+
data-isinvalid={true}
|
|
156
|
+
id="myTextInput-helperText"
|
|
157
|
+
/>
|
|
179
158
|
</div>
|
|
180
159
|
`;
|
|
181
160
|
|
|
182
161
|
exports[`UI Snapshots renders the text input UI snapshot correctly 6`] = `
|
|
183
162
|
<div
|
|
184
|
-
className="css-
|
|
163
|
+
className="css-1xdhyk6"
|
|
185
164
|
>
|
|
186
165
|
<label
|
|
187
|
-
className="css-
|
|
166
|
+
className="css-1xdhyk6"
|
|
188
167
|
htmlFor="myTextInput"
|
|
189
168
|
id="myTextInput-label"
|
|
190
169
|
>
|
|
191
170
|
Custom Input Label
|
|
192
|
-
<
|
|
193
|
-
|
|
194
|
-
>
|
|
195
|
-
Required
|
|
196
|
-
</div>
|
|
171
|
+
<span>
|
|
172
|
+
(Required)
|
|
173
|
+
</span>
|
|
197
174
|
</label>
|
|
198
175
|
<input
|
|
199
176
|
aria-required={true}
|
|
@@ -210,21 +187,67 @@ exports[`UI Snapshots renders the text input UI snapshot correctly 6`] = `
|
|
|
210
187
|
</div>
|
|
211
188
|
`;
|
|
212
189
|
|
|
190
|
+
exports[`UI Snapshots renders the text input UI snapshot correctly 7`] = `
|
|
191
|
+
<div
|
|
192
|
+
className="css-kle7zy"
|
|
193
|
+
>
|
|
194
|
+
<label
|
|
195
|
+
className="css-1xdhyk6"
|
|
196
|
+
htmlFor="chakra"
|
|
197
|
+
id="chakra-label"
|
|
198
|
+
>
|
|
199
|
+
Custom Input Label
|
|
200
|
+
</label>
|
|
201
|
+
<input
|
|
202
|
+
className="chakra-input css-0"
|
|
203
|
+
disabled={false}
|
|
204
|
+
id="chakra"
|
|
205
|
+
onBlur={[Function]}
|
|
206
|
+
onFocus={[Function]}
|
|
207
|
+
placeholder="Input Placeholder"
|
|
208
|
+
required={false}
|
|
209
|
+
step={null}
|
|
210
|
+
type="text"
|
|
211
|
+
/>
|
|
212
|
+
</div>
|
|
213
|
+
`;
|
|
214
|
+
|
|
215
|
+
exports[`UI Snapshots renders the text input UI snapshot correctly 8`] = `
|
|
216
|
+
<div
|
|
217
|
+
className="css-1xdhyk6"
|
|
218
|
+
data-testid="props"
|
|
219
|
+
>
|
|
220
|
+
<label
|
|
221
|
+
className="css-1xdhyk6"
|
|
222
|
+
htmlFor="props"
|
|
223
|
+
id="props-label"
|
|
224
|
+
>
|
|
225
|
+
Custom Input Label
|
|
226
|
+
</label>
|
|
227
|
+
<input
|
|
228
|
+
className="chakra-input css-0"
|
|
229
|
+
disabled={false}
|
|
230
|
+
id="props"
|
|
231
|
+
onBlur={[Function]}
|
|
232
|
+
onFocus={[Function]}
|
|
233
|
+
placeholder="Input Placeholder"
|
|
234
|
+
required={false}
|
|
235
|
+
step={null}
|
|
236
|
+
type="text"
|
|
237
|
+
/>
|
|
238
|
+
</div>
|
|
239
|
+
`;
|
|
240
|
+
|
|
213
241
|
exports[`UI Snapshots renders the textarea UI snapshot correctly 1`] = `
|
|
214
242
|
<div
|
|
215
|
-
className="css-
|
|
243
|
+
className="css-1xdhyk6"
|
|
216
244
|
>
|
|
217
245
|
<label
|
|
218
|
-
className="css-
|
|
246
|
+
className="css-1xdhyk6"
|
|
219
247
|
htmlFor="myTextarea"
|
|
220
248
|
id="myTextarea-label"
|
|
221
249
|
>
|
|
222
250
|
Custom textarea Label
|
|
223
|
-
<div
|
|
224
|
-
className="css-0"
|
|
225
|
-
>
|
|
226
|
-
Optional
|
|
227
|
-
</div>
|
|
228
251
|
</label>
|
|
229
252
|
<textarea
|
|
230
253
|
className="chakra-textarea css-0"
|
|
@@ -55,17 +55,35 @@ export const sizeEnumValues = getStorybookEnumValues(
|
|
|
55
55
|
| Component Version | DS Version |
|
|
56
56
|
| ----------------- | ---------- |
|
|
57
57
|
| Added | `0.25.8` |
|
|
58
|
-
| Latest | `0.
|
|
58
|
+
| Latest | `0.26.0` |
|
|
59
|
+
|
|
60
|
+
## Table of Contents
|
|
61
|
+
|
|
62
|
+
- [Overview](#overview)
|
|
63
|
+
- [Component Props](#component-props)
|
|
64
|
+
- [Accessibility](#accessibility)
|
|
65
|
+
- [Sizes](#sizes)
|
|
66
|
+
- [Controlled Toggle](#controlled-toggle)
|
|
67
|
+
- [Browser States](#browser-states)
|
|
68
|
+
- [Layouts](#layouts)
|
|
69
|
+
|
|
70
|
+
## Overview
|
|
59
71
|
|
|
60
72
|
<Description of={Toggle} />
|
|
61
73
|
|
|
62
|
-
The Toggle component is used as an alternative for the Checkbox component and
|
|
74
|
+
The `Toggle` component is used as an alternative for the Checkbox component and
|
|
75
|
+
returns a boolean response. Like the Checkbox component, the `Toggle` component
|
|
76
|
+
can display a label to the right of the toggle and helper/error text below the toggle.
|
|
63
77
|
|
|
64
78
|
### Best Practices
|
|
65
79
|
|
|
66
|
-
Toggle components are commonly used for “on/off” switches to perform binary
|
|
80
|
+
`Toggle` components are commonly used for “on/off” switches to perform binary
|
|
81
|
+
actions that occur immediately after a user “flips the switch.”
|
|
82
|
+
|
|
83
|
+
The Toggle component label should clarify the action being performed. Labels
|
|
84
|
+
should be short and to the point, often three words or less.
|
|
67
85
|
|
|
68
|
-
|
|
86
|
+
## Component Props
|
|
69
87
|
|
|
70
88
|
<Canvas>
|
|
71
89
|
<Story
|
|
@@ -92,6 +110,24 @@ The Toggle component label should clarify the action being performed. Labels sho
|
|
|
92
110
|
|
|
93
111
|
<ArgsTable story="Toggle" />
|
|
94
112
|
|
|
113
|
+
## Accessibility
|
|
114
|
+
|
|
115
|
+
The `Toggle` component is implemented using Chakra's `Switch` component. While
|
|
116
|
+
some accessibility resources state that using a `<button>` element is better for
|
|
117
|
+
a toggle or switch component, Chakra UI internally uses a `checkbox` element.
|
|
118
|
+
Because Chakra's `Switch` component handles the internal state so well and its
|
|
119
|
+
styles, we chose this over implementing this component with a `<button>` element.
|
|
120
|
+
|
|
121
|
+
For comparison and reference, resources that build toggle components with the
|
|
122
|
+
`<button>` element are linked below.
|
|
123
|
+
|
|
124
|
+
Resources:
|
|
125
|
+
|
|
126
|
+
- [Chakra UI Switch](https://chakra-ui.com/docs/components/form/switch)
|
|
127
|
+
- [W3C Switch Example Using HTML Button](https://w3c.github.io/aria-practices/examples/switch/switch-button.html)
|
|
128
|
+
- [Inclusive Components Toggle Buttons](https://inclusive-components.design/toggle-button/)
|
|
129
|
+
- [Accessible HTML Toggle Button (Switch)](https://www.erikkroes.nl/blog/accessible-html-toggle-button-switch/)
|
|
130
|
+
|
|
95
131
|
## Sizes
|
|
96
132
|
|
|
97
133
|
<Canvas>
|
|
@@ -99,13 +135,18 @@ The Toggle component label should clarify the action being performed. Labels sho
|
|
|
99
135
|
<SimpleGrid columns="2">
|
|
100
136
|
<VStack align="left" spacing="s">
|
|
101
137
|
<Heading level={3}>Default</Heading>
|
|
102
|
-
<Toggle defaultChecked={true} labelText="On" />
|
|
103
|
-
<Toggle labelText="Off" />
|
|
138
|
+
<Toggle defaultChecked={true} id="default-checked" labelText="On" />
|
|
139
|
+
<Toggle id="default" labelText="Off" />
|
|
104
140
|
</VStack>
|
|
105
141
|
<VStack align="left" spacing="s">
|
|
106
142
|
<Heading level={3}>Small</Heading>
|
|
107
|
-
<Toggle
|
|
108
|
-
|
|
143
|
+
<Toggle
|
|
144
|
+
defaultChecked={true}
|
|
145
|
+
id="small-checked"
|
|
146
|
+
size={ToggleSizes.Small}
|
|
147
|
+
labelText="On"
|
|
148
|
+
/>
|
|
149
|
+
<Toggle id="default-small" size={ToggleSizes.Small} labelText="Off" />
|
|
109
150
|
</VStack>
|
|
110
151
|
</SimpleGrid>
|
|
111
152
|
</DSProvider>
|
|
@@ -125,17 +166,23 @@ const onChange = (e) => {
|
|
|
125
166
|
console.log(e.target.value);
|
|
126
167
|
};
|
|
127
168
|
|
|
128
|
-
<Toggle
|
|
169
|
+
<Toggle
|
|
170
|
+
id="toggle"
|
|
171
|
+
isChecked={true}
|
|
172
|
+
labelText="Controlled Toggle"
|
|
173
|
+
onChange={onChange}
|
|
174
|
+
/>;
|
|
129
175
|
```
|
|
130
176
|
|
|
131
177
|
<Canvas>
|
|
132
178
|
<DSProvider>
|
|
133
179
|
<Toggle
|
|
180
|
+
id="toggle"
|
|
134
181
|
isChecked={true}
|
|
182
|
+
labelText="Controlled Toggle"
|
|
135
183
|
onChange={(e) => {
|
|
136
184
|
console.log(e.target.value);
|
|
137
185
|
}}
|
|
138
|
-
labelText="Controlled Toggle"
|
|
139
186
|
/>
|
|
140
187
|
</DSProvider>
|
|
141
188
|
</Canvas>
|
|
@@ -147,18 +194,28 @@ const onChange = (e) => {
|
|
|
147
194
|
<SimpleGrid columns="3">
|
|
148
195
|
<VStack align="left" spacing="s">
|
|
149
196
|
<Heading level={3}>Default</Heading>
|
|
150
|
-
<Toggle defaultChecked={true} labelText="On" />
|
|
151
|
-
<Toggle labelText="Off" />
|
|
197
|
+
<Toggle defaultChecked={true} id="checked-default2" labelText="On" />
|
|
198
|
+
<Toggle id="default2" labelText="Off" />
|
|
152
199
|
</VStack>
|
|
153
200
|
<VStack align="left" spacing="s">
|
|
154
201
|
<Heading level={3}>Disabled</Heading>
|
|
155
|
-
<Toggle
|
|
156
|
-
|
|
202
|
+
<Toggle
|
|
203
|
+
defaultChecked={true}
|
|
204
|
+
id="disabled-checked"
|
|
205
|
+
isDisabled={true}
|
|
206
|
+
labelText="On"
|
|
207
|
+
/>
|
|
208
|
+
<Toggle id="disabled2" isDisabled={true} labelText="Off" />
|
|
157
209
|
</VStack>
|
|
158
210
|
<VStack align="left" spacing="s">
|
|
159
211
|
<Heading level={3}>Error</Heading>
|
|
160
|
-
<Toggle
|
|
161
|
-
|
|
212
|
+
<Toggle
|
|
213
|
+
defaultChecked={true}
|
|
214
|
+
id="error-default"
|
|
215
|
+
isInvalid={true}
|
|
216
|
+
labelText="On"
|
|
217
|
+
/>
|
|
218
|
+
<Toggle id="error2" isInvalid={true} labelText="Off" />
|
|
162
219
|
</VStack>
|
|
163
220
|
</SimpleGrid>
|
|
164
221
|
</DSProvider>
|
|
@@ -171,18 +228,19 @@ const onChange = (e) => {
|
|
|
171
228
|
<SimpleGrid columns="2">
|
|
172
229
|
<VStack align="left" spacing="s">
|
|
173
230
|
<Heading level={3}>Grouped</Heading>
|
|
174
|
-
<Toggle defaultChecked={true} labelText="On" />
|
|
175
|
-
<Toggle defaultChecked={true} labelText="On" />
|
|
176
|
-
<Toggle defaultChecked={true} labelText="On" />
|
|
177
|
-
<Toggle defaultChecked={true} labelText="On" />
|
|
178
|
-
<Toggle defaultChecked={true} labelText="On" />
|
|
231
|
+
<Toggle defaultChecked={true} id="layout1" labelText="On" />
|
|
232
|
+
<Toggle defaultChecked={true} id="layout2" labelText="On" />
|
|
233
|
+
<Toggle defaultChecked={true} id="layout3" labelText="On" />
|
|
234
|
+
<Toggle defaultChecked={true} id="layout4" labelText="On" />
|
|
235
|
+
<Toggle defaultChecked={true} id="layout5" labelText="On" />
|
|
179
236
|
</VStack>
|
|
180
237
|
<VStack align="left" spacing="s">
|
|
181
238
|
<Heading level={3}>With Helper Text</Heading>
|
|
182
239
|
<Toggle
|
|
183
240
|
defaultChecked={true}
|
|
184
|
-
labelText="On"
|
|
185
241
|
helperText="Component Helper Text"
|
|
242
|
+
id="helper-text"
|
|
243
|
+
labelText="On"
|
|
186
244
|
/>
|
|
187
245
|
</VStack>
|
|
188
246
|
</SimpleGrid>
|
|
@@ -6,7 +6,6 @@ import renderer from "react-test-renderer";
|
|
|
6
6
|
|
|
7
7
|
import Toggle from "./Toggle";
|
|
8
8
|
import { ToggleSizes } from "./ToggleTypes";
|
|
9
|
-
import * as generateUUID from "../../helpers/generateUUID";
|
|
10
9
|
|
|
11
10
|
describe("Toggle Accessibility", () => {
|
|
12
11
|
it("Passes axe accessibility test", async () => {
|
|
@@ -19,7 +18,6 @@ describe("Toggle Accessibility", () => {
|
|
|
19
18
|
|
|
20
19
|
describe("Toggle", () => {
|
|
21
20
|
let changeHandler;
|
|
22
|
-
let generateUUIDSpy;
|
|
23
21
|
|
|
24
22
|
beforeEach(() => {
|
|
25
23
|
changeHandler = jest.fn();
|
|
@@ -65,13 +63,6 @@ describe("Toggle", () => {
|
|
|
65
63
|
expect(screen.getByRole("checkbox")).toHaveAttribute("id", "inputID");
|
|
66
64
|
});
|
|
67
65
|
|
|
68
|
-
it("Calls the UUID generation function if no id prop value is passed", () => {
|
|
69
|
-
generateUUIDSpy = jest.spyOn(generateUUID, "default");
|
|
70
|
-
expect(generateUUIDSpy).toHaveBeenCalledTimes(0);
|
|
71
|
-
render(<Toggle labelText="Test Label" />);
|
|
72
|
-
expect(generateUUIDSpy).toHaveBeenCalledTimes(1);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
66
|
it("Sets the 'checked' attribute", () => {
|
|
76
67
|
render(<Toggle id="inputID" labelText="Test Label" isChecked />);
|
|
77
68
|
expect(screen.getByRole("checkbox")).toHaveAttribute("checked");
|
|
@@ -120,6 +111,18 @@ describe("Toggle", () => {
|
|
|
120
111
|
expect(changeHandler).toHaveBeenCalledTimes(1);
|
|
121
112
|
});
|
|
122
113
|
|
|
114
|
+
it("Logs a warning when there is no `id` passed", () => {
|
|
115
|
+
const warn = jest.spyOn(console, "warn");
|
|
116
|
+
render(
|
|
117
|
+
// @ts-ignore: Typescript complains when a required prop is not passed, but
|
|
118
|
+
// here we don't want to pass the required prop to make sure the warning appears.
|
|
119
|
+
<Toggle labelText="test" />
|
|
120
|
+
);
|
|
121
|
+
expect(warn).toHaveBeenCalledWith(
|
|
122
|
+
"NYPL Reservoir Toggle: This component's required `id` prop was not passed."
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
|
|
123
126
|
it("Renders the UI snapshot correctly", () => {
|
|
124
127
|
const primary = renderer
|
|
125
128
|
.create(<Toggle id="inputID" labelText="Test Label" />)
|
|
@@ -143,11 +146,26 @@ describe("Toggle", () => {
|
|
|
143
146
|
/>
|
|
144
147
|
)
|
|
145
148
|
.toJSON();
|
|
149
|
+
const withChakraProps = renderer
|
|
150
|
+
.create(
|
|
151
|
+
<Toggle
|
|
152
|
+
id="chakra"
|
|
153
|
+
labelText="Test Label"
|
|
154
|
+
p="20px"
|
|
155
|
+
color="ui.error.primray"
|
|
156
|
+
/>
|
|
157
|
+
)
|
|
158
|
+
.toJSON();
|
|
159
|
+
const withOtherProps = renderer
|
|
160
|
+
.create(<Toggle id="props" labelText="Test Label" data-testid="props" />)
|
|
161
|
+
.toJSON();
|
|
146
162
|
|
|
147
163
|
expect(primary).toMatchSnapshot();
|
|
148
164
|
expect(isChecked).toMatchSnapshot();
|
|
149
165
|
expect(isInvalid).toMatchSnapshot();
|
|
150
166
|
expect(isDisabled).toMatchSnapshot();
|
|
151
167
|
expect(small).toMatchSnapshot();
|
|
168
|
+
expect(withChakraProps).toMatchSnapshot();
|
|
169
|
+
expect(withOtherProps).toMatchSnapshot();
|
|
152
170
|
});
|
|
153
171
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Box,
|
|
3
|
+
chakra,
|
|
3
4
|
Switch,
|
|
4
5
|
useMultiStyleConfig,
|
|
5
6
|
useStyleConfig,
|
|
@@ -10,8 +11,6 @@ import HelperErrorText, {
|
|
|
10
11
|
HelperErrorTextType,
|
|
11
12
|
} from "../HelperErrorText/HelperErrorText";
|
|
12
13
|
import { ToggleSizes } from "./ToggleTypes";
|
|
13
|
-
import generateUUID from "../../helpers/generateUUID";
|
|
14
|
-
|
|
15
14
|
export interface ToggleProps {
|
|
16
15
|
/** Optionally pass in additional Chakra-based styles. */
|
|
17
16
|
additionalStyles?: { [key: string]: any };
|
|
@@ -21,7 +20,7 @@ export interface ToggleProps {
|
|
|
21
20
|
/** Optional string to populate the HelperErrorText for standard state */
|
|
22
21
|
helperText?: HelperErrorTextType;
|
|
23
22
|
/** ID that other components can cross reference for accessibility purposes */
|
|
24
|
-
id
|
|
23
|
+
id: string;
|
|
25
24
|
/** Optional string to populate the HelperErrorText for the error state
|
|
26
25
|
* when `isInvalid` is true. */
|
|
27
26
|
invalidText?: HelperErrorTextType;
|
|
@@ -37,8 +36,7 @@ export interface ToggleProps {
|
|
|
37
36
|
isInvalid?: boolean;
|
|
38
37
|
/** Adds the 'required' attribute to the input when true. */
|
|
39
38
|
isRequired?: boolean;
|
|
40
|
-
/** The toggle's label. This will serve as the text content for
|
|
41
|
-
* element if `showlabel` is true, or an "aria-label" if `showLabel` is false. */
|
|
39
|
+
/** The toggle's label. This will serve as the text content for the `<label>` element */
|
|
42
40
|
labelText: string;
|
|
43
41
|
/** The name prop indicates the `Toggle`'s form element name. If none is
|
|
44
42
|
* specified, 'default' will be used. */
|
|
@@ -56,13 +54,13 @@ export const onChangeDefault = () => {
|
|
|
56
54
|
/**
|
|
57
55
|
* Component that renders Chakra's `Switch` component along with NYPL defaults.
|
|
58
56
|
*/
|
|
59
|
-
const Toggle =
|
|
60
|
-
(props, ref?) => {
|
|
57
|
+
export const Toggle = chakra(
|
|
58
|
+
React.forwardRef<HTMLInputElement, ToggleProps>((props, ref?) => {
|
|
61
59
|
const {
|
|
62
60
|
additionalStyles = {},
|
|
63
61
|
defaultChecked = false,
|
|
64
62
|
helperText,
|
|
65
|
-
id
|
|
63
|
+
id,
|
|
66
64
|
invalidText,
|
|
67
65
|
isChecked,
|
|
68
66
|
isDisabled = false,
|
|
@@ -72,17 +70,24 @@ const Toggle = React.forwardRef<HTMLInputElement, ToggleProps>(
|
|
|
72
70
|
name,
|
|
73
71
|
onChange = onChangeDefault,
|
|
74
72
|
size = ToggleSizes.Default,
|
|
73
|
+
...rest
|
|
75
74
|
} = props;
|
|
76
75
|
const footnote: HelperErrorTextType = isInvalid ? invalidText : helperText;
|
|
77
76
|
const ariaAttributes = {};
|
|
78
|
-
const styles = useMultiStyleConfig("Toggle", {});
|
|
77
|
+
const styles = useMultiStyleConfig("Toggle", { isDisabled, size });
|
|
79
78
|
const switchStyles = useStyleConfig("Switch", { size });
|
|
80
79
|
ariaAttributes["aria-label"] =
|
|
81
80
|
labelText && footnote ? `${labelText} - ${footnote}` : labelText;
|
|
82
81
|
|
|
82
|
+
if (!id) {
|
|
83
|
+
console.warn(
|
|
84
|
+
"NYPL Reservoir Toggle: This component's required `id` prop was not passed."
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
83
88
|
return (
|
|
84
89
|
<>
|
|
85
|
-
<Box __css={{ ...styles, ...additionalStyles }}>
|
|
90
|
+
<Box __css={{ ...styles, ...additionalStyles }} {...rest}>
|
|
86
91
|
<Switch
|
|
87
92
|
id={id}
|
|
88
93
|
name={name || "default"}
|
|
@@ -107,17 +112,16 @@ const Toggle = React.forwardRef<HTMLInputElement, ToggleProps>(
|
|
|
107
112
|
</Switch>
|
|
108
113
|
</Box>
|
|
109
114
|
{footnote && (
|
|
110
|
-
<
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
</Box>
|
|
115
|
+
<HelperErrorText
|
|
116
|
+
additionalStyles={styles.helperErrorText}
|
|
117
|
+
id={`${id}-helperText`}
|
|
118
|
+
isInvalid={isInvalid}
|
|
119
|
+
text={footnote}
|
|
120
|
+
/>
|
|
117
121
|
)}
|
|
118
122
|
</>
|
|
119
123
|
);
|
|
120
|
-
}
|
|
124
|
+
})
|
|
121
125
|
);
|
|
122
126
|
|
|
123
127
|
export default Toggle;
|