@khanacademy/wonder-blocks-modal 3.0.6 → 3.0.8
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 +50 -0
- package/dist/components/close-button.d.ts +31 -0
- package/dist/components/close-button.js.flow +43 -0
- package/dist/components/focus-trap.d.ts +57 -0
- package/dist/components/focus-trap.js.flow +69 -0
- package/dist/components/modal-backdrop.d.ts +50 -0
- package/dist/components/modal-backdrop.js.flow +63 -0
- package/dist/components/modal-content.d.ts +23 -0
- package/dist/components/modal-content.js.flow +39 -0
- package/dist/components/modal-context.d.ts +6 -0
- package/dist/components/modal-context.js.flow +14 -0
- package/dist/components/modal-dialog.d.ts +60 -0
- package/dist/components/modal-dialog.js.flow +75 -0
- package/dist/components/modal-footer.d.ts +27 -0
- package/dist/components/modal-footer.js.flow +34 -0
- package/dist/components/modal-header.d.ts +93 -0
- package/dist/components/modal-header.js.flow +110 -0
- package/dist/components/modal-launcher.d.ts +17 -0
- package/dist/components/modal-launcher.js.flow +34 -0
- package/dist/components/modal-panel.d.ts +84 -0
- package/dist/components/modal-panel.js.flow +102 -0
- package/dist/components/one-pane-dialog.d.ts +124 -0
- package/dist/components/one-pane-dialog.js.flow +153 -0
- package/dist/components/scroll-disabler.d.ts +24 -0
- package/dist/components/scroll-disabler.js.flow +21 -0
- package/dist/es/index.js +222 -210
- package/dist/index.d.ts +8 -0
- package/dist/index.js +237 -226
- package/dist/index.js.flow +23 -2
- package/dist/util/constants.d.ts +5 -0
- package/dist/util/constants.js.flow +12 -0
- package/dist/util/find-focusable-nodes.d.ts +1 -0
- package/dist/util/find-focusable-nodes.js.flow +10 -0
- package/dist/util/maybe-get-portal-mounted-modal-host-element.d.ts +9 -0
- package/dist/util/maybe-get-portal-mounted-modal-host-element.js.flow +18 -0
- package/dist/util/types.d.ts +12 -0
- package/dist/util/types.js.flow +20 -0
- package/package.json +13 -13
- package/src/components/__tests__/{close-button.test.js → close-button.test.tsx} +3 -4
- package/src/components/__tests__/{focus-trap.test.js → focus-trap.test.tsx} +1 -2
- package/src/components/__tests__/{modal-backdrop.test.js → modal-backdrop.test.tsx} +2 -3
- package/src/components/__tests__/{modal-header.test.js → modal-header.test.tsx} +4 -3
- package/src/components/__tests__/{modal-launcher.test.js → modal-launcher.test.tsx} +13 -17
- package/src/components/__tests__/{modal-panel.test.js → modal-panel.test.tsx} +3 -4
- package/src/components/__tests__/{one-pane-dialog.test.js → one-pane-dialog.test.tsx} +1 -2
- package/src/components/{close-button.js → close-button.tsx} +8 -12
- package/src/components/{focus-trap.js → focus-trap.tsx} +12 -12
- package/src/components/{modal-backdrop.js → modal-backdrop.tsx} +23 -21
- package/src/components/{modal-content.js → modal-content.tsx} +11 -12
- package/src/components/modal-context.ts +13 -0
- package/src/components/{modal-dialog.js → modal-dialog.tsx} +15 -23
- package/src/components/{modal-footer.js → modal-footer.tsx} +5 -6
- package/src/components/{modal-header.js → modal-header.tsx} +20 -26
- package/src/components/{modal-launcher.js → modal-launcher.tsx} +43 -70
- package/src/components/{modal-panel.js → modal-panel.tsx} +31 -32
- package/src/components/{one-pane-dialog.js → one-pane-dialog.tsx} +40 -48
- package/src/components/{scroll-disabler.js → scroll-disabler.ts} +3 -4
- package/src/index.ts +17 -0
- package/src/util/{constants.js → constants.ts} +0 -2
- package/src/util/{find-focusable-nodes.js → find-focusable-nodes.ts} +0 -2
- package/src/util/{maybe-get-portal-mounted-modal-host-element.test.js → maybe-get-portal-mounted-modal-host-element.test.tsx} +8 -9
- package/src/util/{maybe-get-portal-mounted-modal-host-element.js → maybe-get-portal-mounted-modal-host-element.ts} +6 -5
- package/src/util/{types.js → types.ts} +3 -2
- package/tsconfig.json +20 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/src/components/__docs__/modal-dialog.stories.js +0 -308
- package/src/components/__docs__/modal-footer.stories.js +0 -337
- package/src/components/__docs__/modal-header.argtypes.js +0 -76
- package/src/components/__docs__/modal-header.stories.js +0 -294
- package/src/components/__docs__/modal-launcher.argtypes.js +0 -78
- package/src/components/__docs__/modal-launcher.stories.js +0 -513
- package/src/components/__docs__/modal-panel.stories.js +0 -414
- package/src/components/__docs__/one-pane-dialog.argtypes.js +0 -108
- package/src/components/__docs__/one-pane-dialog.stories.js +0 -582
- package/src/components/modal-context.js +0 -14
- package/src/index.js +0 -18
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Breadcrumbs } from "@khanacademy/wonder-blocks-breadcrumbs";
|
|
3
|
+
type Common = {
|
|
4
|
+
/**
|
|
5
|
+
* The main title rendered in larger bold text.
|
|
6
|
+
*/
|
|
7
|
+
title: string;
|
|
8
|
+
/**
|
|
9
|
+
* Whether to display the "light" version of this component instead, for
|
|
10
|
+
* use when the item is used on a dark background.
|
|
11
|
+
*/
|
|
12
|
+
light: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* An id to provide a selector for the title element.
|
|
15
|
+
*/
|
|
16
|
+
titleId: string;
|
|
17
|
+
/**
|
|
18
|
+
* Test ID used for e2e testing.
|
|
19
|
+
*
|
|
20
|
+
* In this case, this component is internal, so `testId` is composed with
|
|
21
|
+
* the `testId` passed down from the Dialog variant + a suffix to scope it
|
|
22
|
+
* to this component.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* For testId="some-random-id"
|
|
26
|
+
* The result will be: `some-random-id-modal-header`
|
|
27
|
+
*/
|
|
28
|
+
testId?: string;
|
|
29
|
+
};
|
|
30
|
+
type WithSubtitle = Common & {
|
|
31
|
+
/**
|
|
32
|
+
* The dialog subtitle.
|
|
33
|
+
*/
|
|
34
|
+
subtitle: string;
|
|
35
|
+
};
|
|
36
|
+
type WithBreadcrumbs = Common & {
|
|
37
|
+
/**
|
|
38
|
+
* Adds a breadcrumb-trail, appearing in the ModalHeader, above the title.
|
|
39
|
+
*/
|
|
40
|
+
breadcrumbs: React.ReactElement<React.ComponentProps<typeof Breadcrumbs>>;
|
|
41
|
+
};
|
|
42
|
+
type Props = Common | WithSubtitle | WithBreadcrumbs;
|
|
43
|
+
type DefaultProps = {
|
|
44
|
+
light: Props["light"];
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* This is a helper component that is never rendered by itself. It is always
|
|
48
|
+
* pinned to the top of the dialog, is responsive using the same behavior as its
|
|
49
|
+
* parent dialog, and has the following properties:
|
|
50
|
+
* - title
|
|
51
|
+
* - breadcrumb OR subtitle, but not both.
|
|
52
|
+
*
|
|
53
|
+
* **Accessibility notes:**
|
|
54
|
+
*
|
|
55
|
+
* - By default (e.g. using [OnePaneDialog](/#onepanedialog)), `titleId` is
|
|
56
|
+
* populated automatically by the parent container.
|
|
57
|
+
* - If there is a custom Dialog implementation (e.g. `TwoPaneDialog`), the
|
|
58
|
+
* ModalHeader doesn’t have to have the `titleId` prop however this is
|
|
59
|
+
* recommended. It should match the `aria-labelledby` prop of the
|
|
60
|
+
* [ModalDialog](/#modaldialog) component. If you want to see an example of
|
|
61
|
+
* how to generate this ID, check [IDProvider](/#idprovider).
|
|
62
|
+
*
|
|
63
|
+
* **Implementation notes:**
|
|
64
|
+
*
|
|
65
|
+
* If you are creating a custom Dialog, make sure to follow these guidelines:
|
|
66
|
+
* - Make sure to include it as part of [ModalPanel](/#modalpanel) by using the
|
|
67
|
+
* `header` prop.
|
|
68
|
+
* - Add a title (required).
|
|
69
|
+
* - Optionally add a subtitle or breadcrumbs.
|
|
70
|
+
* - We encourage you to add `titleId` (see Accessibility notes).
|
|
71
|
+
* - If the `ModalPanel` has a dark background, make sure to set `light` to
|
|
72
|
+
* `false`.
|
|
73
|
+
* - If you need to create e2e tests, make sure to pass a `testId` prop and
|
|
74
|
+
* add a sufix to scope the testId to this component: e.g.
|
|
75
|
+
* `some-random-id-ModalHeader`. This scope will also be passed to the title
|
|
76
|
+
* and subtitle elements: e.g. `some-random-id-ModalHeader-title`.
|
|
77
|
+
*
|
|
78
|
+
* Example:
|
|
79
|
+
*
|
|
80
|
+
* ```js
|
|
81
|
+
* <ModalHeader
|
|
82
|
+
* title="Sidebar using ModalHeader"
|
|
83
|
+
* subtitle="subtitle"
|
|
84
|
+
* titleId="uniqueTitleId"
|
|
85
|
+
* light={false}
|
|
86
|
+
* />
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export default class ModalHeader extends React.Component<Props> {
|
|
90
|
+
static defaultProps: DefaultProps;
|
|
91
|
+
render(): React.ReactElement;
|
|
92
|
+
}
|
|
93
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for modal-header
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import { Breadcrumbs } from "@khanacademy/wonder-blocks-breadcrumbs";
|
|
10
|
+
declare type Common = {
|
|
11
|
+
/**
|
|
12
|
+
* The main title rendered in larger bold text.
|
|
13
|
+
*/
|
|
14
|
+
title: string,
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Whether to display the "light" version of this component instead, for
|
|
18
|
+
* use when the item is used on a dark background.
|
|
19
|
+
*/
|
|
20
|
+
light: boolean,
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* An id to provide a selector for the title element.
|
|
24
|
+
*/
|
|
25
|
+
titleId: string,
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Test ID used for e2e testing.
|
|
29
|
+
*
|
|
30
|
+
* In this case, this component is internal, so `testId` is composed with
|
|
31
|
+
* the `testId` passed down from the Dialog variant + a suffix to scope it
|
|
32
|
+
* to this component.
|
|
33
|
+
* @example For testId="some-random-id"
|
|
34
|
+
* The result will be: `some-random-id-modal-header`
|
|
35
|
+
*/
|
|
36
|
+
testId?: string,
|
|
37
|
+
...
|
|
38
|
+
};
|
|
39
|
+
declare type WithSubtitle = {
|
|
40
|
+
...Common,
|
|
41
|
+
...{
|
|
42
|
+
/**
|
|
43
|
+
* The dialog subtitle.
|
|
44
|
+
*/
|
|
45
|
+
subtitle: string,
|
|
46
|
+
...
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
declare type WithBreadcrumbs = {
|
|
50
|
+
...Common,
|
|
51
|
+
...{
|
|
52
|
+
/**
|
|
53
|
+
* Adds a breadcrumb-trail, appearing in the ModalHeader, above the title.
|
|
54
|
+
*/
|
|
55
|
+
breadcrumbs: React.Element<React.ComponentProps<typeof Breadcrumbs>>,
|
|
56
|
+
...
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
declare type Props = Common | WithSubtitle | WithBreadcrumbs;
|
|
60
|
+
declare type DefaultProps = {
|
|
61
|
+
light: $PropertyType<Props, "light">,
|
|
62
|
+
...
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* This is a helper component that is never rendered by itself. It is always
|
|
66
|
+
* pinned to the top of the dialog, is responsive using the same behavior as its
|
|
67
|
+
* parent dialog, and has the following properties:
|
|
68
|
+
* - title
|
|
69
|
+
* - breadcrumb OR subtitle, but not both.
|
|
70
|
+
*
|
|
71
|
+
* **Accessibility notes:**
|
|
72
|
+
*
|
|
73
|
+
* - By default (e.g. using [OnePaneDialog](/#onepanedialog)), `titleId` is
|
|
74
|
+
* populated automatically by the parent container.
|
|
75
|
+
* - If there is a custom Dialog implementation (e.g. `TwoPaneDialog`), the
|
|
76
|
+
* ModalHeader doesn’t have to have the `titleId` prop however this is
|
|
77
|
+
* recommended. It should match the `aria-labelledby` prop of the
|
|
78
|
+
* [ModalDialog](/#modaldialog) component. If you want to see an example of
|
|
79
|
+
* how to generate this ID, check [IDProvider](/#idprovider).
|
|
80
|
+
*
|
|
81
|
+
* **Implementation notes:**
|
|
82
|
+
*
|
|
83
|
+
* If you are creating a custom Dialog, make sure to follow these guidelines:
|
|
84
|
+
* - Make sure to include it as part of [ModalPanel](/#modalpanel) by using the
|
|
85
|
+
* `header` prop.
|
|
86
|
+
* - Add a title (required).
|
|
87
|
+
* - Optionally add a subtitle or breadcrumbs.
|
|
88
|
+
* - We encourage you to add `titleId` (see Accessibility notes).
|
|
89
|
+
* - If the `ModalPanel` has a dark background, make sure to set `light` to
|
|
90
|
+
* `false`.
|
|
91
|
+
* - If you need to create e2e tests, make sure to pass a `testId` prop and
|
|
92
|
+
* add a sufix to scope the testId to this component: e.g.
|
|
93
|
+
* `some-random-id-ModalHeader`. This scope will also be passed to the title
|
|
94
|
+
* and subtitle elements: e.g. `some-random-id-ModalHeader-title`.
|
|
95
|
+
*
|
|
96
|
+
* Example:
|
|
97
|
+
*
|
|
98
|
+
* ```js
|
|
99
|
+
* <ModalHeader
|
|
100
|
+
* title="Sidebar using ModalHeader"
|
|
101
|
+
* subtitle="subtitle"
|
|
102
|
+
* titleId="uniqueTitleId"
|
|
103
|
+
* light={false}
|
|
104
|
+
* />
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
declare export default class ModalHeader mixins React.Component<Props> {
|
|
108
|
+
static defaultProps: DefaultProps;
|
|
109
|
+
render(): React.Element<>;
|
|
110
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { ModalElement } from "../util/types";
|
|
3
|
+
declare const _default: React.ForwardRefExoticComponent<{
|
|
4
|
+
children?: ((arg1: {
|
|
5
|
+
openModal: () => unknown;
|
|
6
|
+
}) => React.ReactNode) | undefined;
|
|
7
|
+
onClose?: (() => unknown) | undefined;
|
|
8
|
+
testId?: string | undefined;
|
|
9
|
+
initialFocusId?: string | undefined;
|
|
10
|
+
backdropDismissEnabled?: boolean | undefined;
|
|
11
|
+
opened?: boolean | undefined;
|
|
12
|
+
modal: ModalElement | React.FC<{
|
|
13
|
+
closeModal: () => void;
|
|
14
|
+
}>;
|
|
15
|
+
closedFocusId?: string | undefined;
|
|
16
|
+
} & React.RefAttributes<unknown>>;
|
|
17
|
+
export default _default;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for modal-launcher
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import type { ModalElement } from "../util/types";
|
|
10
|
+
declare var _default: React.ForwardRefExoticComponent<{
|
|
11
|
+
...{
|
|
12
|
+
children?:
|
|
13
|
+
| ((arg1: {
|
|
14
|
+
openModal: () => mixed,
|
|
15
|
+
...
|
|
16
|
+
}) => React.Node)
|
|
17
|
+
| void,
|
|
18
|
+
onClose?: (() => mixed) | void,
|
|
19
|
+
testId?: string | void,
|
|
20
|
+
initialFocusId?: string | void,
|
|
21
|
+
backdropDismissEnabled?: boolean | void,
|
|
22
|
+
opened?: boolean | void,
|
|
23
|
+
modal:
|
|
24
|
+
| ModalElement
|
|
25
|
+
| React.FC<{
|
|
26
|
+
closeModal: () => void,
|
|
27
|
+
...
|
|
28
|
+
}>,
|
|
29
|
+
closedFocusId?: string | void,
|
|
30
|
+
...
|
|
31
|
+
},
|
|
32
|
+
...React.RefAttributes<mixed>,
|
|
33
|
+
}>;
|
|
34
|
+
declare export default typeof _default;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { StyleType } from "@khanacademy/wonder-blocks-core";
|
|
3
|
+
import ModalContent from "./modal-content";
|
|
4
|
+
import ModalHeader from "./modal-header";
|
|
5
|
+
import ModalFooter from "./modal-footer";
|
|
6
|
+
type Props = {
|
|
7
|
+
/**
|
|
8
|
+
* The main contents of the ModalPanel. All other parts of the panel
|
|
9
|
+
* are positioned around it.
|
|
10
|
+
*/
|
|
11
|
+
content: React.ReactElement<React.ComponentProps<typeof ModalContent>> | React.ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* The modal header to show at the top of the panel.
|
|
14
|
+
*/
|
|
15
|
+
header?: React.ReactElement<React.ComponentProps<typeof ModalHeader>> | React.ReactNode;
|
|
16
|
+
/**
|
|
17
|
+
* A footer to show beneath the contents.
|
|
18
|
+
*/
|
|
19
|
+
footer?: React.ReactElement<React.ComponentProps<typeof ModalFooter>> | React.ReactNode;
|
|
20
|
+
/**
|
|
21
|
+
* When true, the close button is shown; otherwise, the close button is not shown.
|
|
22
|
+
*/
|
|
23
|
+
closeButtonVisible: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Should the contents of the panel become scrollable should they
|
|
26
|
+
* become too tall?
|
|
27
|
+
*/
|
|
28
|
+
scrollOverflow: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Whether to display the "light" version of this component instead, for
|
|
31
|
+
* use when the item is used on a dark background.
|
|
32
|
+
*/
|
|
33
|
+
light: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Any optional styling to apply to the panel.
|
|
36
|
+
*/
|
|
37
|
+
style?: StyleType;
|
|
38
|
+
/**
|
|
39
|
+
* Called when the close button is clicked.
|
|
40
|
+
*
|
|
41
|
+
* If you're using `ModalLauncher`, you should not use this prop!
|
|
42
|
+
* Instead, to listen for when the modal closes, add an `onClose` handler
|
|
43
|
+
* to the `ModalLauncher`. Doing so will throw an error.
|
|
44
|
+
*/
|
|
45
|
+
onClose?: () => unknown;
|
|
46
|
+
/**
|
|
47
|
+
* Test ID used for e2e testing.
|
|
48
|
+
*
|
|
49
|
+
* In this case, this `testId` comes from the `testId` prop defined in the
|
|
50
|
+
* Dialog variant (e.g. OnePaneDialog).
|
|
51
|
+
*/
|
|
52
|
+
testId?: string;
|
|
53
|
+
};
|
|
54
|
+
type DefaultProps = {
|
|
55
|
+
closeButtonVisible: Props["closeButtonVisible"];
|
|
56
|
+
scrollOverflow: Props["scrollOverflow"];
|
|
57
|
+
light: Props["light"];
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* ModalPanel is the content container.
|
|
61
|
+
*
|
|
62
|
+
* **Implementation notes:**
|
|
63
|
+
*
|
|
64
|
+
* If you are creating a custom Dialog, make sure to follow these guidelines:
|
|
65
|
+
* - Make sure to add this component inside the [ModalDialog](/#modaldialog).
|
|
66
|
+
* - If needed, you can also add a [ModalHeader](/#modalheader) using the
|
|
67
|
+
* `header` prop. Same goes for [ModalFooter](/#modalfooter).
|
|
68
|
+
* - If you need to create e2e tests, make sure to pass a `testId` prop. This
|
|
69
|
+
* will be passed down to this component using a sufix: e.g.
|
|
70
|
+
* `some-random-id-ModalPanel`. This scope will be propagated to the
|
|
71
|
+
* CloseButton element as well: e.g. `some-random-id-CloseButton`.
|
|
72
|
+
*
|
|
73
|
+
* ```js
|
|
74
|
+
* <ModalDialog>
|
|
75
|
+
* <ModalPanel content={"custom content goes here"} />
|
|
76
|
+
* </ModalDialog>
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export default class ModalPanel extends React.Component<Props> {
|
|
80
|
+
static defaultProps: DefaultProps;
|
|
81
|
+
renderMainContent(): React.ReactNode;
|
|
82
|
+
render(): React.ReactElement;
|
|
83
|
+
}
|
|
84
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for modal-panel
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import type { StyleType } from "@khanacademy/wonder-blocks-core";
|
|
10
|
+
import ModalContent from "./modal-content";
|
|
11
|
+
import ModalHeader from "./modal-header";
|
|
12
|
+
import ModalFooter from "./modal-footer";
|
|
13
|
+
declare type Props = {
|
|
14
|
+
/**
|
|
15
|
+
* The main contents of the ModalPanel. All other parts of the panel
|
|
16
|
+
* are positioned around it.
|
|
17
|
+
*/
|
|
18
|
+
content:
|
|
19
|
+
| React.Element<React.ComponentProps<typeof ModalContent>>
|
|
20
|
+
| React.Node,
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The modal header to show at the top of the panel.
|
|
24
|
+
*/
|
|
25
|
+
header?: React.Element<React.ComponentProps<typeof ModalHeader>> | React.Node,
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A footer to show beneath the contents.
|
|
29
|
+
*/
|
|
30
|
+
footer?: React.Element<React.ComponentProps<typeof ModalFooter>> | React.Node,
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* When true, the close button is shown; otherwise, the close button is not shown.
|
|
34
|
+
*/
|
|
35
|
+
closeButtonVisible: boolean,
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Should the contents of the panel become scrollable should they
|
|
39
|
+
* become too tall?
|
|
40
|
+
*/
|
|
41
|
+
scrollOverflow: boolean,
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Whether to display the "light" version of this component instead, for
|
|
45
|
+
* use when the item is used on a dark background.
|
|
46
|
+
*/
|
|
47
|
+
light: boolean,
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Any optional styling to apply to the panel.
|
|
51
|
+
*/
|
|
52
|
+
style?: StyleType,
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Called when the close button is clicked.
|
|
56
|
+
*
|
|
57
|
+
* If you're using `ModalLauncher`, you should not use this prop!
|
|
58
|
+
* Instead, to listen for when the modal closes, add an `onClose` handler
|
|
59
|
+
* to the `ModalLauncher`. Doing so will throw an error.
|
|
60
|
+
*/
|
|
61
|
+
onClose?: () => mixed,
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Test ID used for e2e testing.
|
|
65
|
+
*
|
|
66
|
+
* In this case, this `testId` comes from the `testId` prop defined in the
|
|
67
|
+
* Dialog variant (e.g. OnePaneDialog).
|
|
68
|
+
*/
|
|
69
|
+
testId?: string,
|
|
70
|
+
...
|
|
71
|
+
};
|
|
72
|
+
declare type DefaultProps = {
|
|
73
|
+
closeButtonVisible: $PropertyType<Props, "closeButtonVisible">,
|
|
74
|
+
scrollOverflow: $PropertyType<Props, "scrollOverflow">,
|
|
75
|
+
light: $PropertyType<Props, "light">,
|
|
76
|
+
...
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* ModalPanel is the content container.
|
|
80
|
+
*
|
|
81
|
+
* **Implementation notes:**
|
|
82
|
+
*
|
|
83
|
+
* If you are creating a custom Dialog, make sure to follow these guidelines:
|
|
84
|
+
* - Make sure to add this component inside the [ModalDialog](/#modaldialog).
|
|
85
|
+
* - If needed, you can also add a [ModalHeader](/#modalheader) using the
|
|
86
|
+
* `header` prop. Same goes for [ModalFooter](/#modalfooter).
|
|
87
|
+
* - If you need to create e2e tests, make sure to pass a `testId` prop. This
|
|
88
|
+
* will be passed down to this component using a sufix: e.g.
|
|
89
|
+
* `some-random-id-ModalPanel`. This scope will be propagated to the
|
|
90
|
+
* CloseButton element as well: e.g. `some-random-id-CloseButton`.
|
|
91
|
+
*
|
|
92
|
+
* ```js
|
|
93
|
+
* <ModalDialog>
|
|
94
|
+
* <ModalPanel content={"custom content goes here"} />
|
|
95
|
+
* </ModalDialog>
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
declare export default class ModalPanel mixins React.Component<Props> {
|
|
99
|
+
static defaultProps: DefaultProps;
|
|
100
|
+
renderMainContent(): React.Node;
|
|
101
|
+
render(): React.Element<>;
|
|
102
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Breadcrumbs } from "@khanacademy/wonder-blocks-breadcrumbs";
|
|
3
|
+
import type { StyleType } from "@khanacademy/wonder-blocks-core";
|
|
4
|
+
import ModalHeader from "./modal-header";
|
|
5
|
+
type Common = {
|
|
6
|
+
/**
|
|
7
|
+
* The content of the modal, appearing between the titlebar and footer.
|
|
8
|
+
*/
|
|
9
|
+
content: React.ReactNode;
|
|
10
|
+
/**
|
|
11
|
+
* The title of the modal, appearing in the titlebar.
|
|
12
|
+
*/
|
|
13
|
+
title: string;
|
|
14
|
+
/**
|
|
15
|
+
* The content of the modal's footer. A great place for buttons!
|
|
16
|
+
*
|
|
17
|
+
* Content is right-aligned by default. To control alignment yourself,
|
|
18
|
+
* provide a container element with 100% width.
|
|
19
|
+
*/
|
|
20
|
+
footer?: React.ReactNode;
|
|
21
|
+
/**
|
|
22
|
+
* Called when the close button is clicked.
|
|
23
|
+
*
|
|
24
|
+
* If you're using `ModalLauncher`, you probably shouldn't use this prop!
|
|
25
|
+
* Instead, to listen for when the modal closes, add an `onClose` handler
|
|
26
|
+
* to the `ModalLauncher`. Doing so will result in a console.warn().
|
|
27
|
+
*/
|
|
28
|
+
onClose?: () => unknown;
|
|
29
|
+
/**
|
|
30
|
+
* When true, the close button is shown; otherwise, the close button is not shown.
|
|
31
|
+
*/
|
|
32
|
+
closeButtonVisible?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* When set, provides a component that can render content above the top of the modal;
|
|
35
|
+
* when not set, no additional content is shown above the modal.
|
|
36
|
+
* This prop is passed down to the ModalDialog.
|
|
37
|
+
*/
|
|
38
|
+
above?: React.ReactNode;
|
|
39
|
+
/**
|
|
40
|
+
* When set, provides a component that will render content below the bottom of the modal;
|
|
41
|
+
* when not set, no additional content is shown below the modal.
|
|
42
|
+
* This prop is passed down to the ModalDialog.
|
|
43
|
+
*
|
|
44
|
+
* NOTE: Devs can customize this content by rendering the component assigned to this prop with custom styles,
|
|
45
|
+
* such as by wrapping it in a View.
|
|
46
|
+
*/
|
|
47
|
+
below?: React.ReactNode;
|
|
48
|
+
/**
|
|
49
|
+
* When set, overrides the default role value. Default role is "dialog"
|
|
50
|
+
* Roles other than dialog and alertdialog aren't appropriate for this
|
|
51
|
+
* component
|
|
52
|
+
*/
|
|
53
|
+
role?: "dialog" | "alertdialog";
|
|
54
|
+
/**
|
|
55
|
+
* Optional custom styles.
|
|
56
|
+
*/
|
|
57
|
+
style?: StyleType;
|
|
58
|
+
/**
|
|
59
|
+
* Test ID used for e2e testing. This ID will be passed down to the Dialog.
|
|
60
|
+
*/
|
|
61
|
+
testId?: string;
|
|
62
|
+
/**
|
|
63
|
+
* An optional id parameter for the title. If one is
|
|
64
|
+
* not provided, a unique id will be generated.
|
|
65
|
+
*/
|
|
66
|
+
titleId?: string;
|
|
67
|
+
/**
|
|
68
|
+
* The ID of the content describing this dialog, if applicable.
|
|
69
|
+
*/
|
|
70
|
+
["aria-describedby"]?: string;
|
|
71
|
+
};
|
|
72
|
+
type WithSubtitle = Common & {
|
|
73
|
+
/**
|
|
74
|
+
* The subtitle of the modal, appearing in the titlebar, below the title.
|
|
75
|
+
*/
|
|
76
|
+
subtitle: string;
|
|
77
|
+
};
|
|
78
|
+
type WithBreadcrumbs = Common & {
|
|
79
|
+
/**
|
|
80
|
+
* Adds a breadcrumb-trail, appearing in the ModalHeader, above the title.
|
|
81
|
+
*/
|
|
82
|
+
breadcrumbs: React.ReactElement<React.ComponentProps<typeof Breadcrumbs>>;
|
|
83
|
+
};
|
|
84
|
+
type Props = Common | WithSubtitle | WithBreadcrumbs;
|
|
85
|
+
type DefaultProps = {
|
|
86
|
+
closeButtonVisible: Props["closeButtonVisible"];
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* This is the standard layout for most straightforward modal experiences.
|
|
90
|
+
*
|
|
91
|
+
* The ModalHeader is required, but the ModalFooter is optional.
|
|
92
|
+
* The content of the dialog itself is fully customizable, but the
|
|
93
|
+
* left/right/top/bottom padding is fixed.
|
|
94
|
+
*
|
|
95
|
+
* ### Usage
|
|
96
|
+
*
|
|
97
|
+
* ```jsx
|
|
98
|
+
* import {OnePaneDialog} from "@khanacademy/wonder-blocks-modal";
|
|
99
|
+
* import {Body} from "@khanacademy/wonder-blocks-typography";
|
|
100
|
+
*
|
|
101
|
+
* <OnePaneDialog
|
|
102
|
+
* title="Some title"
|
|
103
|
+
* content={
|
|
104
|
+
* <Body>
|
|
105
|
+
* {`Lorem ipsum dolor sit amet, consectetur adipiscing
|
|
106
|
+
* elit, sed do eiusmod tempor incididunt ut labore et
|
|
107
|
+
* dolore magna aliqua. Ut enim ad minim veniam,
|
|
108
|
+
* quis nostrud exercitation ullamco laboris nisi ut
|
|
109
|
+
* aliquip ex ea commodo consequat. Duis aute irure
|
|
110
|
+
* dolor in reprehenderit in voluptate velit esse
|
|
111
|
+
* cillum dolore eu fugiat nulla pariatur. Excepteur
|
|
112
|
+
* sint occaecat cupidatat non proident, sunt in culpa
|
|
113
|
+
* qui officia deserunt mollit anim id est.`}
|
|
114
|
+
* </Body>
|
|
115
|
+
* }
|
|
116
|
+
* />
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export default class OnePaneDialog extends React.Component<Props> {
|
|
120
|
+
static defaultProps: DefaultProps;
|
|
121
|
+
renderHeader(uniqueId: string): React.ReactElement<React.ComponentProps<typeof ModalHeader>>;
|
|
122
|
+
render(): React.ReactElement;
|
|
123
|
+
}
|
|
124
|
+
export {};
|