@vaadin/overlay 24.0.0-alpha1

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,208 @@
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 imperatively by using `renderer` callback function.
59
+ *
60
+ * ### Rendering
61
+ *
62
+ * The renderer function provides `root`, `owner`, `model` arguments when applicable.
63
+ * Generate DOM content by using `model` object properties if needed, append it to the `root`
64
+ * element and control the state of the host element by accessing `owner`. Before generating new
65
+ * content, users are able to check if there is already content in `root` for reusing it.
66
+ *
67
+ * ```html
68
+ * <vaadin-overlay id="overlay"></vaadin-overlay>
69
+ * ```
70
+ * ```js
71
+ * const overlay = document.querySelector('#overlay');
72
+ * overlay.renderer = function(root) {
73
+ * root.textContent = "Overlay content";
74
+ * };
75
+ * ```
76
+ *
77
+ * Renderer is called on the opening of the overlay and each time the related model is updated.
78
+ * DOM generated during the renderer call can be reused
79
+ * in the next renderer call and will be provided with the `root` argument.
80
+ * On first call it will be empty.
81
+ *
82
+ * ### Styling
83
+ *
84
+ * The following Shadow DOM parts are available for styling:
85
+ *
86
+ * Part name | Description
87
+ * -----------|---------------------------------------------------------|
88
+ * `backdrop` | Backdrop of the overlay
89
+ * `overlay` | Container for position/sizing/alignment of the content
90
+ * `content` | Content of the overlay
91
+ *
92
+ * The following state attributes are available for styling:
93
+ *
94
+ * Attribute | Description | Part
95
+ * ---|---|---
96
+ * `opening` | Applied just after the overlay is attached to the DOM. You can apply a CSS @keyframe animation for this state. | `:host`
97
+ * `closing` | Applied just before the overlay is detached from the DOM. You can apply a CSS @keyframe animation for this state. | `:host`
98
+ *
99
+ * The following custom CSS properties are available for styling:
100
+ *
101
+ * Custom CSS property | Description | Default value
102
+ * ---|---|---
103
+ * `--vaadin-overlay-viewport-bottom` | Bottom offset of the visible viewport area | `0` or detected offset
104
+ *
105
+ * See [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.
106
+ *
107
+ * @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
108
+ * @fires {CustomEvent} vaadin-overlay-open - Fired after the overlay is opened.
109
+ * @fires {CustomEvent} vaadin-overlay-close - Fired before the overlay will be closed. If canceled the closing of the overlay is canceled as well.
110
+ * @fires {CustomEvent} vaadin-overlay-closing - Fired when the overlay will be closed.
111
+ * @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.
112
+ * @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.
113
+ */
114
+ declare class Overlay extends ThemableMixin(DirMixin(ControllerMixin(HTMLElement))) {
115
+ /**
116
+ * When true, the overlay is visible and attached to body.
117
+ */
118
+ opened: boolean | null | undefined;
119
+
120
+ /**
121
+ * Owner element passed with renderer function
122
+ */
123
+ owner: HTMLElement | null;
124
+
125
+ /**
126
+ * Custom function for rendering the content of the overlay.
127
+ * Receives three arguments:
128
+ *
129
+ * - `root` The root container DOM element. Append your content to it.
130
+ * - `owner` The host element of the renderer function.
131
+ * - `model` The object with the properties related with rendering.
132
+ */
133
+ renderer: OverlayRenderer | null | undefined;
134
+
135
+ /**
136
+ * When true the overlay has backdrop on top of content when opened.
137
+ */
138
+ withBackdrop: boolean;
139
+
140
+ /**
141
+ * Object with properties that is passed to `renderer` function
142
+ */
143
+ model: object | null | undefined;
144
+
145
+ /**
146
+ * When true the overlay won't disable the main content, showing
147
+ * it doesn’t change the functionality of the user interface.
148
+ */
149
+ modeless: boolean;
150
+
151
+ /**
152
+ * When set to true, the overlay is hidden. This also closes the overlay
153
+ * immediately in case there is a closing animation in progress.
154
+ */
155
+ hidden: boolean;
156
+
157
+ /**
158
+ * When true move focus to the first focusable element in the overlay,
159
+ * or to the overlay if there are no focusable elements.
160
+ */
161
+ focusTrap: boolean;
162
+
163
+ /**
164
+ * Set to true to enable restoring of focus when overlay is closed.
165
+ */
166
+ restoreFocusOnClose: boolean;
167
+
168
+ /**
169
+ * Set to specify the element which should be focused on overlay close,
170
+ * if `restoreFocusOnClose` is set to true.
171
+ */
172
+ restoreFocusNode?: HTMLElement;
173
+
174
+ close(sourceEvent?: Event | null): void;
175
+
176
+ /**
177
+ * Requests an update for the content of the overlay.
178
+ * While performing the update, it invokes the renderer passed in the `renderer` property.
179
+ *
180
+ * It is not guaranteed that the update happens immediately (synchronously) after it is requested.
181
+ */
182
+ requestContentUpdate(): void;
183
+
184
+ /**
185
+ * Brings the overlay as visually the frontmost one
186
+ */
187
+ bringToFront(): void;
188
+
189
+ addEventListener<K extends keyof OverlayEventMap>(
190
+ type: K,
191
+ listener: (this: Overlay, ev: OverlayEventMap[K]) => void,
192
+ options?: AddEventListenerOptions | boolean,
193
+ ): void;
194
+
195
+ removeEventListener<K extends keyof OverlayEventMap>(
196
+ type: K,
197
+ listener: (this: Overlay, ev: OverlayEventMap[K]) => void,
198
+ options?: EventListenerOptions | boolean,
199
+ ): void;
200
+ }
201
+
202
+ declare global {
203
+ interface HTMLElementTagNameMap {
204
+ 'vaadin-overlay': Overlay;
205
+ }
206
+ }
207
+
208
+ export { Overlay };