@vaadin/overlay 23.3.0-alpha4

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,251 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2017 - 2022 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
7
+ import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
8
+ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
9
+
10
+ export type OverlayRenderer = (root: HTMLElement, owner: HTMLElement, model?: object) => void;
11
+
12
+ /**
13
+ * Fired when the `opened` property changes.
14
+ */
15
+ export type OverlayOpenedChangedEvent = CustomEvent<{ value: boolean }>;
16
+
17
+ /**
18
+ * Fired after the overlay is opened.
19
+ */
20
+ export type OverlayOpenEvent = CustomEvent;
21
+
22
+ /**
23
+ * Fired before the overlay will be closed.
24
+ * If canceled the closing of the overlay is canceled as well.
25
+ */
26
+ export type OverlayCloseEvent = CustomEvent;
27
+
28
+ /**
29
+ * Fired when the overlay will be closed.
30
+ */
31
+ export type OverlayClosingEvent = CustomEvent;
32
+
33
+ /**
34
+ * Fired before the overlay will be closed on outside click.
35
+ * If canceled the closing of the overlay is canceled as well.
36
+ */
37
+ export type OverlayOutsideClickEvent = CustomEvent<{ sourceEvent: MouseEvent }>;
38
+
39
+ /**
40
+ * Fired before the overlay will be closed on ESC button press.
41
+ * If canceled the closing of the overlay is canceled as well.
42
+ */
43
+ export type OverlayEscapePressEvent = CustomEvent<{ sourceEvent: KeyboardEvent }>;
44
+
45
+ export interface OverlayCustomEventMap {
46
+ 'opened-changed': OverlayOpenedChangedEvent;
47
+ 'vaadin-overlay-open': OverlayOpenEvent;
48
+ 'vaadin-overlay-close': OverlayCloseEvent;
49
+ 'vaadin-overlay-closing': OverlayClosingEvent;
50
+ 'vaadin-overlay-outside-click': OverlayOutsideClickEvent;
51
+ 'vaadin-overlay-escape-press': OverlayEscapePressEvent;
52
+ }
53
+
54
+ export type OverlayEventMap = HTMLElementEventMap & OverlayCustomEventMap;
55
+
56
+ /**
57
+ * `<vaadin-overlay>` is a Web Component for creating overlays. The content of the overlay
58
+ * can be populated in two ways: imperatively by using renderer callback function and
59
+ * declaratively by using Polymer's Templates.
60
+ *
61
+ * ### Rendering
62
+ *
63
+ * By default, the overlay uses the content provided by using the renderer callback function.
64
+ *
65
+ * The renderer function provides `root`, `owner`, `model` arguments when applicable.
66
+ * Generate DOM content by using `model` object properties if needed, append it to the `root`
67
+ * element and control the state of the host element by accessing `owner`. Before generating new
68
+ * content, users are able to check if there is already content in `root` for reusing it.
69
+ *
70
+ * ```html
71
+ * <vaadin-overlay id="overlay"></vaadin-overlay>
72
+ * ```
73
+ * ```js
74
+ * const overlay = document.querySelector('#overlay');
75
+ * overlay.renderer = function(root) {
76
+ * root.textContent = "Overlay content";
77
+ * };
78
+ * ```
79
+ *
80
+ * Renderer is called on the opening of the overlay and each time the related model is updated.
81
+ * DOM generated during the renderer call can be reused
82
+ * in the next renderer call and will be provided with the `root` argument.
83
+ * On first call it will be empty.
84
+ *
85
+ * **NOTE:** when the renderer property is defined, the `<template>` content is not used.
86
+ *
87
+ * ### Templating
88
+ *
89
+ * Alternatively, the content can be provided with Polymer Template.
90
+ * Overlay finds the first child template and uses that in case renderer callback function
91
+ * is not provided. You can also set a custom template using the `template` property.
92
+ *
93
+ * After the content from the template is stamped, the `content` property
94
+ * points to the content container.
95
+ *
96
+ * The overlay provides `forwardHostProp` when calling
97
+ * `Polymer.Templatize.templatize` for the template, so that the bindings
98
+ * from the parent scope propagate to the content.
99
+ *
100
+ * ```html
101
+ * <vaadin-overlay>
102
+ * <template>Overlay content</template>
103
+ * </vaadin-overlay>
104
+ * ```
105
+ *
106
+ * ### Styling
107
+ *
108
+ * To style the overlay content, use styles in the parent scope:
109
+ *
110
+ * - If the overlay is used in a component, then the component styles
111
+ * apply the overlay content.
112
+ * - If the overlay is used in the global DOM scope, then global styles
113
+ * apply to the overlay content.
114
+ *
115
+ * See examples for styling the overlay content in the live demos.
116
+ *
117
+ * The following Shadow DOM parts are available for styling the overlay component itself:
118
+ *
119
+ * Part name | Description
120
+ * -----------|---------------------------------------------------------|
121
+ * `backdrop` | Backdrop of the overlay
122
+ * `overlay` | Container for position/sizing/alignment of the content
123
+ * `content` | Content of the overlay
124
+ *
125
+ * The following state attributes are available for styling:
126
+ *
127
+ * Attribute | Description | Part
128
+ * ---|---|---
129
+ * `opening` | Applied just after the overlay is attached to the DOM. You can apply a CSS @keyframe animation for this state. | `:host`
130
+ * `closing` | Applied just before the overlay is detached from the DOM. You can apply a CSS @keyframe animation for this state. | `:host`
131
+ *
132
+ * The following custom CSS properties are available for styling:
133
+ *
134
+ * Custom CSS property | Description | Default value
135
+ * ---|---|---
136
+ * `--vaadin-overlay-viewport-bottom` | Bottom offset of the visible viewport area | `0` or detected offset
137
+ *
138
+ * See [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.
139
+ *
140
+ * @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
141
+ * @fires {CustomEvent} vaadin-overlay-open - Fired after the overlay is opened.
142
+ * @fires {CustomEvent} vaadin-overlay-close - Fired before the overlay will be closed. If canceled the closing of the overlay is canceled as well.
143
+ * @fires {CustomEvent} vaadin-overlay-closing - Fired when the overlay will be closed.
144
+ * @fires {CustomEvent} vaadin-overlay-outside-click - Fired before the overlay will be closed on outside click. If canceled the closing of the overlay is canceled as well.
145
+ * @fires {CustomEvent} vaadin-overlay-escape-press - Fired before the overlay will be closed on ESC button press. If canceled the closing of the overlay is canceled as well.
146
+ */
147
+ declare class Overlay extends ThemableMixin(DirMixin(ControllerMixin(HTMLElement))) {
148
+ /**
149
+ * When true, the overlay is visible and attached to body.
150
+ */
151
+ opened: boolean | null | undefined;
152
+
153
+ /**
154
+ * Owner element passed with renderer function
155
+ */
156
+ owner: HTMLElement | null;
157
+
158
+ /**
159
+ * Custom function for rendering the content of the overlay.
160
+ * Receives three arguments:
161
+ *
162
+ * - `root` The root container DOM element. Append your content to it.
163
+ * - `owner` The host element of the renderer function.
164
+ * - `model` The object with the properties related with rendering.
165
+ */
166
+ renderer: OverlayRenderer | null | undefined;
167
+
168
+ /**
169
+ * The template of the overlay content.
170
+ */
171
+ template: HTMLTemplateElement | null | undefined;
172
+
173
+ /**
174
+ * References the content container after the template is stamped.
175
+ */
176
+ content: HTMLElement | undefined;
177
+
178
+ /**
179
+ * When true the overlay has backdrop on top of content when opened.
180
+ */
181
+ withBackdrop: boolean;
182
+
183
+ /**
184
+ * Object with properties that is passed to `renderer` function
185
+ */
186
+ model: object | null | undefined;
187
+
188
+ /**
189
+ * When true the overlay won't disable the main content, showing
190
+ * it doesn’t change the functionality of the user interface.
191
+ */
192
+ modeless: boolean;
193
+
194
+ /**
195
+ * When set to true, the overlay is hidden. This also closes the overlay
196
+ * immediately in case there is a closing animation in progress.
197
+ */
198
+ hidden: boolean;
199
+
200
+ /**
201
+ * When true move focus to the first focusable element in the overlay,
202
+ * or to the overlay if there are no focusable elements.
203
+ */
204
+ focusTrap: boolean;
205
+
206
+ /**
207
+ * Set to true to enable restoring of focus when overlay is closed.
208
+ */
209
+ restoreFocusOnClose: boolean;
210
+
211
+ /**
212
+ * Set to specify the element which should be focused on overlay close,
213
+ * if `restoreFocusOnClose` is set to true.
214
+ */
215
+ restoreFocusNode?: HTMLElement;
216
+
217
+ close(sourceEvent?: Event | null): void;
218
+
219
+ /**
220
+ * Requests an update for the content of the overlay.
221
+ * While performing the update, it invokes the renderer passed in the `renderer` property.
222
+ *
223
+ * It is not guaranteed that the update happens immediately (synchronously) after it is requested.
224
+ */
225
+ requestContentUpdate(): void;
226
+
227
+ /**
228
+ * Brings the overlay as visually the frontmost one
229
+ */
230
+ bringToFront(): void;
231
+
232
+ addEventListener<K extends keyof OverlayEventMap>(
233
+ type: K,
234
+ listener: (this: Overlay, ev: OverlayEventMap[K]) => void,
235
+ options?: AddEventListenerOptions | boolean,
236
+ ): void;
237
+
238
+ removeEventListener<K extends keyof OverlayEventMap>(
239
+ type: K,
240
+ listener: (this: Overlay, ev: OverlayEventMap[K]) => void,
241
+ options?: EventListenerOptions | boolean,
242
+ ): void;
243
+ }
244
+
245
+ declare global {
246
+ interface HTMLElementTagNameMap {
247
+ 'vaadin-overlay': Overlay;
248
+ }
249
+ }
250
+
251
+ export { Overlay };