@nypl/design-system-react-components 0.25.12 → 0.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +131 -1
- package/README.md +10 -10
- package/dist/components/Accordion/Accordion.d.ts +6 -4
- package/dist/components/Accordion/AccordionTypes.d.ts +5 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +4 -4
- package/dist/components/Breadcrumbs/BreadcrumbsTypes.d.ts +1 -1
- package/dist/components/Button/Button.d.ts +2 -2
- package/dist/components/Card/Card.d.ts +22 -29
- package/dist/components/Checkbox/Checkbox.d.ts +3 -3
- package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +9 -6
- 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 +5 -5
- package/dist/components/Heading/HeadingTypes.d.ts +1 -1
- package/dist/components/HelperErrorText/HelperErrorText.d.ts +9 -8
- package/dist/components/Hero/Hero.d.ts +9 -5
- package/dist/components/HorizontalRule/HorizontalRule.d.ts +2 -10
- package/dist/components/Icons/Icon.d.ts +2 -1
- package/dist/components/Icons/IconTypes.d.ts +1 -0
- package/dist/components/Image/Image.d.ts +27 -9
- package/dist/components/Image/ImageTypes.d.ts +4 -4
- 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 +4 -2
- package/dist/components/Notification/Notification.d.ts +7 -7
- 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 +5 -7
- package/dist/components/RadioGroup/RadioGroup.d.ts +16 -8
- package/dist/components/SearchBar/SearchBar.d.ts +4 -4
- package/dist/components/Select/Select.d.ts +12 -8
- package/dist/components/Select/SelectTypes.d.ts +4 -0
- package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +8 -6
- package/dist/components/SkeletonLoader/SkeletonLoaderTypes.d.ts +0 -4
- 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 +10 -23
- package/dist/components/Table/Table.d.ts +1 -1
- package/dist/components/Tabs/Tabs.d.ts +7 -6
- package/dist/components/Template/Template.d.ts +17 -8
- package/dist/components/Text/Text.d.ts +4 -4
- package/dist/components/Text/TextTypes.d.ts +1 -1
- package/dist/components/TextInput/TextInput.d.ts +7 -7
- package/dist/components/Toggle/Toggle.d.ts +8 -10
- package/dist/components/Toggle/{ToggleSizes.d.ts → ToggleTypes.d.ts} +1 -1
- package/dist/components/VideoPlayer/VideoPlayer.d.ts +2 -1
- package/dist/design-system-react-components.cjs.development.js +2075 -1468
- 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 +2086 -1483
- package/dist/design-system-react-components.esm.js.map +1 -1
- package/dist/helpers/enums.d.ts +4 -0
- package/dist/hooks/useCarouselStyles.d.ts +3 -2
- package/dist/hooks/useNYPLTheme.d.ts +12 -0
- package/dist/index.d.ts +11 -9
- package/dist/styles.css +1 -1
- package/dist/theme/components/accordion.d.ts +7 -12
- package/dist/theme/components/breadcrumb.d.ts +3 -0
- package/dist/theme/components/button.d.ts +10 -2
- package/dist/theme/components/card.d.ts +44 -24
- package/dist/theme/components/checkbox.d.ts +6 -4
- package/dist/theme/components/checkboxGroup.d.ts +4 -2
- 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 +25 -18
- 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 +21 -15
- package/dist/theme/components/image.d.ts +1 -1
- package/dist/theme/components/label.d.ts +9 -10
- package/dist/theme/components/list.d.ts +99 -9
- package/dist/theme/components/notification.d.ts +4 -4
- package/dist/theme/components/pagination.d.ts +2 -5
- package/dist/theme/components/radio.d.ts +7 -4
- package/dist/theme/components/radioGroup.d.ts +4 -2
- package/dist/theme/components/select.d.ts +37 -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 +20 -5
- 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 +5 -6
- package/src/components/AccessibilityGuide/SkipNavigation.stories.mdx +34 -0
- package/src/components/Accordion/Accordion.stories.mdx +150 -66
- package/src/components/Accordion/Accordion.test.tsx +65 -17
- package/src/components/Accordion/Accordion.tsx +61 -27
- package/src/components/Accordion/AccordionTypes.tsx +5 -0
- package/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap +505 -14
- package/src/components/Autosuggest/Autosuggest.stories.mdx +4 -3
- package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +37 -19
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +57 -36
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +14 -13
- package/src/components/Breadcrumbs/BreadcrumbsTypes.tsx +1 -1
- 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 +493 -329
- package/src/components/Card/Card.test.tsx +138 -18
- package/src/components/Card/Card.tsx +151 -85
- package/src/components/Card/__snapshots__/Card.test.tsx.snap +221 -101
- package/src/components/Chakra/Center.stories.mdx +2 -2
- package/src/components/Chakra/Grid.stories.mdx +4 -4
- package/src/components/Checkbox/Checkbox.stories.mdx +73 -9
- package/src/components/Checkbox/Checkbox.test.tsx +89 -10
- package/src/components/Checkbox/Checkbox.tsx +26 -16
- package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +209 -6
- package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +135 -23
- package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +216 -90
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +39 -26
- package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +493 -89
- 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 +94 -15
- package/src/components/DatePicker/DatePicker.tsx +67 -58
- 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 +118 -47
- package/src/components/Form/Form.test.tsx +59 -16
- package/src/components/Form/Form.tsx +89 -65
- 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 +87 -41
- package/src/components/Grid/SimpleGrid.test.tsx +24 -9
- 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 +56 -25
- package/src/components/Heading/Heading.test.tsx +17 -7
- package/src/components/Heading/Heading.tsx +60 -58
- package/src/components/Heading/HeadingTypes.tsx +1 -1
- package/src/components/Heading/__snapshots__/Heading.test.tsx.snap +27 -8
- 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 +143 -113
- package/src/components/Hero/Hero.test.tsx +146 -58
- package/src/components/Hero/Hero.tsx +144 -112
- 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 -17
- package/src/components/HorizontalRule/HorizontalRule.tsx +9 -25
- package/src/components/HorizontalRule/__snapshots__/HorizontalRule.test.tsx.snap +18 -5
- package/src/components/Icons/Icon.stories.mdx +80 -23
- package/src/components/Icons/Icon.test.tsx +51 -2
- package/src/components/Icons/Icon.tsx +93 -71
- package/src/components/Icons/IconTypes.tsx +1 -0
- package/src/components/Icons/__snapshots__/Icon.test.tsx.snap +129 -0
- package/src/components/Image/Image.stories.mdx +160 -71
- package/src/components/Image/Image.test.tsx +40 -48
- package/src/components/Image/Image.tsx +80 -48
- package/src/components/Image/ImageTypes.ts +4 -4
- package/src/components/Image/__snapshots__/Image.test.tsx.snap +84 -21
- 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 -1
- package/src/components/Link/Link.test.tsx +21 -0
- package/src/components/Link/Link.tsx +16 -9
- 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 +73 -22
- package/src/components/List/List.tsx +44 -28
- 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 +40 -16
- package/src/components/Logo/Logo.test.tsx +29 -2
- package/src/components/Logo/Logo.tsx +28 -11
- package/src/components/Logo/LogoSvgs.tsx +4 -0
- package/src/components/Logo/LogoTypes.tsx +3 -1
- package/src/components/Logo/__snapshots__/Logo.test.tsx.snap +73 -2
- package/src/components/Modal/Modal.stories.mdx +13 -0
- package/src/components/Notification/Notification.stories.mdx +29 -5
- package/src/components/Notification/Notification.test.tsx +23 -0
- package/src/components/Notification/Notification.tsx +53 -51
- package/src/components/Notification/__snapshots__/Notification.test.tsx.snap +158 -29
- package/src/components/Pagination/Pagination.stories.mdx +27 -6
- package/src/components/Pagination/Pagination.test.tsx +55 -2
- package/src/components/Pagination/Pagination.tsx +12 -9
- 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 +87 -13
- package/src/components/ProgressIndicator/ProgressIndicator.tsx +20 -10
- package/src/components/ProgressIndicator/__snapshots__/ProgressIndicator.test.tsx.snap +101 -14
- package/src/components/Radio/Radio.stories.mdx +75 -11
- package/src/components/Radio/Radio.test.tsx +83 -9
- package/src/components/Radio/Radio.tsx +70 -62
- package/src/components/Radio/__snapshots__/Radio.test.tsx.snap +163 -5
- package/src/components/RadioGroup/RadioGroup.stories.mdx +293 -94
- package/src/components/RadioGroup/RadioGroup.test.tsx +193 -68
- package/src/components/RadioGroup/RadioGroup.tsx +110 -101
- package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +1258 -902
- 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 +20 -11
- package/src/components/SearchBar/__snapshots__/SearchBar.test.tsx.snap +1039 -0
- package/src/components/Select/Select.stories.mdx +151 -62
- package/src/components/Select/Select.test.tsx +56 -44
- package/src/components/Select/Select.tsx +125 -104
- package/src/components/Select/SelectTypes.tsx +5 -0
- package/src/components/Select/__snapshots__/Select.test.tsx.snap +749 -409
- package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +53 -23
- package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +14 -8
- package/src/components/SkeletonLoader/SkeletonLoader.tsx +80 -78
- package/src/components/SkeletonLoader/SkeletonLoaderTypes.tsx +0 -5
- package/src/components/SkeletonLoader/__snapshots__/SkeletonLoader.test.tsx.snap +169 -10
- package/src/components/Slider/Slider.stories.mdx +123 -41
- package/src/components/Slider/Slider.test.tsx +65 -17
- package/src/components/Slider/Slider.tsx +30 -23
- 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 +19 -1
- 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 +229 -61
- package/src/components/StructuredContent/StructuredContent.test.tsx +162 -101
- package/src/components/StructuredContent/StructuredContent.tsx +98 -103
- 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 +4 -4
- 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 +47 -33
- package/src/components/Table/Table.stories.mdx +38 -11
- package/src/components/Table/Table.test.tsx +16 -1
- package/src/components/Table/Table.tsx +10 -8
- package/src/components/Table/__snapshots__/Table.test.tsx.snap +408 -5
- package/src/components/Tabs/Tabs.stories.mdx +59 -10
- package/src/components/Tabs/Tabs.test.tsx +29 -11
- package/src/components/Tabs/Tabs.tsx +28 -21
- package/src/components/Tabs/__snapshots__/Tabs.test.tsx.snap +394 -5
- package/src/components/Template/Template.stories.mdx +73 -32
- package/src/components/Template/Template.test.tsx +68 -5
- package/src/components/Template/Template.tsx +89 -71
- package/src/components/Template/__snapshots__/Template.test.tsx.snap +195 -22
- package/src/components/Text/Text.stories.mdx +32 -15
- package/src/components/Text/Text.test.tsx +14 -11
- package/src/components/Text/Text.tsx +13 -16
- package/src/components/Text/TextTypes.tsx +1 -1
- package/src/components/Text/__snapshots__/Text.test.tsx.snap +21 -4
- package/src/components/TextInput/TextInput.stories.mdx +73 -27
- package/src/components/TextInput/TextInput.test.tsx +65 -50
- package/src/components/TextInput/TextInput.tsx +123 -115
- package/src/components/TextInput/__snapshots__/TextInput.test.tsx.snap +96 -73
- package/src/components/Toggle/Toggle.stories.mdx +74 -26
- package/src/components/Toggle/Toggle.test.tsx +41 -10
- package/src/components/Toggle/Toggle.tsx +29 -26
- package/src/components/Toggle/{ToggleSizes.tsx → ToggleTypes.tsx} +1 -1
- package/src/components/Toggle/__snapshots__/Toggle.test.tsx.snap +191 -4
- package/src/components/VideoPlayer/VideoPlayer.stories.mdx +52 -4
- package/src/components/VideoPlayer/VideoPlayer.test.tsx +41 -6
- package/src/components/VideoPlayer/VideoPlayer.tsx +134 -120
- 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 +168 -0
- package/src/{components/Card/CardTypes.tsx → helpers/enums.ts} +2 -2
- package/src/hooks/tests/useNYPLTheme.test.tsx +1 -1
- package/src/hooks/useCarouselStyles.stories.mdx +30 -0
- package/src/hooks/useCarouselStyles.ts +3 -2
- package/src/hooks/useNYPLTheme.stories.mdx +101 -0
- package/src/hooks/useNYPLTheme.ts +31 -7
- package/src/hooks/useWindowSize.stories.mdx +23 -0
- package/src/index.ts +11 -15
- package/src/styles/base/_place-holder.scss +1 -1
- package/src/theme/components/accordion.ts +7 -12
- package/src/theme/components/breadcrumb.ts +3 -0
- package/src/theme/components/button.ts +15 -7
- package/src/theme/components/card.ts +56 -36
- package/src/theme/components/checkbox.ts +10 -8
- package/src/theme/components/checkboxGroup.ts +4 -2
- 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 +29 -23
- package/src/theme/components/heading.ts +1 -1
- package/src/theme/components/helperErrorText.ts +1 -0
- package/src/theme/components/hero.ts +14 -16
- package/src/theme/components/icon.ts +5 -2
- package/src/theme/components/image.ts +1 -1
- package/src/theme/components/label.ts +4 -3
- package/src/theme/components/list.ts +73 -66
- package/src/theme/components/notification.ts +7 -7
- package/src/theme/components/pagination.ts +2 -5
- package/src/theme/components/progressIndicator.ts +3 -3
- package/src/theme/components/radio.ts +9 -9
- package/src/theme/components/radioGroup.ts +4 -2
- package/src/theme/components/select.ts +35 -16
- 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 +43 -13
- 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 +28 -21
- package/dist/components/Card/CardTypes.d.ts +0 -4
- package/dist/components/CheckboxGroup/CheckboxGroupLayoutTypes.d.ts +0 -4
- package/dist/components/RadioGroup/RadioGroupLayoutTypes.d.ts +0 -4
- package/dist/components/SearchBar/SearchBar.Test.d.ts +0 -1
- package/dist/helpers/generateUUID.d.ts +0 -1
- package/src/components/CheckboxGroup/CheckboxGroupLayoutTypes.tsx +0 -4
- package/src/components/RadioGroup/RadioGroupLayoutTypes.tsx +0 -4
- package/src/docs/Intro.stories.mdx +0 -53
- package/src/helpers/generateUUID.tsx +0 -5
|
@@ -4,7 +4,7 @@ import { axe } from "jest-axe";
|
|
|
4
4
|
import renderer from "react-test-renderer";
|
|
5
5
|
|
|
6
6
|
import Heading from "./Heading";
|
|
7
|
-
import {
|
|
7
|
+
import { HeadingSizes, HeadingLevels } from "./HeadingTypes";
|
|
8
8
|
|
|
9
9
|
describe("Heading Accessibility", () => {
|
|
10
10
|
it("passes axe accessibility test", async () => {
|
|
@@ -93,7 +93,7 @@ describe("Heading", () => {
|
|
|
93
93
|
|
|
94
94
|
it("throws error when neither child nor text is passed", () => {
|
|
95
95
|
expect(() => render(<Heading id="h1" level={HeadingLevels.One} />)).toThrow(
|
|
96
|
-
"Heading
|
|
96
|
+
"NYPL Reservoir Heading: No children or value was passed to the `text` prop."
|
|
97
97
|
);
|
|
98
98
|
});
|
|
99
99
|
|
|
@@ -105,7 +105,7 @@ describe("Heading", () => {
|
|
|
105
105
|
<span>many</span>
|
|
106
106
|
</Heading>
|
|
107
107
|
)
|
|
108
|
-
).toThrow("
|
|
108
|
+
).toThrow("NYPL Reservoir Heading: Only pass one child into Heading.");
|
|
109
109
|
});
|
|
110
110
|
|
|
111
111
|
it("uses custom display size", () => {
|
|
@@ -113,8 +113,8 @@ describe("Heading", () => {
|
|
|
113
113
|
<Heading
|
|
114
114
|
id="h1"
|
|
115
115
|
level={HeadingLevels.One}
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
size={HeadingSizes.Secondary}
|
|
117
|
+
text="Heading with Secondary size"
|
|
118
118
|
/>
|
|
119
119
|
);
|
|
120
120
|
expect(screen.getByRole("heading", { level: 1 })).toHaveStyle({
|
|
@@ -140,8 +140,8 @@ describe("Heading", () => {
|
|
|
140
140
|
<Heading
|
|
141
141
|
id="customDisplaySize"
|
|
142
142
|
level={HeadingLevels.One}
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
size={HeadingSizes.Secondary}
|
|
144
|
+
text="Heading with Secondary size"
|
|
145
145
|
/>
|
|
146
146
|
)
|
|
147
147
|
.toJSON();
|
|
@@ -176,6 +176,14 @@ describe("Heading", () => {
|
|
|
176
176
|
</Heading>
|
|
177
177
|
)
|
|
178
178
|
.toJSON();
|
|
179
|
+
const withChakraProps = renderer
|
|
180
|
+
.create(
|
|
181
|
+
<Heading id="chakra" text="Heading" p="20px" color="ui.red.primary" />
|
|
182
|
+
)
|
|
183
|
+
.toJSON();
|
|
184
|
+
const withOtherProps = renderer
|
|
185
|
+
.create(<Heading id="props" text="Heading" data-testid="props" />)
|
|
186
|
+
.toJSON();
|
|
179
187
|
|
|
180
188
|
expect(basic).toMatchSnapshot();
|
|
181
189
|
expect(basicWithChildText).toMatchSnapshot();
|
|
@@ -183,5 +191,7 @@ describe("Heading", () => {
|
|
|
183
191
|
expect(otherLevel).toMatchSnapshot();
|
|
184
192
|
expect(withLink).toMatchSnapshot();
|
|
185
193
|
expect(withCustomLink).toMatchSnapshot();
|
|
194
|
+
expect(withChakraProps).toMatchSnapshot();
|
|
195
|
+
expect(withOtherProps).toMatchSnapshot();
|
|
186
196
|
});
|
|
187
197
|
});
|
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
chakra,
|
|
3
|
+
Heading as ChakraHeading,
|
|
4
|
+
useStyleConfig,
|
|
5
|
+
} from "@chakra-ui/react";
|
|
2
6
|
import * as React from "react";
|
|
3
7
|
|
|
4
|
-
import {
|
|
8
|
+
import { HeadingSizes, HeadingLevels } from "./HeadingTypes";
|
|
5
9
|
import Link from "../Link/Link";
|
|
6
10
|
import { getVariant } from "../../utils/utils";
|
|
7
|
-
import generateUUID from "../../helpers/generateUUID";
|
|
8
|
-
|
|
9
11
|
export interface HeadingProps {
|
|
10
12
|
/** Optionally pass in additional Chakra-based styles. */
|
|
11
13
|
additionalStyles?: { [key: string]: any };
|
|
12
14
|
/** Optional className that appears in addition to `heading` */
|
|
13
15
|
className?: string;
|
|
14
|
-
/** Optional size used to override the default styles of the semantic HTM
|
|
15
|
-
* `<h>` elements */
|
|
16
|
-
displaySize?: HeadingDisplaySizes;
|
|
17
16
|
/** Optional ID that other components can cross reference for accessibility purposes */
|
|
18
17
|
id?: string;
|
|
19
18
|
/** Optional number 1-6 used to create the `<h*>` tag; if prop is not passed,
|
|
20
19
|
* `Heading` will default to `<h2>` */
|
|
21
20
|
level?: HeadingLevels;
|
|
21
|
+
/** Optional size used to override the default styles of the semantic HTM
|
|
22
|
+
* `<h>` elements */
|
|
23
|
+
size?: HeadingSizes;
|
|
22
24
|
/** Inner text of the `<h*>` element */
|
|
23
25
|
text?: string;
|
|
24
26
|
/** Optional URL that header points to; when `url` prop is passed to
|
|
@@ -42,61 +44,61 @@ const getMappedLevel = (level = HeadingLevels.Two) => {
|
|
|
42
44
|
return levelMap[level] || 2;
|
|
43
45
|
};
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
: `h${finalLevel}`;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
47
|
+
export const Heading = chakra(
|
|
48
|
+
(props: React.PropsWithChildren<HeadingProps>) => {
|
|
49
|
+
const {
|
|
50
|
+
additionalStyles = {},
|
|
51
|
+
className,
|
|
52
|
+
id,
|
|
53
|
+
level = HeadingLevels.Two,
|
|
54
|
+
size,
|
|
55
|
+
text,
|
|
56
|
+
url,
|
|
57
|
+
urlClass,
|
|
58
|
+
...rest
|
|
59
|
+
} = props;
|
|
60
|
+
const finalLevel = getMappedLevel(level);
|
|
61
|
+
const variant = size ? getVariant(size, HeadingSizes) : `h${finalLevel}`;
|
|
62
|
+
const styles = useStyleConfig("Heading", { variant });
|
|
63
|
+
// Combine native base styles with any additional styles.
|
|
64
|
+
// This is used in the `Hero` and `Notification` components.
|
|
65
|
+
const finalStyles = { ...styles, ...additionalStyles };
|
|
66
|
+
const asHeading: any = `h${finalLevel}`;
|
|
65
67
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
if (!props.children && !text) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
"NYPL Reservoir Heading: No children or value was passed to the `text` prop."
|
|
71
|
+
);
|
|
72
|
+
}
|
|
69
73
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
if (React.Children.count(props.children) > 1) {
|
|
75
|
+
// Catching the error because React's error isn't as helpful.
|
|
76
|
+
throw new Error(
|
|
77
|
+
"NYPL Reservoir Heading: Only pass one child into Heading."
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const contentToRender = props.children ? props.children : text;
|
|
82
|
+
const content = url ? (
|
|
83
|
+
<Link className={urlClass} href={url} id={`${id}-link`}>
|
|
84
|
+
{contentToRender}
|
|
85
|
+
</Link>
|
|
86
|
+
) : (
|
|
87
|
+
contentToRender
|
|
74
88
|
);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<ChakraHeading
|
|
92
|
+
as={asHeading}
|
|
93
|
+
className={className}
|
|
94
|
+
id={id}
|
|
95
|
+
sx={finalStyles}
|
|
96
|
+
{...rest}
|
|
97
|
+
>
|
|
98
|
+
{content}
|
|
99
|
+
</ChakraHeading>
|
|
78
100
|
);
|
|
79
101
|
}
|
|
80
|
-
|
|
81
|
-
const contentToRender = props.children ? props.children : text;
|
|
82
|
-
const content = url ? (
|
|
83
|
-
<Link className={urlClass} href={url} id={`${id}-link`}>
|
|
84
|
-
{contentToRender}
|
|
85
|
-
</Link>
|
|
86
|
-
) : (
|
|
87
|
-
contentToRender
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
return (
|
|
91
|
-
<ChakraHeading
|
|
92
|
-
id={id}
|
|
93
|
-
as={asHeading}
|
|
94
|
-
sx={finalStyles}
|
|
95
|
-
className={className}
|
|
96
|
-
>
|
|
97
|
-
{content}
|
|
98
|
-
</ChakraHeading>
|
|
99
|
-
);
|
|
100
|
-
}
|
|
102
|
+
);
|
|
101
103
|
|
|
102
104
|
export default Heading;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
exports[`Heading renders the UI snapshot correctly 1`] = `
|
|
4
4
|
<h1
|
|
5
|
-
className="chakra-heading css-
|
|
5
|
+
className="chakra-heading css-1xdhyk6"
|
|
6
6
|
id="basic"
|
|
7
7
|
>
|
|
8
8
|
Heading text
|
|
@@ -11,7 +11,7 @@ exports[`Heading renders the UI snapshot correctly 1`] = `
|
|
|
11
11
|
|
|
12
12
|
exports[`Heading renders the UI snapshot correctly 2`] = `
|
|
13
13
|
<h1
|
|
14
|
-
className="chakra-heading css-
|
|
14
|
+
className="chakra-heading css-1xdhyk6"
|
|
15
15
|
id="basicWithChildText"
|
|
16
16
|
>
|
|
17
17
|
Heading text
|
|
@@ -20,16 +20,16 @@ exports[`Heading renders the UI snapshot correctly 2`] = `
|
|
|
20
20
|
|
|
21
21
|
exports[`Heading renders the UI snapshot correctly 3`] = `
|
|
22
22
|
<h1
|
|
23
|
-
className="chakra-heading css-
|
|
23
|
+
className="chakra-heading css-1xdhyk6"
|
|
24
24
|
id="customDisplaySize"
|
|
25
25
|
>
|
|
26
|
-
Heading with Secondary
|
|
26
|
+
Heading with Secondary size
|
|
27
27
|
</h1>
|
|
28
28
|
`;
|
|
29
29
|
|
|
30
30
|
exports[`Heading renders the UI snapshot correctly 4`] = `
|
|
31
31
|
<h6
|
|
32
|
-
className="chakra-heading css-
|
|
32
|
+
className="chakra-heading css-1xdhyk6"
|
|
33
33
|
id="otherLevel"
|
|
34
34
|
>
|
|
35
35
|
Heading level six
|
|
@@ -38,11 +38,11 @@ exports[`Heading renders the UI snapshot correctly 4`] = `
|
|
|
38
38
|
|
|
39
39
|
exports[`Heading renders the UI snapshot correctly 5`] = `
|
|
40
40
|
<h1
|
|
41
|
-
className="chakra-heading css-
|
|
41
|
+
className="chakra-heading css-1xdhyk6"
|
|
42
42
|
id="withLink"
|
|
43
43
|
>
|
|
44
44
|
<a
|
|
45
|
-
className="css-
|
|
45
|
+
className="css-1xdhyk6"
|
|
46
46
|
href="fake-url"
|
|
47
47
|
id="withLink-link"
|
|
48
48
|
rel={null}
|
|
@@ -55,7 +55,7 @@ exports[`Heading renders the UI snapshot correctly 5`] = `
|
|
|
55
55
|
|
|
56
56
|
exports[`Heading renders the UI snapshot correctly 6`] = `
|
|
57
57
|
<h1
|
|
58
|
-
className="chakra-heading css-
|
|
58
|
+
className="chakra-heading css-1xdhyk6"
|
|
59
59
|
id="withCustomLink"
|
|
60
60
|
>
|
|
61
61
|
Part of the heading text is
|
|
@@ -69,3 +69,22 @@ exports[`Heading renders the UI snapshot correctly 6`] = `
|
|
|
69
69
|
</a>
|
|
70
70
|
</h1>
|
|
71
71
|
`;
|
|
72
|
+
|
|
73
|
+
exports[`Heading renders the UI snapshot correctly 7`] = `
|
|
74
|
+
<h2
|
|
75
|
+
className="chakra-heading css-10g9ftz"
|
|
76
|
+
id="chakra"
|
|
77
|
+
>
|
|
78
|
+
Heading
|
|
79
|
+
</h2>
|
|
80
|
+
`;
|
|
81
|
+
|
|
82
|
+
exports[`Heading renders the UI snapshot correctly 8`] = `
|
|
83
|
+
<h2
|
|
84
|
+
className="chakra-heading css-1xdhyk6"
|
|
85
|
+
data-testid="props"
|
|
86
|
+
id="props"
|
|
87
|
+
>
|
|
88
|
+
Heading
|
|
89
|
+
</h2>
|
|
90
|
+
`;
|
|
@@ -47,10 +47,22 @@ import DSProvider from "../../theme/provider";
|
|
|
47
47
|
| Component Version | DS Version |
|
|
48
48
|
| ----------------- | ---------- |
|
|
49
49
|
| Added | `0.0.10` |
|
|
50
|
-
| Latest | `0.
|
|
50
|
+
| Latest | `0.26.0` |
|
|
51
|
+
|
|
52
|
+
## Table of Contents
|
|
53
|
+
|
|
54
|
+
- [Overview](#overview)
|
|
55
|
+
- [Component Props](#component-props)
|
|
56
|
+
- [Accessibility](#accessibility)
|
|
57
|
+
- [With HTML Children](#with-html-children)
|
|
58
|
+
- [Invalid State](#invalid-state)
|
|
59
|
+
|
|
60
|
+
## Overview
|
|
51
61
|
|
|
52
62
|
<Description of={HelperErrorText} />
|
|
53
63
|
|
|
64
|
+
## Component Props
|
|
65
|
+
|
|
54
66
|
<Canvas withToolbar>
|
|
55
67
|
<Story
|
|
56
68
|
name="HelperErrorText with Controls"
|
|
@@ -75,6 +87,54 @@ import DSProvider from "../../theme/provider";
|
|
|
75
87
|
|
|
76
88
|
<ArgsTable story="HelperErrorText with Controls" />
|
|
77
89
|
|
|
90
|
+
## Accessibility
|
|
91
|
+
|
|
92
|
+
In the "invalid" state when `isInvalid` is set to true, the text passed to the
|
|
93
|
+
`invalidText` prop will be presented to screen readers be default. If you need
|
|
94
|
+
to turn this off, set the `ariaLive` prop to `"off"`. This is used in DS "form"
|
|
95
|
+
components for invalid form submissions or incorrect values entered.
|
|
96
|
+
|
|
97
|
+
### ariaAtomic
|
|
98
|
+
|
|
99
|
+
The `ariaAtomic` prop sets the `aria-atomic` attribute and it is set to `true`
|
|
100
|
+
by default. This allows the entire DOM element to be presented to assistive
|
|
101
|
+
technologies. When it is set to `false`, only additionals or removals will be
|
|
102
|
+
read by assistive technologies.
|
|
103
|
+
|
|
104
|
+
### ariaLive
|
|
105
|
+
|
|
106
|
+
The `ariaLive` prop sets the `aria-live` attribute; `"polite"` is set by default
|
|
107
|
+
in the "invalid" state and `"off"` otherwise. This sets the priority of when the
|
|
108
|
+
text in this component should be read to users by assistive technologies. The
|
|
109
|
+
`"off"` value indicates that the content should not be presented, `"polite"` that
|
|
110
|
+
it will be announced at the next available time slot, and `"assertive"` that it
|
|
111
|
+
should be announced immediately.
|
|
112
|
+
|
|
113
|
+
<Canvas>
|
|
114
|
+
<Story
|
|
115
|
+
name="With Aria Controls"
|
|
116
|
+
args={{
|
|
117
|
+
ariaAtomic: true,
|
|
118
|
+
ariaLive: "polite",
|
|
119
|
+
isInvalid: true,
|
|
120
|
+
}}
|
|
121
|
+
>
|
|
122
|
+
{(args) => (
|
|
123
|
+
<HelperErrorText
|
|
124
|
+
{...args}
|
|
125
|
+
text="Only invalid text can be read to screen readers with the appropriate aria-atomic and aria-live props."
|
|
126
|
+
/>
|
|
127
|
+
)}
|
|
128
|
+
</Story>
|
|
129
|
+
</Canvas>
|
|
130
|
+
|
|
131
|
+
Resources:
|
|
132
|
+
|
|
133
|
+
- [MDN ARIA live regions](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions)
|
|
134
|
+
- [W3C WAI-ARIA 1.1 - aria-live (property)](https://www.w3.org/TR/wai-aria-1.1/#aria-live)
|
|
135
|
+
- [W3C ARIA19: Using ARIA role=alert or Live Regions to Identify Errors](https://www.w3.org/TR/WCAG20-TECHS/ARIA19.html)
|
|
136
|
+
- [DigitalA11y WAI-ARIA:aria-live (Property)](https://www.digitala11y.com/aria-live-properties/)
|
|
137
|
+
|
|
78
138
|
## With HTML Children
|
|
79
139
|
|
|
80
140
|
The `HelperErrorText` component can render any React component or HTML element
|
|
@@ -93,8 +153,9 @@ through the `text` prop.
|
|
|
93
153
|
<HelperErrorText
|
|
94
154
|
text={
|
|
95
155
|
<Text>
|
|
96
|
-
This second example uses DS components, such
|
|
97
|
-
<Link href="#">`Link`</Link> component, and the `Text`
|
|
156
|
+
This second example uses Reservoir Design System (DS) components, such
|
|
157
|
+
as the <Link href="#">`Link`</Link> component, and the `Text`
|
|
158
|
+
component.
|
|
98
159
|
</Text>
|
|
99
160
|
}
|
|
100
161
|
/>
|
|
@@ -111,42 +172,3 @@ NYPL "invalid" styling.
|
|
|
111
172
|
<HelperErrorText isInvalid text="This is the error text :(" />
|
|
112
173
|
</Story>
|
|
113
174
|
</Canvas>
|
|
114
|
-
|
|
115
|
-
## With Aria Props
|
|
116
|
-
|
|
117
|
-
In the "invalid" state when `isInvalid` is set to true, the rendered text can be
|
|
118
|
-
presented to screen readers if `ariaAtomic` and `ariaLive` are set appropriately.
|
|
119
|
-
|
|
120
|
-
### ariaAtomic
|
|
121
|
-
|
|
122
|
-
The `ariaAtomic` prop sets the `aria-atomic` attribute; `true` by default. This
|
|
123
|
-
allows the entire DOM element to be presented to assistive technologies. When it
|
|
124
|
-
is set to `false`, only additionals or removals will be read by assistive
|
|
125
|
-
technologies.
|
|
126
|
-
|
|
127
|
-
### ariaLive
|
|
128
|
-
|
|
129
|
-
The `ariaLive` prop sets the `aria-live` attribute; `polite` by default in the
|
|
130
|
-
"invalid" state and `off` otherwise. This sets the priority of when the text in
|
|
131
|
-
this component should be read to users by assistive technologies. The `off` value
|
|
132
|
-
indicates that the content should not be presented, `polite` that it will be
|
|
133
|
-
announced at the next available time slot, and `assertive` that it should be
|
|
134
|
-
announced immediately.
|
|
135
|
-
|
|
136
|
-
<Canvas>
|
|
137
|
-
<Story
|
|
138
|
-
name="With Aria Controls"
|
|
139
|
-
args={{
|
|
140
|
-
ariaAtomic: true,
|
|
141
|
-
ariaLive: "polite",
|
|
142
|
-
isInvalid: true,
|
|
143
|
-
}}
|
|
144
|
-
>
|
|
145
|
-
{(args) => (
|
|
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
|
-
/>
|
|
150
|
-
)}
|
|
151
|
-
</Story>
|
|
152
|
-
</Canvas>
|
|
@@ -90,10 +90,25 @@ describe("HelperErrorText", () => {
|
|
|
90
90
|
/>
|
|
91
91
|
)
|
|
92
92
|
.toJSON();
|
|
93
|
+
const withChakraProps = renderer
|
|
94
|
+
.create(
|
|
95
|
+
<HelperErrorText
|
|
96
|
+
id="chakra"
|
|
97
|
+
text="Text"
|
|
98
|
+
p="20px"
|
|
99
|
+
color="ui.red.primary"
|
|
100
|
+
/>
|
|
101
|
+
)
|
|
102
|
+
.toJSON();
|
|
103
|
+
const withOtherProps = renderer
|
|
104
|
+
.create(<HelperErrorText id="props" text="Text" data-testid="props" />)
|
|
105
|
+
.toJSON();
|
|
93
106
|
|
|
94
107
|
expect(basic).toMatchSnapshot();
|
|
95
108
|
expect(invalid).toMatchSnapshot();
|
|
96
109
|
expect(withHTMLString).toMatchSnapshot();
|
|
97
110
|
expect(withHTMLElement).toMatchSnapshot();
|
|
111
|
+
expect(withChakraProps).toMatchSnapshot();
|
|
112
|
+
expect(withOtherProps).toMatchSnapshot();
|
|
98
113
|
});
|
|
99
114
|
});
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
+
import { Box, chakra, useStyleConfig } from "@chakra-ui/react";
|
|
1
2
|
import * as React from "react";
|
|
2
|
-
import { Box, useStyleConfig } from "@chakra-ui/react";
|
|
3
|
-
|
|
4
|
-
import generateUUID from "../../helpers/generateUUID";
|
|
5
3
|
|
|
6
4
|
export type AriaLiveValues = "assertive" | "off" | "polite";
|
|
7
5
|
export type HelperErrorTextType = string | JSX.Element;
|
|
@@ -13,11 +11,12 @@ interface HelperErrorTextProps {
|
|
|
13
11
|
* read the entire DOM element. When false, only changes (additionals or
|
|
14
12
|
* removals) will be read. True by default. */
|
|
15
13
|
ariaAtomic?: boolean;
|
|
16
|
-
/** Aria attribute
|
|
17
|
-
* indicates the priority of the text and when it should be presented to
|
|
18
|
-
* using screen readers; "off" indicates that the content should not be
|
|
19
|
-
* "polite" that it will be announced at the next available time
|
|
20
|
-
* "assertive" that it should be announced immediately.
|
|
14
|
+
/** Aria attribute used in the invalid state to read error text by default.
|
|
15
|
+
* This indicates the priority of the text and when it should be presented to
|
|
16
|
+
* users using screen readers; "off" indicates that the content should not be
|
|
17
|
+
* presented, "polite" that it will be announced at the next available time
|
|
18
|
+
* slot, and "assertive" that it should be announced immediately. This is set
|
|
19
|
+
* to "off" by default and to "polite" by when `isInvalid` is true. */
|
|
21
20
|
ariaLive?: AriaLiveValues;
|
|
22
21
|
/** Additional className to add. */
|
|
23
22
|
className?: string;
|
|
@@ -30,32 +29,38 @@ interface HelperErrorTextProps {
|
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
/**
|
|
33
|
-
* Helper or
|
|
32
|
+
* Helper or error text for forms components.
|
|
34
33
|
*/
|
|
35
|
-
export
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
isInvalid = false,
|
|
42
|
-
text,
|
|
43
|
-
}: HelperErrorTextProps) {
|
|
44
|
-
// Only announce the text in the invalid state.
|
|
45
|
-
const announceAriaLive = isInvalid;
|
|
46
|
-
const styles = useStyleConfig("HelperErrorText", { isInvalid });
|
|
47
|
-
const finalStyles = { ...styles, ...additionalStyles };
|
|
48
|
-
const props = {
|
|
49
|
-
"aria-atomic": ariaAtomic,
|
|
50
|
-
"aria-live": announceAriaLive ? ariaLive : "off",
|
|
51
|
-
className,
|
|
52
|
-
"data-isinvalid": isInvalid,
|
|
34
|
+
export const HelperErrorText = chakra(
|
|
35
|
+
({
|
|
36
|
+
additionalStyles = {},
|
|
37
|
+
ariaAtomic = true,
|
|
38
|
+
ariaLive = "polite",
|
|
39
|
+
className = "",
|
|
53
40
|
id,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
41
|
+
isInvalid = false,
|
|
42
|
+
text,
|
|
43
|
+
...rest
|
|
44
|
+
}: HelperErrorTextProps) => {
|
|
45
|
+
// Only announce the text in the invalid state.
|
|
46
|
+
const announceAriaLive = isInvalid;
|
|
47
|
+
const styles = useStyleConfig("HelperErrorText", { isInvalid });
|
|
48
|
+
const finalStyles = { ...styles, ...additionalStyles };
|
|
49
|
+
const props = {
|
|
50
|
+
"aria-atomic": ariaAtomic,
|
|
51
|
+
"aria-live": announceAriaLive ? ariaLive : "off",
|
|
52
|
+
className,
|
|
53
|
+
"data-isinvalid": isInvalid,
|
|
54
|
+
id,
|
|
55
|
+
__css: finalStyles,
|
|
56
|
+
...rest,
|
|
57
|
+
};
|
|
58
|
+
return typeof text === "string" ? (
|
|
59
|
+
<Box {...props} dangerouslySetInnerHTML={{ __html: text }} />
|
|
60
|
+
) : (
|
|
61
|
+
<Box {...props}>{text}</Box>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
export default HelperErrorText;
|
|
@@ -4,7 +4,7 @@ exports[`HelperErrorText Renders the UI snapshot correctly 1`] = `
|
|
|
4
4
|
<div
|
|
5
5
|
aria-atomic={true}
|
|
6
6
|
aria-live="off"
|
|
7
|
-
className="
|
|
7
|
+
className="css-1xdhyk6"
|
|
8
8
|
dangerouslySetInnerHTML={
|
|
9
9
|
Object {
|
|
10
10
|
"__html": "Text",
|
|
@@ -19,7 +19,7 @@ exports[`HelperErrorText Renders the UI snapshot correctly 2`] = `
|
|
|
19
19
|
<div
|
|
20
20
|
aria-atomic={true}
|
|
21
21
|
aria-live="polite"
|
|
22
|
-
className="
|
|
22
|
+
className="css-1xdhyk6"
|
|
23
23
|
dangerouslySetInnerHTML={
|
|
24
24
|
Object {
|
|
25
25
|
"__html": "Text",
|
|
@@ -34,7 +34,7 @@ exports[`HelperErrorText Renders the UI snapshot correctly 3`] = `
|
|
|
34
34
|
<div
|
|
35
35
|
aria-atomic={true}
|
|
36
36
|
aria-live="polite"
|
|
37
|
-
className="
|
|
37
|
+
className="css-1xdhyk6"
|
|
38
38
|
dangerouslySetInnerHTML={
|
|
39
39
|
Object {
|
|
40
40
|
"__html": "This helper text <b>contains HTML in the string</b>.",
|
|
@@ -49,7 +49,7 @@ exports[`HelperErrorText Renders the UI snapshot correctly 4`] = `
|
|
|
49
49
|
<div
|
|
50
50
|
aria-atomic={true}
|
|
51
51
|
aria-live="polite"
|
|
52
|
-
className="
|
|
52
|
+
className="css-1xdhyk6"
|
|
53
53
|
data-isinvalid={true}
|
|
54
54
|
id="invalid"
|
|
55
55
|
>
|
|
@@ -60,3 +60,34 @@ exports[`HelperErrorText Renders the UI snapshot correctly 4`] = `
|
|
|
60
60
|
.
|
|
61
61
|
</div>
|
|
62
62
|
`;
|
|
63
|
+
|
|
64
|
+
exports[`HelperErrorText Renders the UI snapshot correctly 5`] = `
|
|
65
|
+
<div
|
|
66
|
+
aria-atomic={true}
|
|
67
|
+
aria-live="off"
|
|
68
|
+
className="css-10g9ftz"
|
|
69
|
+
dangerouslySetInnerHTML={
|
|
70
|
+
Object {
|
|
71
|
+
"__html": "Text",
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
data-isinvalid={false}
|
|
75
|
+
id="chakra"
|
|
76
|
+
/>
|
|
77
|
+
`;
|
|
78
|
+
|
|
79
|
+
exports[`HelperErrorText Renders the UI snapshot correctly 6`] = `
|
|
80
|
+
<div
|
|
81
|
+
aria-atomic={true}
|
|
82
|
+
aria-live="off"
|
|
83
|
+
className="css-1xdhyk6"
|
|
84
|
+
dangerouslySetInnerHTML={
|
|
85
|
+
Object {
|
|
86
|
+
"__html": "Text",
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
data-isinvalid={false}
|
|
90
|
+
data-testid="props"
|
|
91
|
+
id="props"
|
|
92
|
+
/>
|
|
93
|
+
`;
|