@vaadin/overlay 24.1.5 → 24.2.0-alpha10

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.
@@ -0,0 +1,103 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2017 - 2023 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+
7
+ /**
8
+ * Returns all attached overlays in visual stacking order.
9
+ * @private
10
+ */
11
+ const getAttachedInstances = () =>
12
+ Array.from(document.body.children)
13
+ .filter((el) => el instanceof HTMLElement && el._hasOverlayStackMixin && !el.hasAttribute('closing'))
14
+ .sort((a, b) => a.__zIndex - b.__zIndex || 0);
15
+
16
+ /**
17
+ * Returns true if the overlay is the last one in the opened overlays stack.
18
+ * @param {HTMLElement} overlay
19
+ * @return {boolean}
20
+ * @protected
21
+ */
22
+ export const isLastOverlay = (overlay) => overlay === getAttachedInstances().pop();
23
+
24
+ /**
25
+ * @polymerMixin
26
+ */
27
+ export const OverlayStackMixin = (superClass) =>
28
+ class OverlayStackMixin extends superClass {
29
+ constructor() {
30
+ super();
31
+
32
+ this._hasOverlayStackMixin = true;
33
+ }
34
+
35
+ /**
36
+ * Returns true if this is the last one in the opened overlays stack.
37
+ *
38
+ * @return {boolean}
39
+ * @protected
40
+ */
41
+ get _last() {
42
+ return isLastOverlay(this);
43
+ }
44
+
45
+ /**
46
+ * Brings the overlay as visually the frontmost one.
47
+ */
48
+ bringToFront() {
49
+ let zIndex = '';
50
+ const frontmost = getAttachedInstances()
51
+ .filter((o) => o !== this)
52
+ .pop();
53
+ if (frontmost) {
54
+ const frontmostZIndex = frontmost.__zIndex;
55
+ zIndex = frontmostZIndex + 1;
56
+ }
57
+ this.style.zIndex = zIndex;
58
+ this.__zIndex = zIndex || parseFloat(getComputedStyle(this).zIndex);
59
+ }
60
+
61
+ /** @protected */
62
+ _enterModalState() {
63
+ if (document.body.style.pointerEvents !== 'none') {
64
+ // Set body pointer-events to 'none' to disable mouse interactions with
65
+ // other document nodes.
66
+ this._previousDocumentPointerEvents = document.body.style.pointerEvents;
67
+ document.body.style.pointerEvents = 'none';
68
+ }
69
+
70
+ // Disable pointer events in other attached overlays
71
+ getAttachedInstances().forEach((el) => {
72
+ if (el !== this) {
73
+ el.$.overlay.style.pointerEvents = 'none';
74
+ }
75
+ });
76
+ }
77
+
78
+ /** @protected */
79
+ _exitModalState() {
80
+ if (this._previousDocumentPointerEvents !== undefined) {
81
+ // Restore body pointer-events
82
+ document.body.style.pointerEvents = this._previousDocumentPointerEvents;
83
+ delete this._previousDocumentPointerEvents;
84
+ }
85
+
86
+ // Restore pointer events in the previous overlay(s)
87
+ const instances = getAttachedInstances();
88
+
89
+ let el;
90
+ // Use instances.pop() to ensure the reverse order
91
+ while ((el = instances.pop())) {
92
+ if (el === this) {
93
+ // Skip the current instance
94
+ continue;
95
+ }
96
+ el.$.overlay.style.removeProperty('pointer-events');
97
+ if (!el.modeless) {
98
+ // Stop after the last modal
99
+ break;
100
+ }
101
+ }
102
+ }
103
+ };
@@ -0,0 +1,66 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2017 - 2023 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { css } from 'lit';
7
+
8
+ export const overlayStyles = css`
9
+ :host {
10
+ z-index: 200;
11
+ position: fixed;
12
+
13
+ /* Despite of what the names say, <vaadin-overlay> is just a container
14
+ for position/sizing/alignment. The actual overlay is the overlay part. */
15
+
16
+ /* Default position constraints: the entire viewport. Note: themes can
17
+ override this to introduce gaps between the overlay and the viewport. */
18
+ inset: 0;
19
+ bottom: var(--vaadin-overlay-viewport-bottom);
20
+
21
+ /* Use flexbox alignment for the overlay part. */
22
+ display: flex;
23
+ flex-direction: column; /* makes dropdowns sizing easier */
24
+ /* Align to center by default. */
25
+ align-items: center;
26
+ justify-content: center;
27
+
28
+ /* Allow centering when max-width/max-height applies. */
29
+ margin: auto;
30
+
31
+ /* The host is not clickable, only the overlay part is. */
32
+ pointer-events: none;
33
+
34
+ /* Remove tap highlight on touch devices. */
35
+ -webkit-tap-highlight-color: transparent;
36
+
37
+ /* CSS API for host */
38
+ --vaadin-overlay-viewport-bottom: 0;
39
+ }
40
+
41
+ :host([hidden]),
42
+ :host(:not([opened]):not([closing])) {
43
+ display: none !important;
44
+ }
45
+
46
+ [part='overlay'] {
47
+ -webkit-overflow-scrolling: touch;
48
+ overflow: auto;
49
+ pointer-events: auto;
50
+
51
+ /* Prevent overflowing the host */
52
+ max-width: 100%;
53
+ box-sizing: border-box;
54
+
55
+ -webkit-tap-highlight-color: initial; /* reenable tap highlight inside */
56
+ }
57
+
58
+ [part='backdrop'] {
59
+ z-index: -1;
60
+ content: '';
61
+ background: rgba(0, 0, 0, 0.5);
62
+ position: fixed;
63
+ inset: 0;
64
+ pointer-events: auto;
65
+ }
66
+ `;
@@ -3,12 +3,11 @@
3
3
  * Copyright (c) 2017 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
