@internetarchive/modal-manager 0.2.8 → 0.2.9-alpha.2
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/.editorconfig +29 -29
- package/.eslintrc.js +14 -14
- package/.github/workflows/ci.yml +26 -26
- package/LICENSE +661 -661
- package/README.md +139 -139
- package/custom-elements.json +170 -170
- package/demo/index.html +278 -278
- package/dist/index.d.ts +7 -7
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/src/modal-config.d.ts +92 -92
- package/dist/src/modal-config.js +22 -22
- package/dist/src/modal-config.js.map +1 -1
- package/dist/src/modal-manager-host-bridge-interface.d.ts +12 -12
- package/dist/src/modal-manager-host-bridge-interface.js.map +1 -1
- package/dist/src/modal-manager-host-bridge.d.ts +34 -34
- package/dist/src/modal-manager-host-bridge.js +62 -62
- package/dist/src/modal-manager-host-bridge.js.map +1 -1
- package/dist/src/modal-manager-interface.d.ts +25 -25
- package/dist/src/modal-manager-interface.js.map +1 -1
- package/dist/src/modal-manager-mode.d.ts +10 -10
- package/dist/src/modal-manager-mode.js +11 -11
- package/dist/src/modal-manager-mode.js.map +1 -1
- package/dist/src/modal-manager.d.ts +108 -108
- package/dist/src/modal-manager.js +189 -189
- package/dist/src/modal-manager.js.map +1 -1
- package/dist/src/modal-template.d.ts +32 -32
- package/dist/src/modal-template.js +276 -276
- package/dist/src/modal-template.js.map +1 -1
- package/dist/test/modal-config.test.d.ts +1 -1
- package/dist/test/modal-config.test.js +61 -61
- package/dist/test/modal-config.test.js.map +1 -1
- package/dist/test/modal-manager.test.d.ts +1 -1
- package/dist/test/modal-manager.test.js +200 -200
- package/dist/test/modal-manager.test.js.map +1 -1
- package/dist/test/modal-template.test.d.ts +1 -1
- package/dist/test/modal-template.test.js +95 -95
- package/dist/test/modal-template.test.js.map +1 -1
- package/docs/assets/css/main.css +2678 -2678
- package/docs/classes/_src_modal_config_.modalconfig.html +429 -429
- package/docs/classes/_src_modal_manager_.modalmanager.html +7702 -7702
- package/docs/classes/_src_modal_manager_host_bridge_.modalmanagerhostbridge.html +409 -409
- package/docs/classes/_src_modal_template_.modaltemplate.html +7096 -7096
- package/docs/enums/_src_modal_manager_mode_.modalmanagermode.html +196 -196
- package/docs/globals.html +150 -150
- package/docs/index.html +252 -252
- package/docs/interfaces/_src_modal_manager_host_bridge_interface_.modalmanagerhostbridgeinterface.html +210 -210
- package/docs/interfaces/_src_modal_manager_interface_.modalmanagerinterface.html +7095 -7095
- package/docs/modules/_index_.html +208 -208
- package/docs/modules/_src_modal_config_.html +146 -146
- package/docs/modules/_src_modal_manager_.html +146 -146
- package/docs/modules/_src_modal_manager_host_bridge_.html +146 -146
- package/docs/modules/_src_modal_manager_host_bridge_interface_.html +146 -146
- package/docs/modules/_src_modal_manager_interface_.html +146 -146
- package/docs/modules/_src_modal_manager_mode_.html +146 -146
- package/docs/modules/_src_modal_template_.html +146 -146
- package/docs/modules/_test_modal_config_test_.html +106 -106
- package/docs/modules/_test_modal_manager_test_.html +106 -106
- package/docs/modules/_test_modal_template_test_.html +106 -106
- package/index.ts +7 -7
- package/karma.conf.js +24 -24
- package/package.json +82 -82
- package/src/modal-config.ts +117 -117
- package/src/modal-manager-host-bridge-interface.ts +13 -13
- package/src/modal-manager-host-bridge.ts +82 -82
- package/src/modal-manager-interface.ts +28 -28
- package/src/modal-manager-mode.ts +10 -10
- package/src/modal-manager.ts +228 -228
- package/src/modal-template.ts +279 -279
- package/test/modal-config.test.ts +69 -69
- package/test/modal-manager.test.ts +245 -245
- package/test/modal-template.test.ts +111 -111
- package/tsconfig.json +20 -20
|
@@ -1,108 +1,108 @@
|
|
|
1
|
-
import { LitElement, CSSResult, TemplateResult, PropertyValues } from 'lit';
|
|
2
|
-
import './modal-template';
|
|
3
|
-
import { ModalConfig } from './modal-config';
|
|
4
|
-
import { ModalManagerInterface } from './modal-manager-interface';
|
|
5
|
-
import { ModalManagerHostBridgeInterface } from './modal-manager-host-bridge-interface';
|
|
6
|
-
import { ModalManagerMode } from './modal-manager-mode';
|
|
7
|
-
export declare class ModalManager extends LitElement implements ModalManagerInterface {
|
|
8
|
-
/**
|
|
9
|
-
* The current mode of the ModalManager
|
|
10
|
-
*
|
|
11
|
-
* Current options are `modal` or `closed`
|
|
12
|
-
*
|
|
13
|
-
* @type {ModalManagerMode}
|
|
14
|
-
* @memberof ModalManager
|
|
15
|
-
*/
|
|
16
|
-
mode: ModalManagerMode;
|
|
17
|
-
/**
|
|
18
|
-
* Custom content to display in the modal's content slot
|
|
19
|
-
*
|
|
20
|
-
* @type {(TemplateResult | undefined)}
|
|
21
|
-
* @memberof ModalManager
|
|
22
|
-
*/
|
|
23
|
-
customModalContent?: TemplateResult;
|
|
24
|
-
/**
|
|
25
|
-
* Thie hostBridge handles environmental-specific interactions such as adding classes
|
|
26
|
-
* to the body tag or event listeners needed to support the modal manager in the host environment.
|
|
27
|
-
*
|
|
28
|
-
* There is a default `ModalManagerHostBridge`, but consumers can override it with a custom
|
|
29
|
-
* `ModalManagerHostBridgeInterface`
|
|
30
|
-
*
|
|
31
|
-
* @type {ModalManagerHostBridgeInterface}
|
|
32
|
-
* @memberof ModalManager
|
|
33
|
-
*/
|
|
34
|
-
hostBridge: ModalManagerHostBridgeInterface;
|
|
35
|
-
/**
|
|
36
|
-
* Reference to the ModalTemplate DOM element
|
|
37
|
-
*
|
|
38
|
-
* @private
|
|
39
|
-
* @type {ModalTemplate}
|
|
40
|
-
* @memberof ModalManager
|
|
41
|
-
*/
|
|
42
|
-
private modalTemplate;
|
|
43
|
-
/** @inheritdoc */
|
|
44
|
-
render(): TemplateResult;
|
|
45
|
-
/** @inheritdoc */
|
|
46
|
-
getMode(): ModalManagerMode;
|
|
47
|
-
/** @inheritdoc */
|
|
48
|
-
closeModal(): void;
|
|
49
|
-
/**
|
|
50
|
-
* Whether the modal should close if the user taps on the backdrop
|
|
51
|
-
*
|
|
52
|
-
* @private
|
|
53
|
-
* @memberof ModalManager
|
|
54
|
-
*/
|
|
55
|
-
private closeOnBackdropClick;
|
|
56
|
-
/**
|
|
57
|
-
* A callback if the user closes the modal
|
|
58
|
-
*
|
|
59
|
-
* @private
|
|
60
|
-
* @memberof ModalManager
|
|
61
|
-
*/
|
|
62
|
-
private userClosedModalCallback?;
|
|
63
|
-
/**
|
|
64
|
-
* Call the userClosedModalCallback and reset it if it exists
|
|
65
|
-
*
|
|
66
|
-
* @private
|
|
67
|
-
* @memberof ModalManager
|
|
68
|
-
*/
|
|
69
|
-
private callUserClosedModalCallback;
|
|
70
|
-
/** @inheritdoc */
|
|
71
|
-
showModal(options: {
|
|
72
|
-
config: ModalConfig;
|
|
73
|
-
customModalContent?: TemplateResult;
|
|
74
|
-
userClosedModalCallback?: () => void;
|
|
75
|
-
}): Promise<void>;
|
|
76
|
-
/** @inheritdoc */
|
|
77
|
-
updated(changed: PropertyValues): void;
|
|
78
|
-
/**
|
|
79
|
-
* Called when the backdrop is clicked
|
|
80
|
-
*
|
|
81
|
-
* @private
|
|
82
|
-
* @memberof ModalManager
|
|
83
|
-
*/
|
|
84
|
-
private backdropClicked;
|
|
85
|
-
/**
|
|
86
|
-
* Handle the mode change
|
|
87
|
-
*
|
|
88
|
-
* @private
|
|
89
|
-
* @memberof ModalManager
|
|
90
|
-
*/
|
|
91
|
-
private handleModeChange;
|
|
92
|
-
/**
|
|
93
|
-
* Emit a modeChange event
|
|
94
|
-
*
|
|
95
|
-
* @private
|
|
96
|
-
* @memberof ModalManager
|
|
97
|
-
*/
|
|
98
|
-
private emitModeChangeEvent;
|
|
99
|
-
/**
|
|
100
|
-
* Called when the modal close button is pressed. Closes the modal.
|
|
101
|
-
*
|
|
102
|
-
* @private
|
|
103
|
-
* @memberof ModalManager
|
|
104
|
-
*/
|
|
105
|
-
private closeButtonPressed;
|
|
106
|
-
/** @inheritdoc */
|
|
107
|
-
static get styles(): CSSResult;
|
|
108
|
-
}
|
|
1
|
+
import { LitElement, CSSResult, TemplateResult, PropertyValues } from 'lit';
|
|
2
|
+
import './modal-template';
|
|
3
|
+
import { ModalConfig } from './modal-config';
|
|
4
|
+
import { ModalManagerInterface } from './modal-manager-interface';
|
|
5
|
+
import { ModalManagerHostBridgeInterface } from './modal-manager-host-bridge-interface';
|
|
6
|
+
import { ModalManagerMode } from './modal-manager-mode';
|
|
7
|
+
export declare class ModalManager extends LitElement implements ModalManagerInterface {
|
|
8
|
+
/**
|
|
9
|
+
* The current mode of the ModalManager
|
|
10
|
+
*
|
|
11
|
+
* Current options are `modal` or `closed`
|
|
12
|
+
*
|
|
13
|
+
* @type {ModalManagerMode}
|
|
14
|
+
* @memberof ModalManager
|
|
15
|
+
*/
|
|
16
|
+
mode: ModalManagerMode;
|
|
17
|
+
/**
|
|
18
|
+
* Custom content to display in the modal's content slot
|
|
19
|
+
*
|
|
20
|
+
* @type {(TemplateResult | undefined)}
|
|
21
|
+
* @memberof ModalManager
|
|
22
|
+
*/
|
|
23
|
+
customModalContent?: TemplateResult;
|
|
24
|
+
/**
|
|
25
|
+
* Thie hostBridge handles environmental-specific interactions such as adding classes
|
|
26
|
+
* to the body tag or event listeners needed to support the modal manager in the host environment.
|
|
27
|
+
*
|
|
28
|
+
* There is a default `ModalManagerHostBridge`, but consumers can override it with a custom
|
|
29
|
+
* `ModalManagerHostBridgeInterface`
|
|
30
|
+
*
|
|
31
|
+
* @type {ModalManagerHostBridgeInterface}
|
|
32
|
+
* @memberof ModalManager
|
|
33
|
+
*/
|
|
34
|
+
hostBridge: ModalManagerHostBridgeInterface;
|
|
35
|
+
/**
|
|
36
|
+
* Reference to the ModalTemplate DOM element
|
|
37
|
+
*
|
|
38
|
+
* @private
|
|
39
|
+
* @type {ModalTemplate}
|
|
40
|
+
* @memberof ModalManager
|
|
41
|
+
*/
|
|
42
|
+
private modalTemplate;
|
|
43
|
+
/** @inheritdoc */
|
|
44
|
+
render(): TemplateResult;
|
|
45
|
+
/** @inheritdoc */
|
|
46
|
+
getMode(): ModalManagerMode;
|
|
47
|
+
/** @inheritdoc */
|
|
48
|
+
closeModal(): void;
|
|
49
|
+
/**
|
|
50
|
+
* Whether the modal should close if the user taps on the backdrop
|
|
51
|
+
*
|
|
52
|
+
* @private
|
|
53
|
+
* @memberof ModalManager
|
|
54
|
+
*/
|
|
55
|
+
private closeOnBackdropClick;
|
|
56
|
+
/**
|
|
57
|
+
* A callback if the user closes the modal
|
|
58
|
+
*
|
|
59
|
+
* @private
|
|
60
|
+
* @memberof ModalManager
|
|
61
|
+
*/
|
|
62
|
+
private userClosedModalCallback?;
|
|
63
|
+
/**
|
|
64
|
+
* Call the userClosedModalCallback and reset it if it exists
|
|
65
|
+
*
|
|
66
|
+
* @private
|
|
67
|
+
* @memberof ModalManager
|
|
68
|
+
*/
|
|
69
|
+
private callUserClosedModalCallback;
|
|
70
|
+
/** @inheritdoc */
|
|
71
|
+
showModal(options: {
|
|
72
|
+
config: ModalConfig;
|
|
73
|
+
customModalContent?: TemplateResult;
|
|
74
|
+
userClosedModalCallback?: () => void;
|
|
75
|
+
}): Promise<void>;
|
|
76
|
+
/** @inheritdoc */
|
|
77
|
+
updated(changed: PropertyValues): void;
|
|
78
|
+
/**
|
|
79
|
+
* Called when the backdrop is clicked
|
|
80
|
+
*
|
|
81
|
+
* @private
|
|
82
|
+
* @memberof ModalManager
|
|
83
|
+
*/
|
|
84
|
+
private backdropClicked;
|
|
85
|
+
/**
|
|
86
|
+
* Handle the mode change
|
|
87
|
+
*
|
|
88
|
+
* @private
|
|
89
|
+
* @memberof ModalManager
|
|
90
|
+
*/
|
|
91
|
+
private handleModeChange;
|
|
92
|
+
/**
|
|
93
|
+
* Emit a modeChange event
|
|
94
|
+
*
|
|
95
|
+
* @private
|
|
96
|
+
* @memberof ModalManager
|
|
97
|
+
*/
|
|
98
|
+
private emitModeChangeEvent;
|
|
99
|
+
/**
|
|
100
|
+
* Called when the modal close button is pressed. Closes the modal.
|
|
101
|
+
*
|
|
102
|
+
* @private
|
|
103
|
+
* @memberof ModalManager
|
|
104
|
+
*/
|
|
105
|
+
private closeButtonPressed;
|
|
106
|
+
/** @inheritdoc */
|
|
107
|
+
static get styles(): CSSResult;
|
|
108
|
+
}
|
|
@@ -1,190 +1,190 @@
|
|
|
1
|
-
import { __awaiter, __decorate } from "tslib";
|
|
2
|
-
import { LitElement, html, css, } from 'lit';
|
|
3
|
-
import { property, customElement, query } from 'lit/decorators.js';
|
|
4
|
-
import './modal-template';
|
|
5
|
-
import { ModalManagerHostBridge } from './modal-manager-host-bridge';
|
|
6
|
-
import { ModalManagerMode } from './modal-manager-mode';
|
|
7
|
-
let ModalManager = class ModalManager extends LitElement {
|
|
8
|
-
constructor() {
|
|
9
|
-
super(...arguments);
|
|
10
|
-
/**
|
|
11
|
-
* The current mode of the ModalManager
|
|
12
|
-
*
|
|
13
|
-
* Current options are `modal` or `closed`
|
|
14
|
-
*
|
|
15
|
-
* @type {ModalManagerMode}
|
|
16
|
-
* @memberof ModalManager
|
|
17
|
-
*/
|
|
18
|
-
this.mode = ModalManagerMode.Closed;
|
|
19
|
-
/**
|
|
20
|
-
* Thie hostBridge handles environmental-specific interactions such as adding classes
|
|
21
|
-
* to the body tag or event listeners needed to support the modal manager in the host environment.
|
|
22
|
-
*
|
|
23
|
-
* There is a default `ModalManagerHostBridge`, but consumers can override it with a custom
|
|
24
|
-
* `ModalManagerHostBridgeInterface`
|
|
25
|
-
*
|
|
26
|
-
* @type {ModalManagerHostBridgeInterface}
|
|
27
|
-
* @memberof ModalManager
|
|
28
|
-
*/
|
|
29
|
-
this.hostBridge = new ModalManagerHostBridge(this);
|
|
30
|
-
/**
|
|
31
|
-
* Whether the modal should close if the user taps on the backdrop
|
|
32
|
-
*
|
|
33
|
-
* @private
|
|
34
|
-
* @memberof ModalManager
|
|
35
|
-
*/
|
|
36
|
-
this.closeOnBackdropClick = true;
|
|
37
|
-
}
|
|
38
|
-
/** @inheritdoc */
|
|
39
|
-
render() {
|
|
40
|
-
return html `
|
|
41
|
-
<div class="container">
|
|
42
|
-
<div class="backdrop" @click=${this.backdropClicked}></div>
|
|
43
|
-
<modal-template
|
|
44
|
-
@closeButtonPressed=${this.closeButtonPressed}
|
|
45
|
-
tabindex="0"
|
|
46
|
-
>
|
|
47
|
-
${this.customModalContent}
|
|
48
|
-
</modal-template>
|
|
49
|
-
</div>
|
|
50
|
-
`;
|
|
51
|
-
}
|
|
52
|
-
/** @inheritdoc */
|
|
53
|
-
getMode() {
|
|
54
|
-
return this.mode;
|
|
55
|
-
}
|
|
56
|
-
/** @inheritdoc */
|
|
57
|
-
closeModal() {
|
|
58
|
-
this.mode = ModalManagerMode.Closed;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Call the userClosedModalCallback and reset it if it exists
|
|
62
|
-
*
|
|
63
|
-
* @private
|
|
64
|
-
* @memberof ModalManager
|
|
65
|
-
*/
|
|
66
|
-
callUserClosedModalCallback() {
|
|
67
|
-
// we assign the callback to a temp var and undefine it before calling it
|
|
68
|
-
// otherwise, we run into the potential for an infinite loop if the
|
|
69
|
-
// callback triggers another `showModal()`, which would execute `userClosedModalCallback`
|
|
70
|
-
const callback = this.userClosedModalCallback;
|
|
71
|
-
this.userClosedModalCallback = undefined;
|
|
72
|
-
if (callback)
|
|
73
|
-
callback();
|
|
74
|
-
}
|
|
75
|
-
/** @inheritdoc */
|
|
76
|
-
showModal(options) {
|
|
77
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
this.closeOnBackdropClick = options.config.closeOnBackdropClick;
|
|
79
|
-
this.userClosedModalCallback = options.userClosedModalCallback;
|
|
80
|
-
this.modalTemplate.config = options.config;
|
|
81
|
-
this.customModalContent = options.customModalContent;
|
|
82
|
-
this.mode = ModalManagerMode.Open;
|
|
83
|
-
yield this.modalTemplate.updateComplete;
|
|
84
|
-
this.modalTemplate.focus();
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
/** @inheritdoc */
|
|
88
|
-
updated(changed) {
|
|
89
|
-
/* istanbul ignore else */
|
|
90
|
-
if (changed.has('mode')) {
|
|
91
|
-
this.handleModeChange();
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Called when the backdrop is clicked
|
|
96
|
-
*
|
|
97
|
-
* @private
|
|
98
|
-
* @memberof ModalManager
|
|
99
|
-
*/
|
|
100
|
-
backdropClicked() {
|
|
101
|
-
if (this.closeOnBackdropClick) {
|
|
102
|
-
this.closeModal();
|
|
103
|
-
this.callUserClosedModalCallback();
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Handle the mode change
|
|
108
|
-
*
|
|
109
|
-
* @private
|
|
110
|
-
* @memberof ModalManager
|
|
111
|
-
*/
|
|
112
|
-
handleModeChange() {
|
|
113
|
-
this.hostBridge.handleModeChange(this.mode);
|
|
114
|
-
this.emitModeChangeEvent();
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Emit a modeChange event
|
|
118
|
-
*
|
|
119
|
-
* @private
|
|
120
|
-
* @memberof ModalManager
|
|
121
|
-
*/
|
|
122
|
-
emitModeChangeEvent() {
|
|
123
|
-
const event = new CustomEvent('modeChanged', {
|
|
124
|
-
detail: { mode: this.mode },
|
|
125
|
-
});
|
|
126
|
-
this.dispatchEvent(event);
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Called when the modal close button is pressed. Closes the modal.
|
|
130
|
-
*
|
|
131
|
-
* @private
|
|
132
|
-
* @memberof ModalManager
|
|
133
|
-
*/
|
|
134
|
-
closeButtonPressed() {
|
|
135
|
-
this.closeModal();
|
|
136
|
-
this.callUserClosedModalCallback();
|
|
137
|
-
}
|
|
138
|
-
/** @inheritdoc */
|
|
139
|
-
static get styles() {
|
|
140
|
-
const modalBackdropColor = css `var(--modalBackdropColor, rgba(10, 10, 10, 0.9))`;
|
|
141
|
-
const modalBackdropZindex = css `var(--modalBackdropZindex, 1000)`;
|
|
142
|
-
const modalWidth = css `var(--modalWidth, 32rem)`;
|
|
143
|
-
const modalMaxWidth = css `var(--modalMaxWidth, 95%)`;
|
|
144
|
-
const modalZindex = css `var(--modalZindex, 2000)`;
|
|
145
|
-
return css `
|
|
146
|
-
.container {
|
|
147
|
-
width: 100%;
|
|
148
|
-
height: 100%;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
.backdrop {
|
|
152
|
-
position: fixed;
|
|
153
|
-
top: 0;
|
|
154
|
-
left: 0;
|
|
155
|
-
background-color: ${modalBackdropColor};
|
|
156
|
-
width: 100%;
|
|
157
|
-
height: 100%;
|
|
158
|
-
z-index: ${modalBackdropZindex};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
modal-template {
|
|
162
|
-
outline: 0;
|
|
163
|
-
position: fixed;
|
|
164
|
-
top: 0;
|
|
165
|
-
left: 50%;
|
|
166
|
-
transform: translate(-50%, 0);
|
|
167
|
-
z-index: ${modalZindex};
|
|
168
|
-
width: ${modalWidth};
|
|
169
|
-
max-width: ${modalMaxWidth};
|
|
170
|
-
}
|
|
171
|
-
`;
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
__decorate([
|
|
175
|
-
property({ type: String, reflect: true })
|
|
176
|
-
], ModalManager.prototype, "mode", void 0);
|
|
177
|
-
__decorate([
|
|
178
|
-
property({ type: Object })
|
|
179
|
-
], ModalManager.prototype, "customModalContent", void 0);
|
|
180
|
-
__decorate([
|
|
181
|
-
property({ type: Object })
|
|
182
|
-
], ModalManager.prototype, "hostBridge", void 0);
|
|
183
|
-
__decorate([
|
|
184
|
-
query('modal-template')
|
|
185
|
-
], ModalManager.prototype, "modalTemplate", void 0);
|
|
186
|
-
ModalManager = __decorate([
|
|
187
|
-
customElement('modal-manager')
|
|
188
|
-
], ModalManager);
|
|
189
|
-
export { ModalManager };
|
|
1
|
+
import { __awaiter, __decorate } from "tslib";
|
|
2
|
+
import { LitElement, html, css, } from 'lit';
|
|
3
|
+
import { property, customElement, query } from 'lit/decorators.js';
|
|
4
|
+
import './modal-template';
|
|
5
|
+
import { ModalManagerHostBridge } from './modal-manager-host-bridge';
|
|
6
|
+
import { ModalManagerMode } from './modal-manager-mode';
|
|
7
|
+
let ModalManager = class ModalManager extends LitElement {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
/**
|
|
11
|
+
* The current mode of the ModalManager
|
|
12
|
+
*
|
|
13
|
+
* Current options are `modal` or `closed`
|
|
14
|
+
*
|
|
15
|
+
* @type {ModalManagerMode}
|
|
16
|
+
* @memberof ModalManager
|
|
17
|
+
*/
|
|
18
|
+
this.mode = ModalManagerMode.Closed;
|
|
19
|
+
/**
|
|
20
|
+
* Thie hostBridge handles environmental-specific interactions such as adding classes
|
|
21
|
+
* to the body tag or event listeners needed to support the modal manager in the host environment.
|
|
22
|
+
*
|
|
23
|
+
* There is a default `ModalManagerHostBridge`, but consumers can override it with a custom
|
|
24
|
+
* `ModalManagerHostBridgeInterface`
|
|
25
|
+
*
|
|
26
|
+
* @type {ModalManagerHostBridgeInterface}
|
|
27
|
+
* @memberof ModalManager
|
|
28
|
+
*/
|
|
29
|
+
this.hostBridge = new ModalManagerHostBridge(this);
|
|
30
|
+
/**
|
|
31
|
+
* Whether the modal should close if the user taps on the backdrop
|
|
32
|
+
*
|
|
33
|
+
* @private
|
|
34
|
+
* @memberof ModalManager
|
|
35
|
+
*/
|
|
36
|
+
this.closeOnBackdropClick = true;
|
|
37
|
+
}
|
|
38
|
+
/** @inheritdoc */
|
|
39
|
+
render() {
|
|
40
|
+
return html `
|
|
41
|
+
<div class="container">
|
|
42
|
+
<div class="backdrop" @click=${this.backdropClicked}></div>
|
|
43
|
+
<modal-template
|
|
44
|
+
@closeButtonPressed=${this.closeButtonPressed}
|
|
45
|
+
tabindex="0"
|
|
46
|
+
>
|
|
47
|
+
${this.customModalContent}
|
|
48
|
+
</modal-template>
|
|
49
|
+
</div>
|
|
50
|
+
`;
|
|
51
|
+
}
|
|
52
|
+
/** @inheritdoc */
|
|
53
|
+
getMode() {
|
|
54
|
+
return this.mode;
|
|
55
|
+
}
|
|
56
|
+
/** @inheritdoc */
|
|
57
|
+
closeModal() {
|
|
58
|
+
this.mode = ModalManagerMode.Closed;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Call the userClosedModalCallback and reset it if it exists
|
|
62
|
+
*
|
|
63
|
+
* @private
|
|
64
|
+
* @memberof ModalManager
|
|
65
|
+
*/
|
|
66
|
+
callUserClosedModalCallback() {
|
|
67
|
+
// we assign the callback to a temp var and undefine it before calling it
|
|
68
|
+
// otherwise, we run into the potential for an infinite loop if the
|
|
69
|
+
// callback triggers another `showModal()`, which would execute `userClosedModalCallback`
|
|
70
|
+
const callback = this.userClosedModalCallback;
|
|
71
|
+
this.userClosedModalCallback = undefined;
|
|
72
|
+
if (callback)
|
|
73
|
+
callback();
|
|
74
|
+
}
|
|
75
|
+
/** @inheritdoc */
|
|
76
|
+
showModal(options) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
this.closeOnBackdropClick = options.config.closeOnBackdropClick;
|
|
79
|
+
this.userClosedModalCallback = options.userClosedModalCallback;
|
|
80
|
+
this.modalTemplate.config = options.config;
|
|
81
|
+
this.customModalContent = options.customModalContent;
|
|
82
|
+
this.mode = ModalManagerMode.Open;
|
|
83
|
+
yield this.modalTemplate.updateComplete;
|
|
84
|
+
this.modalTemplate.focus();
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/** @inheritdoc */
|
|
88
|
+
updated(changed) {
|
|
89
|
+
/* istanbul ignore else */
|
|
90
|
+
if (changed.has('mode')) {
|
|
91
|
+
this.handleModeChange();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Called when the backdrop is clicked
|
|
96
|
+
*
|
|
97
|
+
* @private
|
|
98
|
+
* @memberof ModalManager
|
|
99
|
+
*/
|
|
100
|
+
backdropClicked() {
|
|
101
|
+
if (this.closeOnBackdropClick) {
|
|
102
|
+
this.closeModal();
|
|
103
|
+
this.callUserClosedModalCallback();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Handle the mode change
|
|
108
|
+
*
|
|
109
|
+
* @private
|
|
110
|
+
* @memberof ModalManager
|
|
111
|
+
*/
|
|
112
|
+
handleModeChange() {
|
|
113
|
+
this.hostBridge.handleModeChange(this.mode);
|
|
114
|
+
this.emitModeChangeEvent();
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Emit a modeChange event
|
|
118
|
+
*
|
|
119
|
+
* @private
|
|
120
|
+
* @memberof ModalManager
|
|
121
|
+
*/
|
|
122
|
+
emitModeChangeEvent() {
|
|
123
|
+
const event = new CustomEvent('modeChanged', {
|
|
124
|
+
detail: { mode: this.mode },
|
|
125
|
+
});
|
|
126
|
+
this.dispatchEvent(event);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Called when the modal close button is pressed. Closes the modal.
|
|
130
|
+
*
|
|
131
|
+
* @private
|
|
132
|
+
* @memberof ModalManager
|
|
133
|
+
*/
|
|
134
|
+
closeButtonPressed() {
|
|
135
|
+
this.closeModal();
|
|
136
|
+
this.callUserClosedModalCallback();
|
|
137
|
+
}
|
|
138
|
+
/** @inheritdoc */
|
|
139
|
+
static get styles() {
|
|
140
|
+
const modalBackdropColor = css `var(--modalBackdropColor, rgba(10, 10, 10, 0.9))`;
|
|
141
|
+
const modalBackdropZindex = css `var(--modalBackdropZindex, 1000)`;
|
|
142
|
+
const modalWidth = css `var(--modalWidth, 32rem)`;
|
|
143
|
+
const modalMaxWidth = css `var(--modalMaxWidth, 95%)`;
|
|
144
|
+
const modalZindex = css `var(--modalZindex, 2000)`;
|
|
145
|
+
return css `
|
|
146
|
+
.container {
|
|
147
|
+
width: 100%;
|
|
148
|
+
height: 100%;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.backdrop {
|
|
152
|
+
position: fixed;
|
|
153
|
+
top: 0;
|
|
154
|
+
left: 0;
|
|
155
|
+
background-color: ${modalBackdropColor};
|
|
156
|
+
width: 100%;
|
|
157
|
+
height: 100%;
|
|
158
|
+
z-index: ${modalBackdropZindex};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
modal-template {
|
|
162
|
+
outline: 0;
|
|
163
|
+
position: fixed;
|
|
164
|
+
top: 0;
|
|
165
|
+
left: 50%;
|
|
166
|
+
transform: translate(-50%, 0);
|
|
167
|
+
z-index: ${modalZindex};
|
|
168
|
+
width: ${modalWidth};
|
|
169
|
+
max-width: ${modalMaxWidth};
|
|
170
|
+
}
|
|
171
|
+
`;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
__decorate([
|
|
175
|
+
property({ type: String, reflect: true })
|
|
176
|
+
], ModalManager.prototype, "mode", void 0);
|
|
177
|
+
__decorate([
|
|
178
|
+
property({ type: Object })
|
|
179
|
+
], ModalManager.prototype, "customModalContent", void 0);
|
|
180
|
+
__decorate([
|
|
181
|
+
property({ type: Object })
|
|
182
|
+
], ModalManager.prototype, "hostBridge", void 0);
|
|
183
|
+
__decorate([
|
|
184
|
+
query('modal-template')
|
|
185
|
+
], ModalManager.prototype, "modalTemplate", void 0);
|
|
186
|
+
ModalManager = __decorate([
|
|
187
|
+
customElement('modal-manager')
|
|
188
|
+
], ModalManager);
|
|
189
|
+
export { ModalManager };
|
|
190
190
|
//# sourceMappingURL=modal-manager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modal-manager.js","sourceRoot":"","sources":["../../src/modal-manager.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EACV,IAAI,EACJ,GAAG,GAIJ,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEnE,OAAO,kBAAkB,CAAC;AAG1B,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAGrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAA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3B,mBAAmB;;;;;;;;;mBASnB,WAAW;iBACb,UAAU;qBACN,aAAa;;KAE7B,CAAC;IACJ,CAAC;CACF,CAAA;AAvM4C;IAA1C,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;0CAChB;AAQE;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wDAAqC;AAahE;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gDAGzB;AASuB;IAAxB,KAAK,CAAC,gBAAgB,CAAC;mDAAuC;AA1CpD,YAAY;IADxB,aAAa,CAAC,eAAe,CAAC;GAClB,YAAY,CAgNxB;SAhNY,YAAY","sourcesContent":["import {\n LitElement,\n html,\n css,\n CSSResult,\n TemplateResult,\n PropertyValues,\n} from 'lit';\nimport { property, customElement, query } from 'lit/decorators.js';\n\nimport './modal-template';\nimport { ModalTemplate } from './modal-template';\nimport { ModalConfig } from './modal-config';\nimport { ModalManagerHostBridge } from './modal-manager-host-bridge';\nimport { ModalManagerInterface } from './modal-manager-interface';\nimport { ModalManagerHostBridgeInterface } from './modal-manager-host-bridge-interface';\nimport { ModalManagerMode } from './modal-manager-mode';\n\n@customElement('modal-manager')\nexport class ModalManager extends LitElement implements ModalManagerInterface {\n /**\n * The current mode of the ModalManager\n *\n * Current options are `modal` or `closed`\n *\n * @type {ModalManagerMode}\n * @memberof ModalManager\n */\n @property({ type: String, reflect: true }) mode: ModalManagerMode =\n ModalManagerMode.Closed;\n\n /**\n * Custom content to display in the modal's content slot\n *\n * @type {(TemplateResult | undefined)}\n * @memberof ModalManager\n */\n @property({ type: Object }) customModalContent?: TemplateResult;\n\n /**\n * Thie hostBridge handles environmental-specific interactions such as adding classes\n * to the body tag or event listeners needed to support the modal manager in the host environment.\n *\n * There is a default `ModalManagerHostBridge`, but consumers can override it with a custom\n * `ModalManagerHostBridgeInterface`\n *\n * @type {ModalManagerHostBridgeInterface}\n * @memberof ModalManager\n */\n @property({ type: Object })\n hostBridge: ModalManagerHostBridgeInterface = new ModalManagerHostBridge(\n this\n );\n\n /**\n * Reference to the ModalTemplate DOM element\n *\n * @private\n * @type {ModalTemplate}\n * @memberof ModalManager\n */\n @query('modal-template') private modalTemplate!: ModalTemplate;\n\n /** @inheritdoc */\n render(): TemplateResult {\n return html`\n <div class=\"container\">\n <div class=\"backdrop\" @click=${this.backdropClicked}></div>\n <modal-template\n @closeButtonPressed=${this.closeButtonPressed}\n tabindex=\"0\"\n >\n ${this.customModalContent}\n </modal-template>\n </div>\n `;\n }\n\n /** @inheritdoc */\n getMode(): ModalManagerMode {\n return this.mode;\n }\n\n /** @inheritdoc */\n closeModal(): void {\n this.mode = ModalManagerMode.Closed;\n }\n\n /**\n * Whether the modal should close if the user taps on the backdrop\n *\n * @private\n * @memberof ModalManager\n */\n private closeOnBackdropClick = true;\n\n /**\n * A callback if the user closes the modal\n *\n * @private\n * @memberof ModalManager\n */\n private userClosedModalCallback?: () => void;\n\n /**\n * Call the userClosedModalCallback and reset it if it exists\n *\n * @private\n * @memberof ModalManager\n */\n private callUserClosedModalCallback(): void {\n // we assign the callback to a temp var and undefine it before calling it\n // otherwise, we run into the potential for an infinite loop if the\n // callback triggers another `showModal()`, which would execute `userClosedModalCallback`\n const callback = this.userClosedModalCallback;\n this.userClosedModalCallback = undefined;\n if (callback) callback();\n }\n\n /** @inheritdoc */\n async showModal(options: {\n config: ModalConfig;\n customModalContent?: TemplateResult;\n userClosedModalCallback?: () => void;\n }): Promise<void> {\n this.closeOnBackdropClick = options.config.closeOnBackdropClick;\n this.userClosedModalCallback = options.userClosedModalCallback;\n this.modalTemplate.config = options.config;\n this.customModalContent = options.customModalContent;\n this.mode = ModalManagerMode.Open;\n await this.modalTemplate.updateComplete;\n this.modalTemplate.focus();\n }\n\n /** @inheritdoc */\n updated(changed: PropertyValues): void {\n /* istanbul ignore else */\n if (changed.has('mode')) {\n this.handleModeChange();\n }\n }\n\n /**\n * Called when the backdrop is clicked\n *\n * @private\n * @memberof ModalManager\n */\n private backdropClicked(): void {\n if (this.closeOnBackdropClick) {\n this.closeModal();\n this.callUserClosedModalCallback();\n }\n }\n\n /**\n * Handle the mode change\n *\n * @private\n * @memberof ModalManager\n */\n private handleModeChange(): void {\n this.hostBridge.handleModeChange(this.mode);\n this.emitModeChangeEvent();\n }\n\n /**\n * Emit a modeChange event\n *\n * @private\n * @memberof ModalManager\n */\n private emitModeChangeEvent(): void {\n const event = new CustomEvent('modeChanged', {\n detail: { mode: this.mode },\n });\n this.dispatchEvent(event);\n }\n\n /**\n * Called when the modal close button is pressed. Closes the modal.\n *\n * @private\n * @memberof ModalManager\n */\n private closeButtonPressed(): void {\n this.closeModal();\n this.callUserClosedModalCallback();\n }\n\n /** @inheritdoc */\n static get styles(): CSSResult {\n const modalBackdropColor = css`var(--modalBackdropColor, rgba(10, 10, 10, 0.9))`;\n const modalBackdropZindex = css`var(--modalBackdropZindex, 1000)`;\n\n const modalWidth = css`var(--modalWidth, 32rem)`;\n const modalMaxWidth = css`var(--modalMaxWidth, 95%)`;\n const modalZindex = css`var(--modalZindex, 2000)`;\n\n return css`\n .container {\n width: 100%;\n height: 100%;\n }\n\n .backdrop {\n position: fixed;\n top: 0;\n left: 0;\n background-color: ${modalBackdropColor};\n width: 100%;\n height: 100%;\n z-index: ${modalBackdropZindex};\n }\n\n modal-template {\n outline: 0;\n position: fixed;\n top: 0;\n left: 50%;\n transform: translate(-50%, 0);\n z-index: ${modalZindex};\n width: ${modalWidth};\n max-width: ${modalMaxWidth};\n }\n `;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"modal-manager.js","sourceRoot":"","sources":["../../src/modal-manager.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EACV,IAAI,EACJ,GAAG,GAIJ,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEnE,OAAO,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AA2B,CAAC;QACrD,MAAM,WAAW,GAAG,GAAG,CAAA,0BAA0B,CAAC;QAElD,OAAO,GAAG,CAAA;;;;;;;;;;4BAUc,kBAAkB;;;mBAG3B,mBAAmB;;;;;;;;;mBASnB,WAAW;iBACb,UAAU;qBACN,aAAa;;KAE7B,CAAC;IACJ,CAAC;CACF,CAAA;AAvM4C;IAA1C,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;0CAChB;AAQE;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wDAAqC;AAahE;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gDAGzB;AASuB;IAAxB,KAAK,CAAC,gBAAgB,CAAC;mDAAuC;AA1CpD,YAAY;IADxB,aAAa,CAAC,eAAe,CAAC;GAClB,YAAY,CAgNxB;SAhNY,YAAY","sourcesContent":["import {\r\n LitElement,\r\n html,\r\n css,\r\n CSSResult,\r\n TemplateResult,\r\n PropertyValues,\r\n} from 'lit';\r\nimport { property, customElement, query } from 'lit/decorators.js';\r\n\r\nimport './modal-template';\r\nimport { ModalTemplate } from './modal-template';\r\nimport { ModalConfig } from './modal-config';\r\nimport { ModalManagerHostBridge } from './modal-manager-host-bridge';\r\nimport { ModalManagerInterface } from './modal-manager-interface';\r\nimport { ModalManagerHostBridgeInterface } from './modal-manager-host-bridge-interface';\r\nimport { ModalManagerMode } from './modal-manager-mode';\r\n\r\n@customElement('modal-manager')\r\nexport class ModalManager extends LitElement implements ModalManagerInterface {\r\n /**\r\n * The current mode of the ModalManager\r\n *\r\n * Current options are `modal` or `closed`\r\n *\r\n * @type {ModalManagerMode}\r\n * @memberof ModalManager\r\n */\r\n @property({ type: String, reflect: true }) mode: ModalManagerMode =\r\n ModalManagerMode.Closed;\r\n\r\n /**\r\n * Custom content to display in the modal's content slot\r\n *\r\n * @type {(TemplateResult | undefined)}\r\n * @memberof ModalManager\r\n */\r\n @property({ type: Object }) customModalContent?: TemplateResult;\r\n\r\n /**\r\n * Thie hostBridge handles environmental-specific interactions such as adding classes\r\n * to the body tag or event listeners needed to support the modal manager in the host environment.\r\n *\r\n * There is a default `ModalManagerHostBridge`, but consumers can override it with a custom\r\n * `ModalManagerHostBridgeInterface`\r\n *\r\n * @type {ModalManagerHostBridgeInterface}\r\n * @memberof ModalManager\r\n */\r\n @property({ type: Object })\r\n hostBridge: ModalManagerHostBridgeInterface = new ModalManagerHostBridge(\r\n this\r\n );\r\n\r\n /**\r\n * Reference to the ModalTemplate DOM element\r\n *\r\n * @private\r\n * @type {ModalTemplate}\r\n * @memberof ModalManager\r\n */\r\n @query('modal-template') private modalTemplate!: ModalTemplate;\r\n\r\n /** @inheritdoc */\r\n render(): TemplateResult {\r\n return html`\r\n <div class=\"container\">\r\n <div class=\"backdrop\" @click=${this.backdropClicked}></div>\r\n <modal-template\r\n @closeButtonPressed=${this.closeButtonPressed}\r\n tabindex=\"0\"\r\n >\r\n ${this.customModalContent}\r\n </modal-template>\r\n </div>\r\n `;\r\n }\r\n\r\n /** @inheritdoc */\r\n getMode(): ModalManagerMode {\r\n return this.mode;\r\n }\r\n\r\n /** @inheritdoc */\r\n closeModal(): void {\r\n this.mode = ModalManagerMode.Closed;\r\n }\r\n\r\n /**\r\n * Whether the modal should close if the user taps on the backdrop\r\n *\r\n * @private\r\n * @memberof ModalManager\r\n */\r\n private closeOnBackdropClick = true;\r\n\r\n /**\r\n * A callback if the user closes the modal\r\n *\r\n * @private\r\n * @memberof ModalManager\r\n */\r\n private userClosedModalCallback?: () => void;\r\n\r\n /**\r\n * Call the userClosedModalCallback and reset it if it exists\r\n *\r\n * @private\r\n * @memberof ModalManager\r\n */\r\n private callUserClosedModalCallback(): void {\r\n // we assign the callback to a temp var and undefine it before calling it\r\n // otherwise, we run into the potential for an infinite loop if the\r\n // callback triggers another `showModal()`, which would execute `userClosedModalCallback`\r\n const callback = this.userClosedModalCallback;\r\n this.userClosedModalCallback = undefined;\r\n if (callback) callback();\r\n }\r\n\r\n /** @inheritdoc */\r\n async showModal(options: {\r\n config: ModalConfig;\r\n customModalContent?: TemplateResult;\r\n userClosedModalCallback?: () => void;\r\n }): Promise<void> {\r\n this.closeOnBackdropClick = options.config.closeOnBackdropClick;\r\n this.userClosedModalCallback = options.userClosedModalCallback;\r\n this.modalTemplate.config = options.config;\r\n this.customModalContent = options.customModalContent;\r\n this.mode = ModalManagerMode.Open;\r\n await this.modalTemplate.updateComplete;\r\n this.modalTemplate.focus();\r\n }\r\n\r\n /** @inheritdoc */\r\n updated(changed: PropertyValues): void {\r\n /* istanbul ignore else */\r\n if (changed.has('mode')) {\r\n this.handleModeChange();\r\n }\r\n }\r\n\r\n /**\r\n * Called when the backdrop is clicked\r\n *\r\n * @private\r\n * @memberof ModalManager\r\n */\r\n private backdropClicked(): void {\r\n if (this.closeOnBackdropClick) {\r\n this.closeModal();\r\n this.callUserClosedModalCallback();\r\n }\r\n }\r\n\r\n /**\r\n * Handle the mode change\r\n *\r\n * @private\r\n * @memberof ModalManager\r\n */\r\n private handleModeChange(): void {\r\n this.hostBridge.handleModeChange(this.mode);\r\n this.emitModeChangeEvent();\r\n }\r\n\r\n /**\r\n * Emit a modeChange event\r\n *\r\n * @private\r\n * @memberof ModalManager\r\n */\r\n private emitModeChangeEvent(): void {\r\n const event = new CustomEvent('modeChanged', {\r\n detail: { mode: this.mode },\r\n });\r\n this.dispatchEvent(event);\r\n }\r\n\r\n /**\r\n * Called when the modal close button is pressed. Closes the modal.\r\n *\r\n * @private\r\n * @memberof ModalManager\r\n */\r\n private closeButtonPressed(): void {\r\n this.closeModal();\r\n this.callUserClosedModalCallback();\r\n }\r\n\r\n /** @inheritdoc */\r\n static get styles(): CSSResult {\r\n const modalBackdropColor = css`var(--modalBackdropColor, rgba(10, 10, 10, 0.9))`;\r\n const modalBackdropZindex = css`var(--modalBackdropZindex, 1000)`;\r\n\r\n const modalWidth = css`var(--modalWidth, 32rem)`;\r\n const modalMaxWidth = css`var(--modalMaxWidth, 95%)`;\r\n const modalZindex = css`var(--modalZindex, 2000)`;\r\n\r\n return css`\r\n .container {\r\n width: 100%;\r\n height: 100%;\r\n }\r\n\r\n .backdrop {\r\n position: fixed;\r\n top: 0;\r\n left: 0;\r\n background-color: ${modalBackdropColor};\r\n width: 100%;\r\n height: 100%;\r\n z-index: ${modalBackdropZindex};\r\n }\r\n\r\n modal-template {\r\n outline: 0;\r\n position: fixed;\r\n top: 0;\r\n left: 50%;\r\n transform: translate(-50%, 0);\r\n z-index: ${modalZindex};\r\n width: ${modalWidth};\r\n max-width: ${modalMaxWidth};\r\n }\r\n `;\r\n }\r\n}\r\n"]}
|