@nypl/design-system-react-components 0.26.1 → 1.0.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 +54 -0
- package/README.md +7 -7
- package/dist/components/Accordion/Accordion.d.ts +1 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +1 -5
- package/dist/components/Button/Button.d.ts +2 -10
- package/dist/components/ButtonGroup/ButtonGroup.d.ts +22 -0
- package/dist/components/Card/Card.d.ts +2 -2
- package/dist/components/Checkbox/Checkbox.d.ts +10 -8
- package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +1 -1
- package/dist/components/DatePicker/DatePicker.d.ts +1 -1
- package/dist/components/Form/Form.d.ts +2 -2
- package/dist/components/Grid/SimpleGrid.d.ts +6 -3
- package/dist/components/Heading/Heading.d.ts +2 -5
- package/dist/components/HelperErrorText/HelperErrorText.d.ts +1 -5
- package/dist/components/Hero/Hero.d.ts +13 -9
- package/dist/components/Icons/Icon.d.ts +6 -5
- package/dist/components/Icons/IconSvgs.d.ts +21 -21
- package/dist/components/Image/Image.d.ts +8 -5
- package/dist/components/Link/Link.d.ts +1 -9
- package/dist/components/List/List.d.ts +7 -11
- package/dist/components/Logo/Logo.d.ts +2 -5
- package/dist/components/Logo/LogoSvgs.d.ts +39 -39
- package/dist/components/Modal/Modal.d.ts +28 -8
- package/dist/components/Notification/Notification.d.ts +1 -1
- package/dist/components/ProgressIndicator/ProgressIndicator.d.ts +2 -1
- package/dist/components/RadioGroup/RadioGroup.d.ts +1 -1
- package/dist/components/SearchBar/SearchBar.d.ts +3 -2
- package/dist/components/Select/Select.d.ts +2 -5
- package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +4 -4
- package/dist/components/SkipNavigation/SkipNavigation.d.ts +17 -0
- package/dist/components/StatusBadge/StatusBadge.d.ts +2 -3
- package/dist/components/StructuredContent/StructuredContent.d.ts +2 -2
- package/dist/components/Table/Table.d.ts +1 -1
- package/dist/components/Template/Template.d.ts +2 -0
- package/dist/components/Text/Text.d.ts +1 -1
- package/dist/components/TextInput/TextInput.d.ts +21 -9
- package/dist/components/Toggle/Toggle.d.ts +1 -5
- package/dist/components/VideoPlayer/VideoPlayer.d.ts +2 -1
- package/dist/design-system-react-components.cjs.development.js +983 -1222
- 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 +982 -1285
- package/dist/design-system-react-components.esm.js.map +1 -1
- package/dist/helpers/types.d.ts +1 -0
- package/dist/index.d.ts +27 -48
- package/dist/styles.css +1 -1
- package/dist/theme/components/buttonGroup.d.ts +11 -0
- package/dist/theme/components/card.d.ts +104 -8
- package/dist/theme/components/componentWrapper.d.ts +4 -3
- package/dist/theme/components/customTable.d.ts +11 -14
- package/dist/theme/components/fieldset.d.ts +4 -3
- package/dist/theme/components/helperErrorText.d.ts +4 -3
- package/dist/theme/components/hero.d.ts +1 -1
- package/dist/theme/components/horizontalRule.d.ts +4 -3
- package/dist/theme/components/icon.d.ts +47743 -1
- package/dist/theme/components/image.d.ts +563 -10
- package/dist/theme/components/label.d.ts +4 -3
- package/dist/theme/components/list.d.ts +6 -7
- package/dist/theme/components/logo.d.ts +474 -1
- package/dist/theme/components/notification.d.ts +20 -16
- package/dist/theme/components/progressIndicator.d.ts +6 -4
- package/dist/theme/components/select.d.ts +4 -10
- package/dist/theme/components/skeletonLoader.d.ts +14 -10
- package/dist/theme/components/skipNavigation.d.ts +22 -0
- package/dist/theme/components/slider.d.ts +7 -6
- package/dist/theme/components/structuredContent.d.ts +10 -9
- package/dist/theme/components/text.d.ts +7 -1
- package/dist/theme/components/toggle.d.ts +6 -4
- package/dist/theme/provider.d.ts +2 -4
- package/dist/utils/componentCategories.d.ts +1 -1
- package/dist/utils/interfaces.d.ts +5 -0
- package/dist/utils/utils.d.ts +2 -18
- package/package.json +15 -16
- package/src/__tests__/setup.ts +3 -3
- package/src/__tests__/utils/utils.test.ts +1 -23
- package/src/components/AccessibilityGuide/SkipNavigation.stories.mdx +22 -14
- package/src/components/Accordion/Accordion.stories.mdx +43 -44
- package/src/components/Accordion/Accordion.test.tsx +5 -13
- package/src/components/Accordion/Accordion.tsx +14 -18
- package/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap +6 -6
- package/src/components/Autosuggest/Autosuggest.stories.mdx +1 -1
- package/src/components/Autosuggest/Autosuggest.stories.tsx +23 -25
- package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +21 -37
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +4 -17
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +18 -21
- package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +1 -100
- package/src/components/Button/Button.stories.mdx +89 -126
- package/src/components/Button/Button.test.tsx +16 -30
- package/src/components/Button/Button.tsx +14 -20
- package/src/components/ButtonGroup/ButtonGroup.stories.mdx +147 -0
- package/src/components/ButtonGroup/ButtonGroup.test.tsx +141 -0
- package/src/components/ButtonGroup/ButtonGroup.tsx +99 -0
- package/src/components/ButtonGroup/__snapshots__/ButtonGroup.test.tsx.snap +117 -0
- package/src/components/Card/Card.stories.mdx +144 -178
- package/src/components/Card/Card.test.tsx +36 -97
- package/src/components/Card/Card.tsx +78 -74
- package/src/components/Chakra/Box.stories.mdx +3 -7
- package/src/components/Chakra/Center.stories.mdx +6 -24
- package/src/components/Chakra/Flex.stories.mdx +5 -7
- package/src/components/Chakra/Grid.stories.mdx +1 -1
- package/src/components/Chakra/Stack.stories.mdx +10 -11
- package/src/components/Checkbox/Checkbox.stories.mdx +1 -1
- package/src/components/Checkbox/Checkbox.test.tsx +2 -2
- package/src/components/Checkbox/Checkbox.tsx +20 -13
- package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +6 -17
- package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +1 -7
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +33 -29
- package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +0 -11
- package/src/components/ComponentWrapper/ComponentWrapper.tsx +3 -10
- package/src/components/DatePicker/DatePicker.stories.mdx +23 -37
- package/src/components/DatePicker/DatePicker.test.tsx +21 -19
- package/src/components/DatePicker/DatePicker.tsx +57 -49
- package/src/components/Form/Form.stories.mdx +46 -31
- package/src/components/Form/Form.test.tsx +1 -18
- package/src/components/Form/Form.tsx +7 -7
- package/src/components/Grid/SimpleGrid.stories.mdx +73 -49
- package/src/components/Grid/SimpleGrid.test.tsx +7 -9
- package/src/components/Grid/SimpleGrid.tsx +14 -11
- package/src/components/Heading/Heading.stories.mdx +27 -72
- package/src/components/Heading/Heading.test.tsx +18 -44
- package/src/components/Heading/Heading.tsx +7 -10
- package/src/components/HelperErrorText/HelperErrorText.stories.mdx +1 -3
- package/src/components/HelperErrorText/HelperErrorText.tsx +1 -5
- package/src/components/Hero/Hero.stories.mdx +219 -216
- package/src/components/Hero/Hero.test.tsx +107 -223
- package/src/components/Hero/Hero.tsx +63 -61
- package/src/components/Icons/Icon.stories.mdx +172 -118
- package/src/components/Icons/Icon.test.tsx +8 -16
- package/src/components/Icons/Icon.tsx +75 -29
- package/src/components/Icons/IconSvgs.tsx +42 -42
- package/src/components/Image/Image.stories.mdx +45 -132
- package/src/components/Image/Image.test.tsx +16 -31
- package/src/components/Image/Image.tsx +28 -12
- package/src/components/Link/Link.stories.mdx +30 -94
- package/src/components/Link/Link.test.tsx +25 -75
- package/src/components/Link/Link.tsx +43 -56
- package/src/components/Link/__snapshots__/Link.test.tsx.snap +1 -2
- package/src/components/List/List.stories.mdx +20 -31
- package/src/components/List/List.test.tsx +24 -43
- package/src/components/List/List.tsx +25 -36
- package/src/components/Logo/Logo.stories.mdx +94 -50
- package/src/components/Logo/Logo.test.tsx +10 -19
- package/src/components/Logo/Logo.tsx +50 -17
- package/src/components/Logo/LogoSvgs.tsx +78 -78
- package/src/components/Logo/__snapshots__/Logo.test.tsx.snap +4 -4
- package/src/components/Modal/Modal.stories.mdx +245 -139
- package/src/components/Modal/Modal.test.tsx +147 -10
- 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 +10 -28
- package/src/components/Notification/Notification.test.tsx +9 -12
- package/src/components/Notification/Notification.tsx +34 -37
- package/src/components/Pagination/Pagination.stories.mdx +3 -4
- package/src/components/Pagination/Pagination.tsx +15 -10
- package/src/components/ProgressIndicator/ProgressIndicator.stories.mdx +27 -53
- package/src/components/ProgressIndicator/ProgressIndicator.test.tsx +9 -10
- package/src/components/ProgressIndicator/ProgressIndicator.tsx +17 -21
- package/src/components/ProgressIndicator/__snapshots__/ProgressIndicator.test.tsx.snap +0 -10
- package/src/components/Radio/Radio.stories.mdx +1 -1
- package/src/components/Radio/Radio.tsx +9 -6
- package/src/components/RadioGroup/RadioGroup.stories.mdx +15 -16
- package/src/components/RadioGroup/RadioGroup.test.tsx +2 -8
- package/src/components/RadioGroup/RadioGroup.tsx +28 -24
- package/src/components/SearchBar/SearchBar.stories.mdx +4 -4
- package/src/components/SearchBar/SearchBar.test.tsx +1 -1
- package/src/components/SearchBar/SearchBar.tsx +14 -22
- package/src/components/SearchBar/__snapshots__/SearchBar.test.tsx.snap +1 -13
- package/src/components/Select/Select.stories.mdx +10 -25
- package/src/components/Select/Select.test.tsx +6 -7
- package/src/components/Select/Select.tsx +28 -35
- package/src/components/Select/__snapshots__/Select.test.tsx.snap +24 -24
- package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +17 -56
- package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +7 -21
- package/src/components/SkeletonLoader/SkeletonLoader.tsx +9 -8
- package/src/components/SkeletonLoader/__snapshots__/SkeletonLoader.test.tsx.snap +33 -33
- package/src/components/SkipNavigation/SkipNavigation.stories.mdx +90 -0
- package/src/components/SkipNavigation/SkipNavigation.test.tsx +63 -0
- package/src/components/SkipNavigation/SkipNavigation.tsx +51 -0
- package/src/components/SkipNavigation/__snapshots__/SkipNavigation.test.tsx.snap +130 -0
- package/src/components/Slider/Slider.stories.mdx +19 -53
- package/src/components/Slider/Slider.test.tsx +2 -2
- package/src/components/Slider/Slider.tsx +10 -12
- package/src/components/Slider/__snapshots__/Slider.test.tsx.snap +2 -9
- package/src/components/StatusBadge/StatusBadge.stories.mdx +6 -21
- package/src/components/StatusBadge/StatusBadge.test.tsx +2 -3
- package/src/components/StatusBadge/StatusBadge.tsx +3 -10
- package/src/components/StructuredContent/StructuredContent.stories.mdx +30 -58
- package/src/components/StructuredContent/StructuredContent.test.tsx +42 -44
- package/src/components/StructuredContent/StructuredContent.tsx +9 -18
- package/src/components/StyleGuide/Bidirectionality.stories.mdx +9 -23
- package/src/components/StyleGuide/Buttons.stories.mdx +63 -63
- package/src/components/StyleGuide/ColorCard.tsx +2 -4
- package/src/components/StyleGuide/Colors.stories.mdx +9 -10
- package/src/components/StyleGuide/DesignTokens.stories.mdx +5 -7
- package/src/components/StyleGuide/Forms.stories.mdx +2 -2
- package/src/components/StyleGuide/Iconography.stories.mdx +60 -78
- package/src/components/StyleGuide/Spacing.stories.mdx +1 -2
- package/src/components/StyleGuide/Typography.stories.mdx +16 -19
- package/src/components/Table/Table.stories.mdx +85 -1
- package/src/components/Table/Table.test.tsx +57 -1
- package/src/components/Table/Table.tsx +7 -4
- package/src/components/Table/__snapshots__/Table.test.tsx.snap +121 -0
- package/src/components/Tabs/Tabs.stories.mdx +1 -1
- package/src/components/Tabs/Tabs.test.tsx +2 -2
- package/src/components/Tabs/Tabs.tsx +26 -27
- package/src/components/Template/Template.stories.mdx +49 -54
- package/src/components/Template/Template.tsx +9 -3
- package/src/components/Text/Text.stories.mdx +5 -11
- package/src/components/Text/Text.test.tsx +3 -6
- package/src/components/Text/Text.tsx +3 -5
- package/src/components/TextInput/TextInput.stories.mdx +10 -22
- package/src/components/TextInput/TextInput.test.tsx +32 -62
- package/src/components/TextInput/TextInput.tsx +61 -30
- package/src/components/TextInput/__snapshots__/TextInput.test.tsx.snap +1 -0
- package/src/components/Toggle/Toggle.stories.mdx +5 -16
- package/src/components/Toggle/Toggle.test.tsx +2 -3
- package/src/components/Toggle/Toggle.tsx +9 -10
- package/src/components/VideoPlayer/VideoPlayer.stories.mdx +13 -29
- package/src/components/VideoPlayer/VideoPlayer.test.tsx +18 -23
- package/src/components/VideoPlayer/VideoPlayer.tsx +13 -10
- package/src/docs/Chakra.stories.mdx +14 -11
- package/src/docs/Welcome.stories.mdx +23 -43
- package/src/helpers/types.ts +1 -0
- package/src/hooks/tests/useNYPLTheme.test.tsx +1 -1
- package/src/hooks/useNYPLTheme.stories.mdx +3 -6
- package/src/index.ts +52 -46
- package/src/styles.scss +0 -1
- package/src/theme/components/buttonGroup.ts +10 -0
- package/src/theme/components/card.ts +50 -15
- package/src/theme/components/componentWrapper.ts +5 -1
- package/src/theme/components/customTable.ts +8 -2
- package/src/theme/components/fieldset.ts +5 -1
- package/src/theme/components/helperErrorText.ts +5 -1
- package/src/theme/components/hero.ts +2 -2
- package/src/theme/components/horizontalRule.ts +5 -1
- package/src/theme/components/icon.ts +7 -1
- package/src/theme/components/image.ts +14 -3
- package/src/theme/components/label.ts +5 -1
- package/src/theme/components/list.ts +8 -2
- package/src/theme/components/logo.ts +5 -1
- package/src/theme/components/notification.ts +38 -14
- package/src/theme/components/progressIndicator.ts +10 -5
- package/src/theme/components/select.ts +5 -6
- package/src/theme/components/skeletonLoader.ts +8 -2
- package/src/theme/components/skipNavigation.ts +26 -0
- package/src/theme/components/slider.ts +13 -1
- package/src/theme/components/structuredContent.ts +11 -1
- package/src/theme/components/text.ts +12 -5
- package/src/theme/components/toggle.ts +9 -3
- package/src/theme/foundations/colors.ts +6 -9
- package/src/theme/index.ts +4 -0
- package/src/theme/provider.tsx +1 -1
- package/src/utils/componentCategories.ts +13 -5
- package/src/utils/interfaces.ts +5 -0
- package/src/utils/utils.ts +2 -32
- package/dist/components/Accordion/AccordionTypes.d.ts +0 -5
- package/dist/components/Breadcrumbs/BreadcrumbsTypes.d.ts +0 -8
- package/dist/components/Button/ButtonTypes.d.ts +0 -8
- package/dist/components/DatePicker/DatePickerTypes.d.ts +0 -5
- package/dist/components/Form/FormTypes.d.ts +0 -2
- package/dist/components/Grid/GridTypes.d.ts +0 -9
- package/dist/components/Heading/HeadingTypes.d.ts +0 -14
- package/dist/components/Hero/HeroTypes.d.ts +0 -12
- package/dist/components/Icons/IconTypes.d.ts +0 -77
- package/dist/components/Image/ImageTypes.d.ts +0 -22
- package/dist/components/Link/LinkTypes.d.ts +0 -8
- package/dist/components/List/ListTypes.d.ts +0 -5
- package/dist/components/Logo/LogoTypes.d.ts +0 -54
- package/dist/components/Notification/NotificationTypes.d.ts +0 -5
- package/dist/components/ProgressIndicator/ProgressIndicatorTypes.d.ts +0 -8
- package/dist/components/Select/SelectTypes.d.ts +0 -8
- package/dist/components/SkeletonLoader/SkeletonLoaderTypes.d.ts +0 -5
- package/dist/components/StatusBadge/StatusBadgeTypes.d.ts +0 -5
- package/dist/components/StructuredContent/StructuredContentTypes.d.ts +0 -5
- package/dist/components/Text/TextTypes.d.ts +0 -6
- package/dist/components/TextInput/TextInputTypes.d.ts +0 -25
- package/dist/components/Toggle/ToggleTypes.d.ts +0 -4
- package/dist/components/VideoPlayer/VideoPlayerTypes.d.ts +0 -9
- package/dist/helpers/enums.d.ts +0 -4
- package/dist/utils/siteSections.d.ts +0 -2
- package/src/components/Accordion/AccordionTypes.tsx +0 -5
- package/src/components/Breadcrumbs/BreadcrumbsTypes.tsx +0 -8
- package/src/components/Button/ButtonTypes.tsx +0 -8
- package/src/components/DatePicker/DatePickerTypes.tsx +0 -5
- package/src/components/Form/FormTypes.tsx +0 -3
- package/src/components/Grid/GridTypes.tsx +0 -9
- package/src/components/Heading/HeadingTypes.tsx +0 -15
- package/src/components/Hero/HeroTypes.tsx +0 -20
- package/src/components/Icons/IconTypes.tsx +0 -83
- package/src/components/Image/ImageTypes.ts +0 -24
- package/src/components/Link/LinkTypes.tsx +0 -8
- package/src/components/List/ListTypes.tsx +0 -5
- package/src/components/Logo/LogoTypes.tsx +0 -56
- package/src/components/Modal/_Modal.scss +0 -18
- package/src/components/Notification/NotificationTypes.tsx +0 -5
- package/src/components/ProgressIndicator/ProgressIndicatorTypes.ts +0 -8
- package/src/components/Select/SelectTypes.tsx +0 -10
- package/src/components/SkeletonLoader/SkeletonLoaderTypes.tsx +0 -5
- package/src/components/StatusBadge/StatusBadgeTypes.tsx +0 -5
- package/src/components/StructuredContent/StructuredContentTypes.tsx +0 -5
- package/src/components/Text/TextTypes.tsx +0 -6
- package/src/components/TextInput/TextInputTypes.tsx +0 -48
- package/src/components/Toggle/ToggleTypes.tsx +0 -4
- package/src/components/VideoPlayer/VideoPlayerTypes.tsx +0 -10
- package/src/helpers/enums.ts +0 -4
- package/src/utils/siteSections.ts +0 -10
|
@@ -1,20 +1,157 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
3
3
|
import { axe } from "jest-axe";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import renderer from "react-test-renderer";
|
|
4
6
|
|
|
5
|
-
import
|
|
7
|
+
import Button from "../Button/Button";
|
|
8
|
+
import { ModalTrigger, useModal } from "./Modal";
|
|
6
9
|
|
|
7
10
|
describe("Modal Accessibility", () => {
|
|
8
|
-
it("passes axe accessibility
|
|
9
|
-
const { container } = render(
|
|
11
|
+
it("passes axe accessibility for ModalTrigger", async () => {
|
|
12
|
+
const { container } = render(
|
|
13
|
+
<ModalTrigger
|
|
14
|
+
buttonText="Button Text"
|
|
15
|
+
id="modal-trigger"
|
|
16
|
+
modalProps={{
|
|
17
|
+
bodyContent: "body text",
|
|
18
|
+
closeButtonLabel: "Close Button",
|
|
19
|
+
headingText: "Modal Heading Text",
|
|
20
|
+
onClose: () => {
|
|
21
|
+
console.log("custom close");
|
|
22
|
+
},
|
|
23
|
+
}}
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
26
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("passes axe accessibility for useModal", async () => {
|
|
30
|
+
const { result } = renderHook(() => useModal());
|
|
31
|
+
const { onClose, onOpen, Modal } = result.current;
|
|
32
|
+
const modalProps = {
|
|
33
|
+
bodyContent: (
|
|
34
|
+
<>
|
|
35
|
+
<Button id="custom-close" onClick={onClose}>
|
|
36
|
+
Go back
|
|
37
|
+
</Button>
|
|
38
|
+
<p>This is the body content.</p>
|
|
39
|
+
<Button buttonType="noBrand" id="custom-close2" onClick={onClose}>
|
|
40
|
+
This is a custom close button.
|
|
41
|
+
</Button>
|
|
42
|
+
</>
|
|
43
|
+
),
|
|
44
|
+
closeButtonLabel: "Close Button",
|
|
45
|
+
headingText: "Modal Heading Text",
|
|
46
|
+
onClose: () => {
|
|
47
|
+
console.log("custom close");
|
|
48
|
+
onClose();
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
const { container } = render(
|
|
52
|
+
<>
|
|
53
|
+
<Button id="1" onClick={onOpen} buttonType="noBrand">
|
|
54
|
+
Open Modal
|
|
55
|
+
</Button>
|
|
56
|
+
<Modal {...modalProps} />
|
|
57
|
+
</>
|
|
58
|
+
);
|
|
10
59
|
expect(await axe(container)).toHaveNoViolations();
|
|
11
60
|
});
|
|
12
61
|
});
|
|
13
62
|
|
|
14
|
-
describe("
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
63
|
+
describe("ModalTrigger", () => {
|
|
64
|
+
const modalTrigger = (
|
|
65
|
+
<ModalTrigger
|
|
66
|
+
buttonText="Button Text"
|
|
67
|
+
id="modal-trigger"
|
|
68
|
+
modalProps={{
|
|
69
|
+
bodyContent: "body text",
|
|
70
|
+
closeButtonLabel: "Close Button",
|
|
71
|
+
headingText: "Modal Heading Text",
|
|
72
|
+
onClose: () => {
|
|
73
|
+
console.log("custom close");
|
|
74
|
+
},
|
|
75
|
+
}}
|
|
76
|
+
/>
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
it("renders content when it is opened", () => {
|
|
80
|
+
render(modalTrigger);
|
|
81
|
+
const openButton = screen.getByText("Button Text");
|
|
82
|
+
const closeButton = screen.queryByText("Close Button");
|
|
83
|
+
|
|
84
|
+
expect(openButton).toBeInTheDocument();
|
|
85
|
+
expect(closeButton).not.toBeInTheDocument();
|
|
86
|
+
expect(screen.queryByText("Modal Heading Text")).not.toBeInTheDocument();
|
|
87
|
+
|
|
88
|
+
openButton.click();
|
|
89
|
+
|
|
90
|
+
expect(openButton).toBeInTheDocument();
|
|
91
|
+
expect(screen.queryByText("Close Button")).toBeInTheDocument();
|
|
92
|
+
expect(screen.queryByText("Modal Heading Text")).toBeInTheDocument();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("renders the UI snapshot correctly", () => {
|
|
96
|
+
const basic = renderer.create(modalTrigger).toJSON();
|
|
97
|
+
|
|
98
|
+
expect(basic).toMatchSnapshot();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe("useModal", () => {
|
|
103
|
+
const { result } = renderHook(() => useModal());
|
|
104
|
+
const { onClose, onOpen, Modal } = result.current;
|
|
105
|
+
const modalProps = {
|
|
106
|
+
bodyContent: (
|
|
107
|
+
<>
|
|
108
|
+
<Button id="custom-close" onClick={onClose}>
|
|
109
|
+
Go back
|
|
110
|
+
</Button>
|
|
111
|
+
<p>This is the body content.</p>
|
|
112
|
+
<Button id="custom-close2" onClick={onClose}>
|
|
113
|
+
This is a custom close button.
|
|
114
|
+
</Button>
|
|
115
|
+
</>
|
|
116
|
+
),
|
|
117
|
+
closeButtonLabel: "Close Button",
|
|
118
|
+
headingText: "Modal Heading Text",
|
|
119
|
+
onClose: () => {
|
|
120
|
+
console.log("custom close");
|
|
121
|
+
onClose();
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
const useModalComponent = (
|
|
125
|
+
<>
|
|
126
|
+
<Button id="1" onClick={onOpen} buttonType="noBrand">
|
|
127
|
+
Open Modal
|
|
128
|
+
</Button>
|
|
129
|
+
<Modal {...modalProps} />
|
|
130
|
+
</>
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
it("renders content when it is opened", () => {
|
|
134
|
+
render(useModalComponent);
|
|
135
|
+
const openButton = screen.getByText("Open Modal");
|
|
136
|
+
const closeButton = screen.queryByText("This is a custom close button.");
|
|
137
|
+
|
|
138
|
+
expect(openButton).toBeInTheDocument();
|
|
139
|
+
expect(closeButton).not.toBeInTheDocument();
|
|
140
|
+
expect(screen.queryByText("Modal Heading Text")).not.toBeInTheDocument();
|
|
141
|
+
|
|
142
|
+
openButton.click();
|
|
143
|
+
|
|
144
|
+
// TODO: Fix this test
|
|
145
|
+
// expect(openButton).toBeInTheDocument();
|
|
146
|
+
// expect(
|
|
147
|
+
// screen.queryByText("This is a custom close button.")
|
|
148
|
+
// ).toBeInTheDocument();
|
|
149
|
+
// expect(screen.queryByText("Modal Heading Text")).toBeInTheDocument();
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("renders the UI snapshot correctly", () => {
|
|
153
|
+
const basic = renderer.create(useModalComponent).toJSON();
|
|
154
|
+
|
|
155
|
+
expect(basic).toMatchSnapshot();
|
|
19
156
|
});
|
|
20
157
|
});
|
|
@@ -1,34 +1,154 @@
|
|
|
1
|
+
import {
|
|
2
|
+
chakra,
|
|
3
|
+
Modal as ChakraModal,
|
|
4
|
+
ModalOverlay,
|
|
5
|
+
ModalContent,
|
|
6
|
+
ModalHeader,
|
|
7
|
+
ModalFooter,
|
|
8
|
+
ModalBody,
|
|
9
|
+
ModalCloseButton,
|
|
10
|
+
useDisclosure,
|
|
11
|
+
} from "@chakra-ui/react";
|
|
1
12
|
import * as React from "react";
|
|
2
13
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
14
|
+
import Button from "../Button/Button";
|
|
15
|
+
import ButtonGroup from "../ButtonGroup/ButtonGroup";
|
|
16
|
+
import useWindowSize from "../../hooks/useWindowSize";
|
|
17
|
+
|
|
18
|
+
interface BaseModalProps {
|
|
19
|
+
bodyContent?: string | JSX.Element;
|
|
20
|
+
closeButtonLabel?: string;
|
|
21
|
+
headingText?: string | JSX.Element;
|
|
6
22
|
/** ID that other components can cross reference for accessibility purposes */
|
|
7
23
|
id?: string;
|
|
24
|
+
isOpen?: boolean;
|
|
25
|
+
onClose?: () => void;
|
|
8
26
|
}
|
|
9
27
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
componentWillUnmount() {
|
|
17
|
-
document.body.classList.remove("no-scroll");
|
|
18
|
-
}
|
|
28
|
+
export interface ModalProps {
|
|
29
|
+
buttonText?: string;
|
|
30
|
+
/** ID that other components can cross reference for accessibility purposes */
|
|
31
|
+
id?: string;
|
|
32
|
+
modalProps: BaseModalProps;
|
|
33
|
+
}
|
|
19
34
|
|
|
20
|
-
|
|
21
|
-
|
|
35
|
+
const BaseModal = chakra(
|
|
36
|
+
({
|
|
37
|
+
bodyContent,
|
|
38
|
+
closeButtonLabel = "Close",
|
|
39
|
+
headingText,
|
|
40
|
+
id,
|
|
41
|
+
isOpen,
|
|
42
|
+
onClose,
|
|
43
|
+
...rest
|
|
44
|
+
}: React.PropsWithChildren<BaseModalProps>) => {
|
|
45
|
+
// Based on --nypl-breakpoint-medium
|
|
46
|
+
const breakpointMedium = 600;
|
|
47
|
+
const defaultSize = "xl";
|
|
48
|
+
const fullSize = "full";
|
|
49
|
+
const [size, setSize] = React.useState<string>(defaultSize);
|
|
50
|
+
const windowDimensions = useWindowSize();
|
|
51
|
+
React.useEffect(() => {
|
|
52
|
+
if (windowDimensions.width <= breakpointMedium) {
|
|
53
|
+
setSize(fullSize);
|
|
54
|
+
} else {
|
|
55
|
+
setSize(defaultSize);
|
|
56
|
+
}
|
|
57
|
+
}, [windowDimensions.width]);
|
|
22
58
|
|
|
23
59
|
return (
|
|
24
|
-
<
|
|
25
|
-
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
26
|
-
tabIndex={0}
|
|
27
|
-
className={`modal ${className}`}
|
|
60
|
+
<ChakraModal
|
|
28
61
|
id={id}
|
|
62
|
+
isOpen={isOpen}
|
|
63
|
+
onClose={onClose}
|
|
64
|
+
scrollBehavior="inside"
|
|
65
|
+
size={size}
|
|
66
|
+
{...rest}
|
|
29
67
|
>
|
|
30
|
-
|
|
31
|
-
|
|
68
|
+
<ModalOverlay />
|
|
69
|
+
<ModalContent>
|
|
70
|
+
<ModalHeader>{headingText}</ModalHeader>
|
|
71
|
+
<ModalCloseButton />
|
|
72
|
+
<ModalBody>{bodyContent}</ModalBody>
|
|
73
|
+
|
|
74
|
+
<ModalFooter>
|
|
75
|
+
<ButtonGroup>
|
|
76
|
+
<Button id="modal-close-btn" onClick={onClose}>
|
|
77
|
+
{closeButtonLabel}
|
|
78
|
+
</Button>
|
|
79
|
+
</ButtonGroup>
|
|
80
|
+
</ModalFooter>
|
|
81
|
+
</ModalContent>
|
|
82
|
+
</ChakraModal>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The `ModalTrigger` component renders a button that you click to open the
|
|
89
|
+
* internal `Modal` component. Note that props to update the internal `Modal`
|
|
90
|
+
* component are passed through to the `modalProps` prop.
|
|
91
|
+
*/
|
|
92
|
+
export const ModalTrigger = chakra(
|
|
93
|
+
({
|
|
94
|
+
buttonText,
|
|
95
|
+
id,
|
|
96
|
+
modalProps,
|
|
97
|
+
...rest
|
|
98
|
+
}: React.PropsWithChildren<ModalProps>) => {
|
|
99
|
+
const { isOpen, onOpen, onClose } = useDisclosure();
|
|
100
|
+
const finalOnCloseHandler = () => {
|
|
101
|
+
modalProps.onClose && modalProps.onClose();
|
|
102
|
+
onClose();
|
|
103
|
+
};
|
|
104
|
+
return (
|
|
105
|
+
<>
|
|
106
|
+
<Button id="modal-open-btn" onClick={onOpen}>
|
|
107
|
+
{buttonText}
|
|
108
|
+
</Button>
|
|
109
|
+
|
|
110
|
+
<BaseModal
|
|
111
|
+
bodyContent={modalProps.bodyContent}
|
|
112
|
+
closeButtonLabel={modalProps.closeButtonLabel}
|
|
113
|
+
headingText={modalProps.headingText}
|
|
114
|
+
id={id}
|
|
115
|
+
isOpen={isOpen}
|
|
116
|
+
onClose={finalOnCloseHandler}
|
|
117
|
+
{...rest}
|
|
118
|
+
/>
|
|
119
|
+
</>
|
|
32
120
|
);
|
|
33
121
|
}
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* This hook function can be used to render the `Modal` component with a custom
|
|
126
|
+
* open button(s) and optional custom close button(s). You must render your own
|
|
127
|
+
* button and pass the appropriate `onOpen` and ` handler for the modal to open.
|
|
128
|
+
*/
|
|
129
|
+
export function useModal() {
|
|
130
|
+
const { isOpen, onClose, onOpen } = useDisclosure();
|
|
131
|
+
const Modal = chakra(
|
|
132
|
+
({
|
|
133
|
+
bodyContent,
|
|
134
|
+
closeButtonLabel,
|
|
135
|
+
headingText,
|
|
136
|
+
id,
|
|
137
|
+
...rest
|
|
138
|
+
}: React.PropsWithChildren<BaseModalProps>) => {
|
|
139
|
+
return (
|
|
140
|
+
<BaseModal
|
|
141
|
+
bodyContent={bodyContent}
|
|
142
|
+
closeButtonLabel={closeButtonLabel}
|
|
143
|
+
headingText={headingText}
|
|
144
|
+
id={id}
|
|
145
|
+
isOpen={isOpen}
|
|
146
|
+
onClose={onClose}
|
|
147
|
+
{...rest}
|
|
148
|
+
/>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
return { onClose, onOpen, Modal };
|
|
34
154
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`ModalTrigger renders the UI snapshot correctly 1`] = `
|
|
4
|
+
<button
|
|
5
|
+
className="chakra-button css-1xdhyk6"
|
|
6
|
+
data-testid="button"
|
|
7
|
+
id="modal-open-btn"
|
|
8
|
+
onClick={[Function]}
|
|
9
|
+
type="button"
|
|
10
|
+
>
|
|
11
|
+
Button Text
|
|
12
|
+
</button>
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
exports[`useModal renders the UI snapshot correctly 1`] = `
|
|
16
|
+
<button
|
|
17
|
+
className="chakra-button css-1xdhyk6"
|
|
18
|
+
data-testid="button"
|
|
19
|
+
id="1"
|
|
20
|
+
onClick={[Function]}
|
|
21
|
+
type="button"
|
|
22
|
+
>
|
|
23
|
+
Open Modal
|
|
24
|
+
</button>
|
|
25
|
+
`;
|
|
@@ -8,18 +8,10 @@ import {
|
|
|
8
8
|
import { withDesign } from "storybook-addon-designs";
|
|
9
9
|
|
|
10
10
|
import Icon from "../Icons/Icon";
|
|
11
|
-
import { IconColors, IconNames } from "../Icons/IconTypes";
|
|
12
11
|
import Link from "../Link/Link";
|
|
13
12
|
import Notification from "./Notification";
|
|
14
|
-
import { NotificationTypes } from "./NotificationTypes";
|
|
15
13
|
import { getCategory } from "../../utils/componentCategories";
|
|
16
14
|
import DSProvider from "../../theme/provider";
|
|
17
|
-
import { getStorybookEnumValues } from "../../utils/utils";
|
|
18
|
-
|
|
19
|
-
export const enumValues = getStorybookEnumValues(
|
|
20
|
-
NotificationTypes,
|
|
21
|
-
"NotificationTypes"
|
|
22
|
-
);
|
|
23
15
|
|
|
24
16
|
<Meta
|
|
25
17
|
title={getCategory("Notification")}
|
|
@@ -47,9 +39,7 @@ export const enumValues = getStorybookEnumValues(
|
|
|
47
39
|
},
|
|
48
40
|
notificationContent: { control: false },
|
|
49
41
|
notificationType: {
|
|
50
|
-
|
|
51
|
-
table: { defaultValue: { summary: "NotificationTypes.Standard" } },
|
|
52
|
-
options: enumValues.options,
|
|
42
|
+
table: { defaultValue: { summary: "standard" } },
|
|
53
43
|
},
|
|
54
44
|
}}
|
|
55
45
|
/>
|
|
@@ -59,7 +49,7 @@ export const enumValues = getStorybookEnumValues(
|
|
|
59
49
|
| Component Version | DS Version |
|
|
60
50
|
| ----------------- | ---------- |
|
|
61
51
|
| Added | `0.23.2` |
|
|
62
|
-
| Latest | `0.
|
|
52
|
+
| Latest | `0.28.0` |
|
|
63
53
|
|
|
64
54
|
## Table of Contents
|
|
65
55
|
|
|
@@ -105,16 +95,13 @@ within a parent element.
|
|
|
105
95
|
nisi erat porttitor ligula.
|
|
106
96
|
</>
|
|
107
97
|
),
|
|
108
|
-
notificationType: "
|
|
98
|
+
notificationType: "standard",
|
|
109
99
|
showIcon: true,
|
|
110
100
|
}}
|
|
111
101
|
>
|
|
112
102
|
{(args) => (
|
|
113
103
|
<div style={{ border: "1px solid #ccc" }}>
|
|
114
|
-
<Notification
|
|
115
|
-
{...args}
|
|
116
|
-
notificationType={enumValues.getValue(args.notificationType)}
|
|
117
|
-
/>
|
|
104
|
+
<Notification {...args} />
|
|
118
105
|
</div>
|
|
119
106
|
)}
|
|
120
107
|
</Story>
|
|
@@ -172,7 +159,7 @@ Resources:
|
|
|
172
159
|
<Canvas>
|
|
173
160
|
<DSProvider>
|
|
174
161
|
<Notification
|
|
175
|
-
notificationType=
|
|
162
|
+
notificationType="announcement"
|
|
176
163
|
notificationHeading="Announcement Notification"
|
|
177
164
|
notificationContent={
|
|
178
165
|
<>
|
|
@@ -191,7 +178,7 @@ Resources:
|
|
|
191
178
|
<Canvas>
|
|
192
179
|
<DSProvider>
|
|
193
180
|
<Notification
|
|
194
|
-
notificationType=
|
|
181
|
+
notificationType="warning"
|
|
195
182
|
notificationHeading="Warning Notification"
|
|
196
183
|
notificationContent={
|
|
197
184
|
<>
|
|
@@ -229,7 +216,7 @@ Resources:
|
|
|
229
216
|
<Canvas>
|
|
230
217
|
<DSProvider>
|
|
231
218
|
<Notification
|
|
232
|
-
notificationType=
|
|
219
|
+
notificationType="announcement"
|
|
233
220
|
notificationContent={
|
|
234
221
|
<>
|
|
235
222
|
This is an "announcement" Notification without a heading. Cras mattis
|
|
@@ -247,7 +234,7 @@ Resources:
|
|
|
247
234
|
<Canvas>
|
|
248
235
|
<DSProvider>
|
|
249
236
|
<Notification
|
|
250
|
-
notificationType=
|
|
237
|
+
notificationType="warning"
|
|
251
238
|
notificationContent={
|
|
252
239
|
<>
|
|
253
240
|
This is a "warning" Notification without a heading. Cras mattis
|
|
@@ -330,12 +317,7 @@ The default icon can be overridden by using the `icon` prop to pass a custom `Ic
|
|
|
330
317
|
<Canvas>
|
|
331
318
|
<Story name="Custom Icons">
|
|
332
319
|
<Notification
|
|
333
|
-
icon={
|
|
334
|
-
<Icon
|
|
335
|
-
name={IconNames.Check}
|
|
336
|
-
color={IconColors.SectionResearchSecondary}
|
|
337
|
-
/>
|
|
338
|
-
}
|
|
320
|
+
icon={<Icon name="check" color="section.research.secondary" />}
|
|
339
321
|
notificationHeading="Custom Icon"
|
|
340
322
|
notificationContent={
|
|
341
323
|
<>
|
|
@@ -370,7 +352,7 @@ appears once.
|
|
|
370
352
|
nascetur ridiculus mus.
|
|
371
353
|
</>
|
|
372
354
|
}
|
|
373
|
-
notificationType=
|
|
355
|
+
notificationType="announcement"
|
|
374
356
|
/>
|
|
375
357
|
</Story>
|
|
376
358
|
</Canvas>
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { render, RenderResult, screen } from "@testing-library/react";
|
|
3
3
|
import { axe } from "jest-axe";
|
|
4
4
|
import renderer from "react-test-renderer";
|
|
5
5
|
|
|
6
6
|
import Notification from "./Notification";
|
|
7
|
-
import { NotificationTypes } from "./NotificationTypes";
|
|
8
7
|
import Icon from "../Icons/Icon";
|
|
9
|
-
import { IconNames, IconColors, IconSizes } from "../Icons/IconTypes";
|
|
10
8
|
|
|
11
9
|
describe("Notification Accessibility", () => {
|
|
12
10
|
it("passes axe accessibility test with heading", async () => {
|
|
@@ -56,7 +54,7 @@ describe("Notification Accessibility", () => {
|
|
|
56
54
|
});
|
|
57
55
|
|
|
58
56
|
describe("Notification", () => {
|
|
59
|
-
let utils;
|
|
57
|
+
let utils: RenderResult;
|
|
60
58
|
beforeEach(() => {
|
|
61
59
|
utils = render(
|
|
62
60
|
<Notification
|
|
@@ -107,9 +105,9 @@ describe("Notification", () => {
|
|
|
107
105
|
<Icon
|
|
108
106
|
id="custom-icon"
|
|
109
107
|
className="custom-icon"
|
|
110
|
-
color=
|
|
111
|
-
name=
|
|
112
|
-
size=
|
|
108
|
+
color="brand.primary"
|
|
109
|
+
name="check"
|
|
110
|
+
size="large"
|
|
113
111
|
/>
|
|
114
112
|
}
|
|
115
113
|
id="notificationID"
|
|
@@ -130,7 +128,7 @@ describe("Notification", () => {
|
|
|
130
128
|
id="notificationID"
|
|
131
129
|
notificationContent={<>Notification content.</>}
|
|
132
130
|
notificationHeading="Notification Heading"
|
|
133
|
-
notificationType=
|
|
131
|
+
notificationType="announcement"
|
|
134
132
|
/>
|
|
135
133
|
);
|
|
136
134
|
|
|
@@ -146,7 +144,7 @@ describe("Notification", () => {
|
|
|
146
144
|
id="notificationID"
|
|
147
145
|
notificationContent={<>Notification content.</>}
|
|
148
146
|
notificationHeading="Notification Heading"
|
|
149
|
-
notificationType=
|
|
147
|
+
notificationType="warning"
|
|
150
148
|
/>
|
|
151
149
|
);
|
|
152
150
|
|
|
@@ -170,7 +168,6 @@ describe("Notification", () => {
|
|
|
170
168
|
id="notificationID"
|
|
171
169
|
notificationContent={<>Notification content.</>}
|
|
172
170
|
notificationHeading="Notification Heading"
|
|
173
|
-
notificationType={NotificationTypes.Standard}
|
|
174
171
|
/>
|
|
175
172
|
);
|
|
176
173
|
|
|
@@ -197,7 +194,7 @@ describe("Notification", () => {
|
|
|
197
194
|
id="notificationID2"
|
|
198
195
|
notificationContent={<>Notification content.</>}
|
|
199
196
|
notificationHeading="Notification Heading"
|
|
200
|
-
notificationType=
|
|
197
|
+
notificationType="announcement"
|
|
201
198
|
/>
|
|
202
199
|
)
|
|
203
200
|
.toJSON();
|
|
@@ -207,7 +204,7 @@ describe("Notification", () => {
|
|
|
207
204
|
id="notificationID3"
|
|
208
205
|
notificationContent={<>Notification content.</>}
|
|
209
206
|
notificationHeading="Notification Heading"
|
|
210
|
-
notificationType=
|
|
207
|
+
notificationType="warning"
|
|
211
208
|
/>
|
|
212
209
|
)
|
|
213
210
|
.toJSON();
|