@vaadin/popover 24.5.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,92 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2024 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { microTask } from '@vaadin/component-base/src/async.js';
7
+ import { Debouncer } from '@vaadin/component-base/src/debounce.js';
8
+
9
+ /**
10
+ * A mixin providing popover target functionality.
11
+ *
12
+ * @polymerMixin
13
+ */
14
+ export const PopoverTargetMixin = (superClass) =>
15
+ class PopoverTargetMixinClass extends superClass {
16
+ static get properties() {
17
+ return {
18
+ /**
19
+ * The id of the element to be used as `target` value.
20
+ * The element should be in the DOM by the time when
21
+ * the attribute is set, otherwise a warning is shown.
22
+ */
23
+ for: {
24
+ type: String,
25
+ observer: '__forChanged',
26
+ },
27
+
28
+ /**
29
+ * Reference to the DOM element used both to trigger the overlay
30
+ * by user interaction and to visually position it on the screen.
31
+ *
32
+ * Defaults to an element referenced with `for` attribute, in
33
+ * which case it must be located in the same shadow scope.
34
+ */
35
+ target: {
36
+ type: Object,
37
+ observer: '__targetChanged',
38
+ },
39
+ };
40
+ }
41
+
42
+ /** @private */
43
+ __forChanged(forId) {
44
+ if (forId) {
45
+ this.__setTargetByIdDebouncer = Debouncer.debounce(this.__setTargetByIdDebouncer, microTask, () =>
46
+ this.__setTargetById(forId),
47
+ );
48
+ }
49
+ }
50
+
51
+ /** @private */
52
+ __setTargetById(targetId) {
53
+ if (!this.isConnected) {
54
+ return;
55
+ }
56
+
57
+ const target = this.getRootNode().getElementById(targetId);
58
+
59
+ if (target) {
60
+ this.target = target;
61
+ } else {
62
+ console.warn(`No element with id="${targetId}" set via "for" property found on the page.`);
63
+ }
64
+ }
65
+
66
+ /** @private */
67
+ __targetChanged(target, oldTarget) {
68
+ if (oldTarget) {
69
+ this._removeTargetListeners(oldTarget);
70
+ }
71
+
72
+ if (target) {
73
+ this._addTargetListeners(target);
74
+ }
75
+ }
76
+
77
+ /**
78
+ * @param {HTMLElement} _target
79
+ * @protected
80
+ */
81
+ _addTargetListeners(_target) {
82
+ // To be implemented.
83
+ }
84
+
85
+ /**
86
+ * @param {HTMLElement} _target
87
+ * @protected
88
+ */
89
+ _removeTargetListeners(_target) {
90
+ // To be implemented.
91
+ }
92
+ };
@@ -0,0 +1,191 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2024 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
7
+ import { OverlayClassMixin } from '@vaadin/component-base/src/overlay-class-mixin.js';
8
+ import { ThemePropertyMixin } from '@vaadin/vaadin-themable-mixin/vaadin-theme-property-mixin.js';
9
+ import { PopoverPositionMixin } from './vaadin-popover-position-mixin.js';
10
+ import { PopoverTargetMixin } from './vaadin-popover-target-mixin.js';
11
+
12
+ export type { PopoverPosition } from './vaadin-popover-position-mixin.js';
13
+
14
+ export type PopoverRenderer = (root: HTMLElement, popover: Popover) => void;
15
+
16
+ export type PopoverTrigger = 'click' | 'focus' | 'hover';
17
+
18
+ /**
19
+ * Fired when the `opened` property changes.
20
+ */
21
+ export type PopoverOpenedChangedEvent = CustomEvent<{ value: boolean }>;
22
+
23
+ export interface PopoverCustomEventMap {
24
+ 'opened-changed': PopoverOpenedChangedEvent;
25
+ }
26
+
27
+ export type PopoverEventMap = HTMLElementEventMap & PopoverCustomEventMap;
28
+
29
+ /**
30
+ * `<vaadin-popover>` is a Web Component for creating overlays
31
+ * that are positioned next to specified DOM element (target).
32
+ *
33
+ * Unlike `<vaadin-tooltip>`, the popover supports rich content
34
+ * that can be provided by using `renderer` function.
35
+ *
36
+ * @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
37
+ */
38
+ declare class Popover extends PopoverPositionMixin(
39
+ PopoverTargetMixin(OverlayClassMixin(ThemePropertyMixin(ElementMixin(HTMLElement)))),
40
+ ) {
41
+ /**
42
+ * String used to label the overlay to screen reader users.
43
+ *
44
+ * @attr {string} accessible-name
45
+ */
46
+ accessibleName: string | null | undefined;
47
+
48
+ /**
49
+ * Id of the element used as label of the overlay to screen reader users.
50
+ *
51
+ * @attr {string} accessible-name-ref
52
+ */
53
+ accessibleNameRef: string | null | undefined;
54
+
55
+ /**
56
+ * Height to be set on the overlay content.
57
+ *
58
+ * @attr {string} content-height
59
+ */
60
+ contentHeight: string;
61
+
62
+ /**
63
+ * Width to be set on the overlay content.
64
+ *
65
+ * @attr {string} content-width
66
+ */
67
+ contentWidth: string;
68
+
69
+ /**
70
+ * The delay in milliseconds before the popover is opened
71
+ * on focus when the corresponding trigger is used.
72
+ * @attr {number} focus-delay
73
+ */
74
+ focusDelay: number;
75
+
76
+ /**
77
+ * The delay in milliseconds before the popover is closed
78
+ * on losing hover, when the corresponding trigger is used.
79
+ * On blur, the popover is closed immediately.
80
+ * @attr {number} hide-delay
81
+ */
82
+ hideDelay: number;
83
+
84
+ /**
85
+ * The delay in milliseconds before the popover is opened
86
+ * on hover when the corresponding trigger is used.
87
+ * @attr {number} hover-delay
88
+ */
89
+ hoverDelay: number;
90
+
91
+ /**
92
+ * True if the popover overlay is opened, false otherwise.
93
+ */
94
+ opened: boolean;
95
+
96
+ /**
97
+ * The `role` attribute value to be set on the overlay.
98
+ *
99
+ * @attr {string} overlay-role
100
+ */
101
+ overlayRole: string;
102
+
103
+ /**
104
+ * Custom function for rendering the content of the overlay.
105
+ * Receives two arguments:
106
+ *
107
+ * - `root` The root container DOM element. Append your content to it.
108
+ * - `popover` The reference to the `vaadin-popover` element (overlay host).
109
+ */
110
+ renderer: PopoverRenderer | null | undefined;
111
+
112
+ /**
113
+ * When true, the popover prevents interacting with background elements
114
+ * by setting `pointer-events` style on the document body to `none`.
115
+ * This also enables trapping focus inside the overlay.
116
+ */
117
+ modal: boolean;
118
+
119
+ /**
120
+ * Set to true to disable closing popover overlay on outside click.
121
+ *
122
+ * @attr {boolean} no-close-on-outside-click
123
+ */
124
+ noCloseOnOutsideClick: boolean;
125
+
126
+ /**
127
+ * Set to true to disable closing popover overlay on Escape press.
128
+ * When the popover is modal, pressing Escape anywhere in the
129
+ * document closes the overlay. Otherwise, only Escape press
130
+ * from the popover itself or its target closes the overlay.
131
+ *
132
+ * @attr {boolean} no-close-on-esc
133
+ */
134
+ noCloseOnEsc: boolean;
135
+
136
+ /**
137
+ * Popover trigger mode, used to configure how the overlay is opened or closed.
138
+ * Could be set to multiple by providing an array, e.g. `trigger = ['hover', 'focus']`.
139
+ *
140
+ * Supported values:
141
+ * - `click` (default) - opens and closes on target click.
142
+ * - `hover` - opens on target mouseenter, closes on target mouseleave. Moving mouse
143
+ * to the popover overlay content keeps the overlay opened.
144
+ * - `focus` - opens on target focus, closes on target blur. Moving focus to the
145
+ * popover overlay content keeps the overlay opened.
146
+ *
147
+ * In addition to the behavior specified by `trigger`, the popover can be closed by:
148
+ * - pressing Escape key (unless `noCloseOnEsc` property is true)
149
+ * - outside click (unless `noCloseOnOutsideClick` property is true)
150
+ *
151
+ * When setting `trigger` property to `null`, `undefined` or empty array, the popover
152
+ * can be only opened or closed programmatically by changing `opened` property.
153
+ */
154
+ trigger: PopoverTrigger[] | null | undefined;
155
+
156
+ /**
157
+ * When true, the overlay has a backdrop (modality curtain) on top of the
158
+ * underlying page content, covering the whole viewport.
159
+ *
160
+ * @attr {boolean} with-backdrop
161
+ */
162
+ withBackdrop: boolean;
163
+
164
+ /**
165
+ * Requests an update for the content of the popover.
166
+ * While performing the update, it invokes the renderer passed in the `renderer` property.
167
+ *
168
+ * It is not guaranteed that the update happens immediately (synchronously) after it is requested.
169
+ */
170
+ requestContentUpdate(): void;
171
+
172
+ addEventListener<K extends keyof PopoverEventMap>(
173
+ type: K,
174
+ listener: (this: Popover, ev: PopoverEventMap[K]) => void,
175
+ options?: AddEventListenerOptions | boolean,
176
+ ): void;
177
+
178
+ removeEventListener<K extends keyof PopoverEventMap>(
179
+ type: K,
180
+ listener: (this: Popover, ev: PopoverEventMap[K]) => void,
181
+ options?: EventListenerOptions | boolean,
182
+ ): void;
183
+ }
184
+
185
+ declare global {
186
+ interface HTMLElementTagNameMap {
187
+ 'vaadin-popover': Popover;
188
+ }
189
+ }
190
+
191
+ export { Popover };