7
6
  import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
8
7
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
9
- import { OverlayFocusMixin } from './vaadin-overlay-focus-mixin.js';
8
+ import { OverlayMixin } from './vaadin-overlay-mixin.js';
10
9
 
11
- export type OverlayRenderer = (root: HTMLElement, owner: HTMLElement, model?: object) => void;
10
+ export { OverlayRenderer } from './vaadin-overlay-mixin.js';
12
11
 
13
12
  /**
14
13
  * Fired when the `opened` property changes.
@@ -120,69 +119,7 @@ export type OverlayEventMap = HTMLElementEventMap & OverlayCustomEventMap;
120
119
  * @fires {CustomEvent} vaadin-overlay-outside-click - Fired before the overlay is closed on outside click. Calling `preventDefault()` on the event cancels the closing.
121
120
  * @fires {CustomEvent} vaadin-overlay-escape-press - Fired before the overlay is closed on Escape key press. Calling `preventDefault()` on the event cancels the closing.
122
121
  */
123
- declare class Overlay extends OverlayFocusMixin(ThemableMixin(DirMixin(HTMLElement))) {
124
- /**
125
- * When true, the overlay is visible and attached to body.
126
- */
127
- opened: boolean | null | undefined;
128
-
129
- /**
130
- * Owner element passed with renderer function
131
- */
132
- owner: HTMLElement | null;
133
-
134
- /**
135
- * Custom function for rendering the content of the overlay.
136
- * Receives three arguments:
137
- *
138
- * - `root` The root container DOM element. Append your content to it.
139
- * - `owner` The host element of the renderer function.
140
- * - `model` The object with the properties related with rendering.
141
- */
142
- renderer: OverlayRenderer | null | undefined;
143
-
144
- /**
145
- * When true the overlay has backdrop on top of content when opened.
146
- */
147
- withBackdrop: boolean;
148
-
149
- /**
150
- * Object with properties that is passed to `renderer` function
151
- */
152
- model: object | null | undefined;
153
-
154
- /**
155
- * When true the overlay won't disable the main content, showing
156
- * it doesn't change the functionality of the user interface.
157
- */
158
- modeless: boolean;
159
-
160
- /**
161
- * When set to true, the overlay is hidden. This also closes the overlay
162
- * immediately in case there is a closing animation in progress.
163
- */
164
- hidden: boolean;
165
-
166
- /**
167
- * Returns true if this is the last one in the opened overlays stack.
168
- */
169
- protected readonly _last: boolean;
170
-
171
- close(sourceEvent?: Event | null): void;
172
-
173
- /**
174
- * Requests an update for the content of the overlay.
175
- * While performing the update, it invokes the renderer passed in the `renderer` property.
176
- *
177
- * It is not guaranteed that the update happens immediately (synchronously) after it is requested.
178
- */
179
- requestContentUpdate(): void;
180
-
181
- /**
182
- * Brings the overlay as visually the frontmost one
183
- */
184
- bringToFront(): void;
185
-
122
+ declare class Overlay extends OverlayMixin(ThemableMixin(DirMixin(HTMLElement))) {
186
123
  addEventListener<K extends keyof OverlayEventMap>(
187
124
  type: K,
188
125
  listener: (this: Overlay, ev: OverlayEventMap[K]) => void,
@@ -194,14 +131,6 @@ declare class Overlay extends OverlayFocusMixin(ThemableMixin(DirMixin(HTMLEleme
194
131
  listener: (this: Overlay, ev: OverlayEventMap[K]) => void,
195
132
  options?: EventListenerOptions | boolean,
196
133
  ): void;
197
-
198
- protected _flushAnimation(type: 'closing' | 'opening'): void;
199
-
200
- /**
201
- * Whether to close the overlay on outside click or not.
202
- * Override this method to customize the closing logic.
203
- */
204
- protected _shouldCloseOnOutsideClick(event: Event): boolean;
205
134
  }
206
135
 
207
136
  declare global {