@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ButtonGroup } from "@chakra-ui/react";
|
|
2
2
|
import {
|
|
3
3
|
ArgsTable,
|
|
4
4
|
Canvas,
|
|
@@ -6,22 +6,18 @@ import {
|
|
|
6
6
|
Meta,
|
|
7
7
|
Story,
|
|
8
8
|
} from "@storybook/addon-docs";
|
|
9
|
+
import { useState } from "react";
|
|
9
10
|
|
|
10
|
-
import Modal from "./Modal";
|
|
11
11
|
import Button from "../Button/Button";
|
|
12
|
+
import { ButtonTypes } from "../Button/ButtonTypes";
|
|
13
|
+
import Heading from "../Heading/Heading";
|
|
14
|
+
import Link from "../Link/Link";
|
|
15
|
+
import { ModalTrigger, useModal } from "./Modal";
|
|
12
16
|
import { getCategory } from "../../utils/componentCategories";
|
|
13
17
|
|
|
14
18
|
<Meta
|
|
15
19
|
title={getCategory("Modal")}
|
|
16
20
|
component={Modal}
|
|
17
|
-
argTypes={{
|
|
18
|
-
blockName: { control: false },
|
|
19
|
-
children: { table: { disable: true } },
|
|
20
|
-
className: { control: false },
|
|
21
|
-
id: { control: false },
|
|
22
|
-
modifiers: { control: false },
|
|
23
|
-
open: { description: "Only used in Storybook." },
|
|
24
|
-
}}
|
|
25
21
|
parameters={{
|
|
26
22
|
jest: ["Modal.test.tsx"],
|
|
27
23
|
}}
|
|
@@ -32,151 +28,275 @@ import { getCategory } from "../../utils/componentCategories";
|
|
|
32
28
|
| Component Version | DS Version |
|
|
33
29
|
| ----------------- | ---------- |
|
|
34
30
|
| Added | `0.1.0` |
|
|
35
|
-
| Latest | `0.
|
|
31
|
+
| Latest | `0.27.0` |
|
|
36
32
|
|
|
37
|
-
|
|
33
|
+
## Table of Contents
|
|
38
34
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
<p>
|
|
80
|
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
|
|
81
|
-
eiusmod tempor incididunt ut labore et dolore magna aliqua. Tempus
|
|
82
|
-
quam pellentesque nec nam. Sit amet purus gravida quis blandit
|
|
83
|
-
turpis cursus. Est ante in nibh mauris. Ut faucibus pulvinar
|
|
84
|
-
elementum integer. Mattis ullamcorper velit sed ullamcorper morbi
|
|
85
|
-
tincidunt ornare massa. Consectetur purus ut faucibus pulvinar
|
|
86
|
-
elementum integer enim. Accumsan sit amet nulla facilisi morbi.
|
|
87
|
-
Sagittis vitae et leo duis. Elit scelerisque mauris pellentesque
|
|
88
|
-
pulvinar pellentesque. Ullamcorper velit sed ullamcorper morbi.
|
|
89
|
-
Tellus in hac habitasse platea dictumst. Fermentum leo vel orci
|
|
90
|
-
porta non. Pulvinar mattis nunc sed blandit libero volutpat sed.
|
|
91
|
-
Cras semper auctor neque vitae tempus. Turpis egestas sed tempus
|
|
92
|
-
urna et pharetra pharetra massa. Metus aliquam eleifend mi in nulla
|
|
93
|
-
posuere sollicitudin aliquam. Sit amet risus nullam eget felis eget
|
|
94
|
-
nunc. Pharetra et ultrices neque ornare.
|
|
95
|
-
</p>
|
|
96
|
-
<p>
|
|
97
|
-
Pellentesque massa placerat duis ultricies. Viverra suspendisse
|
|
98
|
-
potenti nullam ac tortor vitae purus faucibus ornare. Pulvinar neque
|
|
99
|
-
laoreet suspendisse interdum consectetur libero. Amet mauris commodo
|
|
100
|
-
quis imperdiet massa tincidunt nunc pulvinar sapien. Quisque
|
|
101
|
-
sagittis purus sit amet. Duis ut diam quam nulla porttitor massa id.
|
|
102
|
-
Quis enim lobortis scelerisque fermentum dui faucibus in ornare. At
|
|
103
|
-
lectus urna duis convallis. In mollis nunc sed id semper risus.
|
|
104
|
-
Dolor sed viverra ipsum nunc aliquet bibendum enim facilisis.
|
|
105
|
-
</p>
|
|
106
|
-
<p>
|
|
107
|
-
Eget felis eget nunc lobortis mattis aliquam faucibus. Orci dapibus
|
|
108
|
-
ultrices in iaculis nunc sed. Vel elit scelerisque mauris
|
|
109
|
-
pellentesque pulvinar. Ultrices neque ornare aenean euismod
|
|
110
|
-
elementum nisi. Sollicitudin ac orci phasellus egestas tellus rutrum
|
|
111
|
-
tellus pellentesque. Lorem ipsum dolor sit amet. Tempus imperdiet
|
|
112
|
-
nulla malesuada pellentesque elit eget gravida cum. Pellentesque
|
|
113
|
-
massa placerat duis ultricies lacus sed turpis tincidunt. Donec et
|
|
114
|
-
odio pellentesque diam volutpat. Augue ut lectus arcu bibendum at
|
|
115
|
-
varius vel pharetra vel. Sit amet justo donec enim diam vulputate ut
|
|
116
|
-
pharetra sit. Felis eget nunc lobortis mattis aliquam faucibus.
|
|
117
|
-
Tincidunt praesent semper feugiat nibh sed pulvinar proin. Facilisi
|
|
118
|
-
nullam vehicula ipsum a. Ut sem nulla pharetra diam sit amet nisl
|
|
119
|
-
suscipit adipiscing.
|
|
120
|
-
</p>
|
|
121
|
-
</Modal>
|
|
122
|
-
)}
|
|
123
|
-
</>
|
|
124
|
-
);
|
|
125
|
-
};
|
|
35
|
+
- [Overview](#overview)
|
|
36
|
+
- [Accessibility](#accessibility)
|
|
37
|
+
- [ModalTrigger](#modaltrigger)
|
|
38
|
+
- [ModalTrigger Component Props](#modaltrigger-component-props)
|
|
39
|
+
- [useModal](#usemodal)
|
|
40
|
+
- [useModal Component Props](#usemodal-component-props)
|
|
41
|
+
- [Content Window Scrolling](#content-window-scrolling)
|
|
42
|
+
|
|
43
|
+
## Overview
|
|
44
|
+
|
|
45
|
+
_Note: This component is going through an accessibility review and is not
|
|
46
|
+
recommended for use until it is updated._
|
|
47
|
+
|
|
48
|
+
## Accessibility
|
|
49
|
+
|
|
50
|
+
TBD
|
|
51
|
+
|
|
52
|
+
## ModalTrigger
|
|
53
|
+
|
|
54
|
+
<Description of={ModalTrigger} />
|
|
55
|
+
|
|
56
|
+
```jsx
|
|
57
|
+
import { ModalTrigger } from "@nypl/design-system-react-components";
|
|
58
|
+
|
|
59
|
+
//...
|
|
60
|
+
<ModalTrigger
|
|
61
|
+
buttonText="Button Text"
|
|
62
|
+
id="modal-trigger"
|
|
63
|
+
modalProps={{
|
|
64
|
+
bodyContent="body text"
|
|
65
|
+
closeButtonLabel="Close Button"
|
|
66
|
+
headingText="Modal Heading Text"
|
|
67
|
+
onClose={() => {
|
|
68
|
+
console.log("custom close");
|
|
69
|
+
}}
|
|
70
|
+
}}
|
|
71
|
+
/>;
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## ModalTrigger Component Props
|
|
126
75
|
|
|
127
76
|
<Canvas withToolbar>
|
|
128
77
|
<Story
|
|
129
|
-
name="
|
|
78
|
+
name="ModalTrigger"
|
|
130
79
|
args={{
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
80
|
+
buttonText: "Button Text",
|
|
81
|
+
id: "modal-trigger",
|
|
82
|
+
modalProps: {
|
|
83
|
+
bodyContent: "body text",
|
|
84
|
+
closeButtonLabel: "Close Button",
|
|
85
|
+
headingText: "Modal Heading Text",
|
|
86
|
+
onClose: () => {
|
|
87
|
+
console.log("custom close");
|
|
88
|
+
},
|
|
89
|
+
},
|
|
136
90
|
}}
|
|
137
91
|
>
|
|
138
|
-
{(args) => <
|
|
92
|
+
{(args) => <ModalTrigger {...args} />}
|
|
139
93
|
</Story>
|
|
140
94
|
</Canvas>
|
|
141
95
|
|
|
142
|
-
<ArgsTable story="
|
|
96
|
+
<ArgsTable story="ModalTrigger" />
|
|
143
97
|
|
|
144
|
-
##
|
|
98
|
+
## useModal
|
|
145
99
|
|
|
146
|
-
|
|
147
|
-
means that the `Modal` component itself does not control or have state for when
|
|
148
|
-
the pop-up should display. Controlling the state for when to render the `Modal`
|
|
149
|
-
component should be contained in the parent component.
|
|
100
|
+
<Description of={useModal} />
|
|
150
101
|
|
|
151
|
-
|
|
152
|
-
|
|
102
|
+
You can retrieve the DS `Modal` component and the `onOpen` and `onClose` function
|
|
103
|
+
handlers when calling the `useModal` function. The `onOpen` function handler is
|
|
104
|
+
used to open the `Modal` React component. This function can be passed to any
|
|
105
|
+
number of elements that use the `onClick` attribute. The `onClose` function can
|
|
106
|
+
be used on any element that uses the `onClick` attribute.
|
|
153
107
|
|
|
154
|
-
|
|
108
|
+
**NOTE: in this case, the `buttonText` prop is not necessary since you have to
|
|
109
|
+
create and render your own button.**
|
|
155
110
|
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const
|
|
162
|
-
const
|
|
111
|
+
```jsx
|
|
112
|
+
import { useModal } from "@nypl/design-system-react-components";
|
|
113
|
+
|
|
114
|
+
// ...
|
|
115
|
+
export const ModalStory = (args) => {
|
|
116
|
+
const { onClose, onOpen, Modal } = useModal();
|
|
117
|
+
const modalProps = {
|
|
118
|
+
bodyContent: (
|
|
119
|
+
<>
|
|
120
|
+
<Button id="custom-close" onClick={onClose}>
|
|
121
|
+
Go back
|
|
122
|
+
</Button>
|
|
123
|
+
<p>This is the body content.</p>
|
|
124
|
+
<Button id="custom-close2" onClick={onClose}>
|
|
125
|
+
This is a custom close button.
|
|
126
|
+
</Button>
|
|
127
|
+
</>
|
|
128
|
+
),
|
|
129
|
+
closeButtonLabel: "Close Button",
|
|
130
|
+
headingText: "Modal Heading Text",
|
|
131
|
+
onClose: () => {
|
|
132
|
+
console.log("custom close");
|
|
133
|
+
onClose();
|
|
134
|
+
},
|
|
135
|
+
};
|
|
163
136
|
return (
|
|
164
137
|
<>
|
|
165
|
-
<
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
)}
|
|
138
|
+
<ButtonGroup>
|
|
139
|
+
<Button id="1" onClick={onOpen}>
|
|
140
|
+
Open Modal
|
|
141
|
+
</Button>
|
|
142
|
+
<Button buttonType={ButtonTypes.Secondary} id="2" onClick={onOpen}>
|
|
143
|
+
I can open the modal, too
|
|
144
|
+
</Button>
|
|
145
|
+
</ButtonGroup>
|
|
146
|
+
<div onClick={onOpen}>
|
|
147
|
+
I'm just a div and shouldn't be used in production but this is just an
|
|
148
|
+
example
|
|
149
|
+
</div>
|
|
150
|
+
<Modal {...modalProps} />
|
|
179
151
|
</>
|
|
180
152
|
);
|
|
181
153
|
};
|
|
182
154
|
```
|
|
155
|
+
|
|
156
|
+
export const ModalStory = (args) => {
|
|
157
|
+
const { onClose, onOpen, Modal } = useModal();
|
|
158
|
+
const modalProps = {
|
|
159
|
+
bodyContent: (
|
|
160
|
+
<>
|
|
161
|
+
<Button id="custom-close" onClick={onClose}>
|
|
162
|
+
Go back
|
|
163
|
+
</Button>
|
|
164
|
+
<p>This is the body content.</p>
|
|
165
|
+
<Button id="custom-close2" onClick={onClose}>
|
|
166
|
+
This is a custom close button.
|
|
167
|
+
</Button>
|
|
168
|
+
</>
|
|
169
|
+
),
|
|
170
|
+
closeButtonLabel: "Close Button",
|
|
171
|
+
headingText: "Modal Heading Text",
|
|
172
|
+
onClose: () => {
|
|
173
|
+
console.log("custom close");
|
|
174
|
+
onClose();
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
return (
|
|
178
|
+
<>
|
|
179
|
+
<ButtonGroup>
|
|
180
|
+
<Button id="1" onClick={onOpen}>
|
|
181
|
+
Open Modal
|
|
182
|
+
</Button>
|
|
183
|
+
<Button buttonType={ButtonTypes.Secondary} id="2" onClick={onOpen}>
|
|
184
|
+
I can open the modal, too
|
|
185
|
+
</Button>
|
|
186
|
+
</ButtonGroup>
|
|
187
|
+
<div onClick={onOpen}>
|
|
188
|
+
I'm just a div and shouldn't be used in production but this is just an
|
|
189
|
+
example
|
|
190
|
+
</div>
|
|
191
|
+
<Modal {...modalProps} />
|
|
192
|
+
</>
|
|
193
|
+
);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
## useModal Component Props
|
|
197
|
+
|
|
198
|
+
<Canvas withToolbar>
|
|
199
|
+
<Story name="Modal">
|
|
200
|
+
<ModalStory />
|
|
201
|
+
</Story>
|
|
202
|
+
</Canvas>
|
|
203
|
+
|
|
204
|
+
## Content Window Scrolling
|
|
205
|
+
|
|
206
|
+
In either `Modal` pattern, the main content inside the `Modal` component will
|
|
207
|
+
scroll while the `Modal`'s header and footer still stay static. Check the
|
|
208
|
+
example below with a lot of content inside the `Modal`.
|
|
209
|
+
|
|
210
|
+
<Canvas withToolbar>
|
|
211
|
+
<Story
|
|
212
|
+
name="Content Window Scrolling"
|
|
213
|
+
args={{
|
|
214
|
+
buttonText: "Button Text",
|
|
215
|
+
id: "modal-scrolling",
|
|
216
|
+
modalProps: {
|
|
217
|
+
bodyContent: (
|
|
218
|
+
<>
|
|
219
|
+
<Heading text="Content Title" />
|
|
220
|
+
<p>
|
|
221
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
|
|
222
|
+
eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
|
223
|
+
Pellentesque massa placerat duis ultricies lacus sed turpis
|
|
224
|
+
tincidunt.
|
|
225
|
+
<Link href="http://nypl.org">Porttitor eget dolor</Link> morbi non
|
|
226
|
+
arcu risus quis varius. Faucibus in ornare quam viverra orci sagittis.
|
|
227
|
+
</p>
|
|
228
|
+
<p>
|
|
229
|
+
Nisl vel pretium lectus quam id leo in. Etiam dignissim diam quis
|
|
230
|
+
enim lobortis scelerisque fermentum. Diam maecenas sed enim ut sem
|
|
231
|
+
viverra. Diam quam nulla porttitor massa id neque. Sed faucibus
|
|
232
|
+
turpis in eu mi.
|
|
233
|
+
</p>
|
|
234
|
+
<p>
|
|
235
|
+
Ornare lectus sit amet est placerat in. Quis blandit turpis cursus
|
|
236
|
+
in. Aliquam ut porttitor leo a diam sollicitudin tempor id eu.
|
|
237
|
+
Pellentesque eu tincidunt tortor aliquam nulla facilisi cras
|
|
238
|
+
fermentum. Porttitor leo a diam sollicitudin tempor id eu nisl
|
|
239
|
+
nunc. Feugiat nisl pretium fusce id velit ut tortor. Porttitor leo
|
|
240
|
+
a diam sollicitudin tempor id eu nisl nunc.
|
|
241
|
+
</p>
|
|
242
|
+
<p>
|
|
243
|
+
Mauris nunc congue nisi vitae suscipit tellus mauris a diam. Purus
|
|
244
|
+
gravida quis blandit turpis cursus in hac. Morbi tempus iaculis
|
|
245
|
+
urna id volutpat. Lectus nulla at volutpat diam ut venenatis.
|
|
246
|
+
Donec ac odio tempor orci dapibus ultrices in iaculis. Dui vivamus
|
|
247
|
+
arcu felis bibendum ut tristique. Cras semper auctor neque vitae
|
|
248
|
+
tempus quam pellentesque. Placerat orci nulla pellentesque
|
|
249
|
+
dignissim enim sit amet. Feugiat pretium nibh ipsum consequat.
|
|
250
|
+
Placerat orci nulla pellentesque dignissim. Suspendisse faucibus
|
|
251
|
+
interdum posuere lorem. Nullam non nisi est sit. Turpis egestas
|
|
252
|
+
integer eget aliquet nibh praesent. Tortor at risus 'viverra
|
|
253
|
+
adipiscing at. Eu augue ut lectus arcu bibendum at varius vel'
|
|
254
|
+
pharetra.
|
|
255
|
+
</p>
|
|
256
|
+
<Heading text="Another Title" />
|
|
257
|
+
<p>
|
|
258
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
|
|
259
|
+
eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
|
260
|
+
Pellentesque massa placerat duis ultricies lacus sed turpis
|
|
261
|
+
tincidunt.
|
|
262
|
+
<Link href="http://nypl.org">Porttitor eget dolor</Link> morbi non
|
|
263
|
+
arcu risus quis varius. Faucibus in ornare quam viverra orci sagittis.
|
|
264
|
+
</p>
|
|
265
|
+
<p>
|
|
266
|
+
Nisl vel pretium lectus quam id leo in. Etiam dignissim diam quis
|
|
267
|
+
enim lobortis scelerisque fermentum. Diam maecenas sed enim ut sem
|
|
268
|
+
viverra. Diam quam nulla porttitor massa id neque. Sed faucibus
|
|
269
|
+
turpis in eu mi.
|
|
270
|
+
</p>
|
|
271
|
+
<p>
|
|
272
|
+
Ornare lectus sit amet est placerat in. Quis blandit turpis cursus
|
|
273
|
+
in. Aliquam ut porttitor leo a diam sollicitudin tempor id eu.
|
|
274
|
+
Pellentesque eu tincidunt tortor aliquam nulla facilisi cras
|
|
275
|
+
fermentum. Porttitor leo a diam sollicitudin tempor id eu nisl
|
|
276
|
+
nunc. Feugiat nisl pretium fusce id velit ut tortor. Porttitor leo
|
|
277
|
+
a diam sollicitudin tempor id eu nisl nunc.
|
|
278
|
+
</p>
|
|
279
|
+
<p>
|
|
280
|
+
Mauris nunc congue nisi vitae suscipit tellus mauris a diam. Purus
|
|
281
|
+
gravida quis blandit turpis cursus in hac. Morbi tempus iaculis
|
|
282
|
+
urna id volutpat. Lectus nulla at volutpat diam ut venenatis.
|
|
283
|
+
Donec ac odio tempor orci dapibus ultrices in iaculis. Dui vivamus
|
|
284
|
+
arcu felis bibendum ut tristique. Cras semper auctor neque vitae
|
|
285
|
+
tempus quam pellentesque. Placerat orci nulla pellentesque
|
|
286
|
+
dignissim enim sit amet. Feugiat pretium nibh ipsum consequat.
|
|
287
|
+
Placerat orci nulla pellentesque dignissim. Suspendisse faucibus
|
|
288
|
+
interdum posuere lorem. Nullam non nisi est sit. Turpis egestas
|
|
289
|
+
integer eget aliquet nibh praesent. Tortor at risus 'viverra
|
|
290
|
+
adipiscing at. Eu augue ut lectus arcu bibendum at varius vel'
|
|
291
|
+
pharetra.
|
|
292
|
+
</p>
|
|
293
|
+
</>
|
|
294
|
+
),
|
|
295
|
+
closeButtonLabel: "Close Button",
|
|
296
|
+
headingText: "Modal Heading Text",
|
|
297
|
+
},
|
|
298
|
+
}}
|
|
299
|
+
>
|
|
300
|
+
{(args) => <ModalTrigger {...args} />}
|
|
301
|
+
</Story>
|
|
302
|
+
</Canvas>
|
|
@@ -1,20 +1,162 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { render } from "@testing-library/react";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
3
4
|
import { axe } from "jest-axe";
|
|
5
|
+
import renderer from "react-test-renderer";
|
|
4
6
|
|
|
5
|
-
import
|
|
7
|
+
import { Button } from "../Button/Button";
|
|
8
|
+
import { ButtonTypes } from "../Button/ButtonTypes";
|
|
9
|
+
import { ModalTrigger, useModal } from "./Modal";
|
|
6
10
|
|
|
7
11
|
describe("Modal Accessibility", () => {
|
|
8
|
-
it("passes axe accessibility
|
|
9
|
-
const { container } = render(
|
|
12
|
+
it("passes axe accessibility for ModalTrigger", async () => {
|
|
13
|
+
const { container } = render(
|
|
14
|
+
<ModalTrigger
|
|
15
|
+
buttonText="Button Text"
|
|
16
|
+
id="modal-trigger"
|
|
17
|
+
modalProps={{
|
|
18
|
+
bodyContent: "body text",
|
|
19
|
+
closeButtonLabel: "Close Button",
|
|
20
|
+
headingText: "Modal Heading Text",
|
|
21
|
+
onClose: () => {
|
|
22
|
+
console.log("custom close");
|
|
23
|
+
},
|
|
24
|
+
}}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
10
27
|
expect(await axe(container)).toHaveNoViolations();
|
|
11
28
|
});
|
|
29
|
+
|
|
30
|
+
it("passes axe accessibility for useModal", async () => {
|
|
31
|
+
const { result } = renderHook(() => useModal());
|
|
32
|
+
const { onClose, onOpen, Modal } = result.current;
|
|
33
|
+
const modalProps = {
|
|
34
|
+
bodyContent: (
|
|
35
|
+
<>
|
|
36
|
+
<Button id="custom-close" onClick={onClose}>
|
|
37
|
+
Go back
|
|
38
|
+
</Button>
|
|
39
|
+
<p>This is the body content.</p>
|
|
40
|
+
<Button
|
|
41
|
+
buttonType={ButtonTypes.NoBrand}
|
|
42
|
+
id="custom-close2"
|
|
43
|
+
onClick={onClose}
|
|
44
|
+
>
|
|
45
|
+
This is a custom close button.
|
|
46
|
+
</Button>
|
|
47
|
+
</>
|
|
48
|
+
),
|
|
49
|
+
closeButtonLabel: "Close Button",
|
|
50
|
+
headingText: "Modal Heading Text",
|
|
51
|
+
onClose: () => {
|
|
52
|
+
console.log("custom close");
|
|
53
|
+
onClose();
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
const { container } = render(
|
|
57
|
+
<>
|
|
58
|
+
<Button id="1" onClick={onOpen} buttonType={ButtonTypes.NoBrand}>
|
|
59
|
+
Open Modal
|
|
60
|
+
</Button>
|
|
61
|
+
<Modal {...modalProps} />
|
|
62
|
+
</>
|
|
63
|
+
);
|
|
64
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("ModalTrigger", () => {
|
|
69
|
+
const modalTrigger = (
|
|
70
|
+
<ModalTrigger
|
|
71
|
+
buttonText="Button Text"
|
|
72
|
+
id="modal-trigger"
|
|
73
|
+
modalProps={{
|
|
74
|
+
bodyContent: "body text",
|
|
75
|
+
closeButtonLabel: "Close Button",
|
|
76
|
+
headingText: "Modal Heading Text",
|
|
77
|
+
onClose: () => {
|
|
78
|
+
console.log("custom close");
|
|
79
|
+
},
|
|
80
|
+
}}
|
|
81
|
+
/>
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
it("renders content when it is opened", () => {
|
|
85
|
+
render(modalTrigger);
|
|
86
|
+
const openButton = screen.getByText("Button Text");
|
|
87
|
+
const closeButton = screen.queryByText("Close Button");
|
|
88
|
+
|
|
89
|
+
expect(openButton).toBeInTheDocument();
|
|
90
|
+
expect(closeButton).not.toBeInTheDocument();
|
|
91
|
+
expect(screen.queryByText("Modal Heading Text")).not.toBeInTheDocument();
|
|
92
|
+
|
|
93
|
+
openButton.click();
|
|
94
|
+
|
|
95
|
+
expect(openButton).toBeInTheDocument();
|
|
96
|
+
expect(screen.queryByText("Close Button")).toBeInTheDocument();
|
|
97
|
+
expect(screen.queryByText("Modal Heading Text")).toBeInTheDocument();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("renders the UI snapshot correctly", () => {
|
|
101
|
+
const basic = renderer.create(modalTrigger).toJSON();
|
|
102
|
+
|
|
103
|
+
expect(basic).toMatchSnapshot();
|
|
104
|
+
});
|
|
12
105
|
});
|
|
13
106
|
|
|
14
|
-
describe("
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
107
|
+
describe("useModal", () => {
|
|
108
|
+
const { result } = renderHook(() => useModal());
|
|
109
|
+
const { onClose, onOpen, Modal } = result.current;
|
|
110
|
+
const modalProps = {
|
|
111
|
+
bodyContent: (
|
|
112
|
+
<>
|
|
113
|
+
<Button id="custom-close" onClick={onClose}>
|
|
114
|
+
Go back
|
|
115
|
+
</Button>
|
|
116
|
+
<p>This is the body content.</p>
|
|
117
|
+
<Button id="custom-close2" onClick={onClose}>
|
|
118
|
+
This is a custom close button.
|
|
119
|
+
</Button>
|
|
120
|
+
</>
|
|
121
|
+
),
|
|
122
|
+
closeButtonLabel: "Close Button",
|
|
123
|
+
headingText: "Modal Heading Text",
|
|
124
|
+
onClose: () => {
|
|
125
|
+
console.log("custom close");
|
|
126
|
+
onClose();
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
const useModalComponent = (
|
|
130
|
+
<>
|
|
131
|
+
<Button id="1" onClick={onOpen} buttonType={ButtonTypes.NoBrand}>
|
|
132
|
+
Open Modal
|
|
133
|
+
</Button>
|
|
134
|
+
<Modal {...modalProps} />
|
|
135
|
+
</>
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
it("renders content when it is opened", () => {
|
|
139
|
+
render(useModalComponent);
|
|
140
|
+
const openButton = screen.getByText("Open Modal");
|
|
141
|
+
const closeButton = screen.queryByText("This is a custom close button.");
|
|
142
|
+
|
|
143
|
+
expect(openButton).toBeInTheDocument();
|
|
144
|
+
expect(closeButton).not.toBeInTheDocument();
|
|
145
|
+
expect(screen.queryByText("Modal Heading Text")).not.toBeInTheDocument();
|
|
146
|
+
|
|
147
|
+
openButton.click();
|
|
148
|
+
|
|
149
|
+
// TODO: Fix this test
|
|
150
|
+
// expect(openButton).toBeInTheDocument();
|
|
151
|
+
// expect(
|
|
152
|
+
// screen.queryByText("This is a custom close button.")
|
|
153
|
+
// ).toBeInTheDocument();
|
|
154
|
+
// expect(screen.queryByText("Modal Heading Text")).toBeInTheDocument();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("renders the UI snapshot correctly", () => {
|
|
158
|
+
const basic = renderer.create(useModalComponent).toJSON();
|
|
159
|
+
|
|
160
|
+
expect(basic).toMatchSnapshot();
|
|
19
161
|
});
|
|
20
162
|
});
|