@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.
Files changed (73) hide show
  1. package/.editorconfig +29 -29
  2. package/.eslintrc.js +14 -14
  3. package/.github/workflows/ci.yml +26 -26
  4. package/LICENSE +661 -661
  5. package/README.md +139 -139
  6. package/custom-elements.json +170 -170
  7. package/demo/index.html +278 -278
  8. package/dist/index.d.ts +7 -7
  9. package/dist/index.js +5 -5
  10. package/dist/index.js.map +1 -1
  11. package/dist/src/modal-config.d.ts +92 -92
  12. package/dist/src/modal-config.js +22 -22
  13. package/dist/src/modal-config.js.map +1 -1
  14. package/dist/src/modal-manager-host-bridge-interface.d.ts +12 -12
  15. package/dist/src/modal-manager-host-bridge-interface.js.map +1 -1
  16. package/dist/src/modal-manager-host-bridge.d.ts +34 -34
  17. package/dist/src/modal-manager-host-bridge.js +62 -62
  18. package/dist/src/modal-manager-host-bridge.js.map +1 -1
  19. package/dist/src/modal-manager-interface.d.ts +25 -25
  20. package/dist/src/modal-manager-interface.js.map +1 -1
  21. package/dist/src/modal-manager-mode.d.ts +10 -10
  22. package/dist/src/modal-manager-mode.js +11 -11
  23. package/dist/src/modal-manager-mode.js.map +1 -1
  24. package/dist/src/modal-manager.d.ts +108 -108
  25. package/dist/src/modal-manager.js +189 -189
  26. package/dist/src/modal-manager.js.map +1 -1
  27. package/dist/src/modal-template.d.ts +32 -32
  28. package/dist/src/modal-template.js +276 -276
  29. package/dist/src/modal-template.js.map +1 -1
  30. package/dist/test/modal-config.test.d.ts +1 -1
  31. package/dist/test/modal-config.test.js +61 -61
  32. package/dist/test/modal-config.test.js.map +1 -1
  33. package/dist/test/modal-manager.test.d.ts +1 -1
  34. package/dist/test/modal-manager.test.js +200 -200
  35. package/dist/test/modal-manager.test.js.map +1 -1
  36. package/dist/test/modal-template.test.d.ts +1 -1
  37. package/dist/test/modal-template.test.js +95 -95
  38. package/dist/test/modal-template.test.js.map +1 -1
  39. package/docs/assets/css/main.css +2678 -2678
  40. package/docs/classes/_src_modal_config_.modalconfig.html +429 -429
  41. package/docs/classes/_src_modal_manager_.modalmanager.html +7702 -7702
  42. package/docs/classes/_src_modal_manager_host_bridge_.modalmanagerhostbridge.html +409 -409
  43. package/docs/classes/_src_modal_template_.modaltemplate.html +7096 -7096
  44. package/docs/enums/_src_modal_manager_mode_.modalmanagermode.html +196 -196
  45. package/docs/globals.html +150 -150
  46. package/docs/index.html +252 -252
  47. package/docs/interfaces/_src_modal_manager_host_bridge_interface_.modalmanagerhostbridgeinterface.html +210 -210
  48. package/docs/interfaces/_src_modal_manager_interface_.modalmanagerinterface.html +7095 -7095
  49. package/docs/modules/_index_.html +208 -208
  50. package/docs/modules/_src_modal_config_.html +146 -146
  51. package/docs/modules/_src_modal_manager_.html +146 -146
  52. package/docs/modules/_src_modal_manager_host_bridge_.html +146 -146
  53. package/docs/modules/_src_modal_manager_host_bridge_interface_.html +146 -146
  54. package/docs/modules/_src_modal_manager_interface_.html +146 -146
  55. package/docs/modules/_src_modal_manager_mode_.html +146 -146
  56. package/docs/modules/_src_modal_template_.html +146 -146
  57. package/docs/modules/_test_modal_config_test_.html +106 -106
  58. package/docs/modules/_test_modal_manager_test_.html +106 -106
  59. package/docs/modules/_test_modal_template_test_.html +106 -106
  60. package/index.ts +7 -7
  61. package/karma.conf.js +24 -24
  62. package/package.json +82 -82
  63. package/src/modal-config.ts +117 -117
  64. package/src/modal-manager-host-bridge-interface.ts +13 -13
  65. package/src/modal-manager-host-bridge.ts +82 -82
  66. package/src/modal-manager-interface.ts +28 -28
  67. package/src/modal-manager-mode.ts +10 -10
  68. package/src/modal-manager.ts +228 -228
  69. package/src/modal-template.ts +279 -279
  70. package/test/modal-config.test.ts +69 -69
  71. package/test/modal-manager.test.ts +245 -245
  72. package/test/modal-template.test.ts +111 -111
  73. package/tsconfig.json +20 -20
@@ -1,228 +1,228 @@
1
- import {
2
- LitElement,
3
- html,
4
- css,
5
- CSSResult,
6
- TemplateResult,
7
- PropertyValues,
8
- } from 'lit';
9
- import { property, customElement, query } from 'lit/decorators.js';
10
-
11
- import './modal-template';
12
- import { ModalTemplate } from './modal-template';
13
- import { ModalConfig } from './modal-config';
14
- import { ModalManagerHostBridge } from './modal-manager-host-bridge';
15
- import { ModalManagerInterface } from './modal-manager-interface';
16
- import { ModalManagerHostBridgeInterface } from './modal-manager-host-bridge-interface';
17
- import { ModalManagerMode } from './modal-manager-mode';
18
-
19
- @customElement('modal-manager')
20
- export class ModalManager extends LitElement implements ModalManagerInterface {
21
- /**
22
- * The current mode of the ModalManager
23
- *
24
- * Current options are `modal` or `closed`
25
- *
26
- * @type {ModalManagerMode}
27
- * @memberof ModalManager
28
- */
29
- @property({ type: String, reflect: true }) mode: ModalManagerMode =
30
- ModalManagerMode.Closed;
31
-
32
- /**
33
- * Custom content to display in the modal's content slot
34
- *
35
- * @type {(TemplateResult | undefined)}
36
- * @memberof ModalManager
37
- */
38
- @property({ type: Object }) customModalContent?: TemplateResult;
39
-
40
- /**
41
- * Thie hostBridge handles environmental-specific interactions such as adding classes
42
- * to the body tag or event listeners needed to support the modal manager in the host environment.
43
- *
44
- * There is a default `ModalManagerHostBridge`, but consumers can override it with a custom
45
- * `ModalManagerHostBridgeInterface`
46
- *
47
- * @type {ModalManagerHostBridgeInterface}
48
- * @memberof ModalManager
49
- */
50
- @property({ type: Object })
51
- hostBridge: ModalManagerHostBridgeInterface = new ModalManagerHostBridge(
52
- this
53
- );
54
-
55
- /**
56
- * Reference to the ModalTemplate DOM element
57
- *
58
- * @private
59
- * @type {ModalTemplate}
60
- * @memberof ModalManager
61
- */
62
- @query('modal-template') private modalTemplate!: ModalTemplate;
63
-
64
- /** @inheritdoc */
65
- render(): TemplateResult {
66
- return html`
67
- <div class="container">
68
- <div class="backdrop" @click=${this.backdropClicked}></div>
69
- <modal-template
70
- @closeButtonPressed=${this.closeButtonPressed}
71
- tabindex="0"
72
- >
73
- ${this.customModalContent}
74
- </modal-template>
75
- </div>
76
- `;
77
- }
78
-
79
- /** @inheritdoc */
80
- getMode(): ModalManagerMode {
81
- return this.mode;
82
- }
83
-
84
- /** @inheritdoc */
85
- closeModal(): void {
86
- this.mode = ModalManagerMode.Closed;
87
- }
88
-
89
- /**
90
- * Whether the modal should close if the user taps on the backdrop
91
- *
92
- * @private
93
- * @memberof ModalManager
94
- */
95
- private closeOnBackdropClick = true;
96
-
97
- /**
98
- * A callback if the user closes the modal
99
- *
100
- * @private
101
- * @memberof ModalManager
102
- */
103
- private userClosedModalCallback?: () => void;
104
-
105
- /**
106
- * Call the userClosedModalCallback and reset it if it exists
107
- *
108
- * @private
109
- * @memberof ModalManager
110
- */
111
- private callUserClosedModalCallback(): void {
112
- // we assign the callback to a temp var and undefine it before calling it
113
- // otherwise, we run into the potential for an infinite loop if the
114
- // callback triggers another `showModal()`, which would execute `userClosedModalCallback`
115
- const callback = this.userClosedModalCallback;
116
- this.userClosedModalCallback = undefined;
117
- if (callback) callback();
118
- }
119
-
120
- /** @inheritdoc */
121
- async showModal(options: {
122
- config: ModalConfig;
123
- customModalContent?: TemplateResult;
124
- userClosedModalCallback?: () => void;
125
- }): Promise<void> {
126
- this.closeOnBackdropClick = options.config.closeOnBackdropClick;
127
- this.userClosedModalCallback = options.userClosedModalCallback;
128
- this.modalTemplate.config = options.config;
129
- this.customModalContent = options.customModalContent;
130
- this.mode = ModalManagerMode.Open;
131
- await this.modalTemplate.updateComplete;
132
- this.modalTemplate.focus();
133
- }
134
-
135
- /** @inheritdoc */
136
- updated(changed: PropertyValues): void {
137
- /* istanbul ignore else */
138
- if (changed.has('mode')) {
139
- this.handleModeChange();
140
- }
141
- }
142
-
143
- /**
144
- * Called when the backdrop is clicked
145
- *
146
- * @private
147
- * @memberof ModalManager
148
- */
149
- private backdropClicked(): void {
150
- if (this.closeOnBackdropClick) {
151
- this.closeModal();
152
- this.callUserClosedModalCallback();
153
- }
154
- }
155
-
156
- /**
157
- * Handle the mode change
158
- *
159
- * @private
160
- * @memberof ModalManager
161
- */
162
- private handleModeChange(): void {
163
- this.hostBridge.handleModeChange(this.mode);
164
- this.emitModeChangeEvent();
165
- }
166
-
167
- /**
168
- * Emit a modeChange event
169
- *
170
- * @private
171
- * @memberof ModalManager
172
- */
173
- private emitModeChangeEvent(): void {
174
- const event = new CustomEvent('modeChanged', {
175
- detail: { mode: this.mode },
176
- });
177
- this.dispatchEvent(event);
178
- }
179
-
180
- /**
181
- * Called when the modal close button is pressed. Closes the modal.
182
- *
183
- * @private
184
- * @memberof ModalManager
185
- */
186
- private closeButtonPressed(): void {
187
- this.closeModal();
188
- this.callUserClosedModalCallback();
189
- }
190
-
191
- /** @inheritdoc */
192
- static get styles(): CSSResult {
193
- const modalBackdropColor = css`var(--modalBackdropColor, rgba(10, 10, 10, 0.9))`;
194
- const modalBackdropZindex = css`var(--modalBackdropZindex, 1000)`;
195
-
196
- const modalWidth = css`var(--modalWidth, 32rem)`;
197
- const modalMaxWidth = css`var(--modalMaxWidth, 95%)`;
198
- const modalZindex = css`var(--modalZindex, 2000)`;
199
-
200
- return css`
201
- .container {
202
- width: 100%;
203
- height: 100%;
204
- }
205
-
206
- .backdrop {
207
- position: fixed;
208
- top: 0;
209
- left: 0;
210
- background-color: ${modalBackdropColor};
211
- width: 100%;
212
- height: 100%;
213
- z-index: ${modalBackdropZindex};
214
- }
215
-
216
- modal-template {
217
- outline: 0;
218
- position: fixed;
219
- top: 0;
220
- left: 50%;
221
- transform: translate(-50%, 0);
222
- z-index: ${modalZindex};
223
- width: ${modalWidth};
224
- max-width: ${modalMaxWidth};
225
- }
226
- `;
227
- }
228
- }
1
+ import {
2
+ LitElement,
3
+ html,
4
+ css,
5
+ CSSResult,
6
+ TemplateResult,
7
+ PropertyValues,
8
+ } from 'lit';
9
+ import { property, customElement, query } from 'lit/decorators.js';
10
+
11
+ import './modal-template';
12
+ import { ModalTemplate } from './modal-template';
13
+ import { ModalConfig } from './modal-config';
14
+ import { ModalManagerHostBridge } from './modal-manager-host-bridge';
15
+ import { ModalManagerInterface } from './modal-manager-interface';
16
+ import { ModalManagerHostBridgeInterface } from './modal-manager-host-bridge-interface';
17
+ import { ModalManagerMode } from './modal-manager-mode';
18
+
19
+ @customElement('modal-manager')
20
+ export class ModalManager extends LitElement implements ModalManagerInterface {
21
+ /**
22
+ * The current mode of the ModalManager
23
+ *
24
+ * Current options are `modal` or `closed`
25
+ *
26
+ * @type {ModalManagerMode}
27
+ * @memberof ModalManager
28
+ */
29
+ @property({ type: String, reflect: true }) mode: ModalManagerMode =
30
+ ModalManagerMode.Closed;
31
+
32
+ /**
33
+ * Custom content to display in the modal's content slot
34
+ *
35
+ * @type {(TemplateResult | undefined)}
36
+ * @memberof ModalManager
37
+ */
38
+ @property({ type: Object }) customModalContent?: TemplateResult;
39
+
40
+ /**
41
+ * Thie hostBridge handles environmental-specific interactions such as adding classes
42
+ * to the body tag or event listeners needed to support the modal manager in the host environment.
43
+ *
44
+ * There is a default `ModalManagerHostBridge`, but consumers can override it with a custom
45
+ * `ModalManagerHostBridgeInterface`
46
+ *
47
+ * @type {ModalManagerHostBridgeInterface}
48
+ * @memberof ModalManager
49
+ */
50
+ @property({ type: Object })
51
+ hostBridge: ModalManagerHostBridgeInterface = new ModalManagerHostBridge(
52
+ this
53
+ );
54
+
55
+ /**
56
+ * Reference to the ModalTemplate DOM element
57
+ *
58
+ * @private
59
+ * @type {ModalTemplate}
60
+ * @memberof ModalManager
61
+ */
62
+ @query('modal-template') private modalTemplate!: ModalTemplate;
63
+
64
+ /** @inheritdoc */
65
+ render(): TemplateResult {
66
+ return html`
67
+ <div class="container">
68
+ <div class="backdrop" @click=${this.backdropClicked}></div>
69
+ <modal-template
70
+ @closeButtonPressed=${this.closeButtonPressed}
71
+ tabindex="0"
72
+ >
73
+ ${this.customModalContent}
74
+ </modal-template>
75
+ </div>
76
+ `;
77
+ }
78
+
79
+ /** @inheritdoc */
80
+ getMode(): ModalManagerMode {
81
+ return this.mode;
82
+ }
83
+
84
+ /** @inheritdoc */
85
+ closeModal(): void {
86
+ this.mode = ModalManagerMode.Closed;
87
+ }
88
+
89
+ /**
90
+ * Whether the modal should close if the user taps on the backdrop
91
+ *
92
+ * @private
93
+ * @memberof ModalManager
94
+ */
95
+ private closeOnBackdropClick = true;
96
+
97
+ /**
98
+ * A callback if the user closes the modal
99
+ *
100
+ * @private
101
+ * @memberof ModalManager
102
+ */
103
+ private userClosedModalCallback?: () => void;
104
+
105
+ /**
106
+ * Call the userClosedModalCallback and reset it if it exists
107
+ *
108
+ * @private
109
+ * @memberof ModalManager
110
+ */
111
+ private callUserClosedModalCallback(): void {
112
+ // we assign the callback to a temp var and undefine it before calling it
113
+ // otherwise, we run into the potential for an infinite loop if the
114
+ // callback triggers another `showModal()`, which would execute `userClosedModalCallback`
115
+ const callback = this.userClosedModalCallback;
116
+ this.userClosedModalCallback = undefined;
117
+ if (callback) callback();
118
+ }
119
+
120
+ /** @inheritdoc */
121
+ async showModal(options: {
122
+ config: ModalConfig;
123
+ customModalContent?: TemplateResult;
124
+ userClosedModalCallback?: () => void;
125
+ }): Promise<void> {
126
+ this.closeOnBackdropClick = options.config.closeOnBackdropClick;
127
+ this.userClosedModalCallback = options.userClosedModalCallback;
128
+ this.modalTemplate.config = options.config;
129
+ this.customModalContent = options.customModalContent;
130
+ this.mode = ModalManagerMode.Open;
131
+ await this.modalTemplate.updateComplete;
132
+ this.modalTemplate.focus();
133
+ }
134
+
135
+ /** @inheritdoc */
136
+ updated(changed: PropertyValues): void {
137
+ /* istanbul ignore else */
138
+ if (changed.has('mode')) {
139
+ this.handleModeChange();
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Called when the backdrop is clicked
145
+ *
146
+ * @private
147
+ * @memberof ModalManager
148
+ */
149
+ private backdropClicked(): void {
150
+ if (this.closeOnBackdropClick) {
151
+ this.closeModal();
152
+ this.callUserClosedModalCallback();
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Handle the mode change
158
+ *
159
+ * @private
160
+ * @memberof ModalManager
161
+ */
162
+ private handleModeChange(): void {
163
+ this.hostBridge.handleModeChange(this.mode);
164
+ this.emitModeChangeEvent();
165
+ }
166
+
167
+ /**
168
+ * Emit a modeChange event
169
+ *
170
+ * @private
171
+ * @memberof ModalManager
172
+ */
173
+ private emitModeChangeEvent(): void {
174
+ const event = new CustomEvent('modeChanged', {
175
+ detail: { mode: this.mode },
176
+ });
177
+ this.dispatchEvent(event);
178
+ }
179
+
180
+ /**
181
+ * Called when the modal close button is pressed. Closes the modal.
182
+ *
183
+ * @private
184
+ * @memberof ModalManager
185
+ */
186
+ private closeButtonPressed(): void {
187
+ this.closeModal();
188
+ this.callUserClosedModalCallback();
189
+ }
190
+
191
+ /** @inheritdoc */
192
+ static get styles(): CSSResult {
193
+ const modalBackdropColor = css`var(--modalBackdropColor, rgba(10, 10, 10, 0.9))`;
194
+ const modalBackdropZindex = css`var(--modalBackdropZindex, 1000)`;
195
+
196
+ const modalWidth = css`var(--modalWidth, 32rem)`;
197
+ const modalMaxWidth = css`var(--modalMaxWidth, 95%)`;
198
+ const modalZindex = css`var(--modalZindex, 2000)`;
199
+
200
+ return css`
201
+ .container {
202
+ width: 100%;
203
+ height: 100%;
204
+ }
205
+
206
+ .backdrop {
207
+ position: fixed;
208
+ top: 0;
209
+ left: 0;
210
+ background-color: ${modalBackdropColor};
211
+ width: 100%;
212
+ height: 100%;
213
+ z-index: ${modalBackdropZindex};
214
+ }
215
+
216
+ modal-template {
217
+ outline: 0;
218
+ position: fixed;
219
+ top: 0;
220
+ left: 50%;
221
+ transform: translate(-50%, 0);
222
+ z-index: ${modalZindex};
223
+ width: ${modalWidth};
224
+ max-width: ${modalMaxWidth};
225
+ }
226
+ `;
227
+ }
228
+ }