@vaadin/popover 24.5.0-alpha1 → 24.5.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.
- package/README.md +1 -1
- package/lit.d.ts +1 -0
- package/lit.js +1 -0
- package/package.json +14 -11
- package/src/lit/renderer-directives.d.ts +58 -0
- package/src/lit/renderer-directives.js +60 -0
- package/src/vaadin-popover-overlay-mixin.js +6 -0
- package/src/vaadin-popover-overlay.js +14 -4
- package/src/vaadin-popover-target-mixin.js +18 -0
- package/src/vaadin-popover.d.ts +72 -0
- package/src/vaadin-popover.js +272 -18
- package/theme/lumo/vaadin-popover-styles.d.ts +1 -0
- package/theme/lumo/vaadin-popover-styles.js +95 -4
- package/theme/material/vaadin-popover-styles.d.ts +1 -1
- package/theme/material/vaadin-popover-styles.js +95 -4
- package/web-types.json +56 -8
- package/web-types.lit.json +26 -5
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ import '@vaadin/popover/src/vaadin-popover.js';
|
|
|
43
43
|
|
|
44
44
|
## Contributing
|
|
45
45
|
|
|
46
|
-
Read the [contributing guide](https://vaadin.com/docs/latest/contributing
|
|
46
|
+
Read the [contributing guide](https://vaadin.com/docs/latest/contributing) to learn about our development process, how to propose bugfixes and improvements, and how to test your changes to Vaadin components.
|
|
47
47
|
|
|
48
48
|
## License
|
|
49
49
|
|
package/lit.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/lit/renderer-directives.js';
|
package/lit.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/lit/renderer-directives.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/popover",
|
|
3
|
-
"version": "24.5.0-
|
|
3
|
+
"version": "24.5.0-alpha10",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
"module": "vaadin-popover.js",
|
|
21
21
|
"type": "module",
|
|
22
22
|
"files": [
|
|
23
|
+
"lit.d.ts",
|
|
24
|
+
"lit.js",
|
|
23
25
|
"src",
|
|
24
26
|
"theme",
|
|
25
27
|
"vaadin-*.d.ts",
|
|
@@ -35,22 +37,23 @@
|
|
|
35
37
|
],
|
|
36
38
|
"dependencies": {
|
|
37
39
|
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
38
|
-
"@vaadin/a11y-base": "24.5.0-
|
|
39
|
-
"@vaadin/component-base": "24.5.0-
|
|
40
|
-
"@vaadin/
|
|
41
|
-
"@vaadin/
|
|
42
|
-
"@vaadin/vaadin-
|
|
43
|
-
"@vaadin/vaadin-
|
|
40
|
+
"@vaadin/a11y-base": "24.5.0-alpha10",
|
|
41
|
+
"@vaadin/component-base": "24.5.0-alpha10",
|
|
42
|
+
"@vaadin/lit-renderer": "24.5.0-alpha10",
|
|
43
|
+
"@vaadin/overlay": "24.5.0-alpha10",
|
|
44
|
+
"@vaadin/vaadin-lumo-styles": "24.5.0-alpha10",
|
|
45
|
+
"@vaadin/vaadin-material-styles": "24.5.0-alpha10",
|
|
46
|
+
"@vaadin/vaadin-themable-mixin": "24.5.0-alpha10",
|
|
44
47
|
"lit": "^3.0.0"
|
|
45
48
|
},
|
|
46
49
|
"devDependencies": {
|
|
47
|
-
"@
|
|
48
|
-
"@vaadin/testing-helpers": "^0.
|
|
49
|
-
"sinon": "^
|
|
50
|
+
"@vaadin/chai-plugins": "24.5.0-alpha10",
|
|
51
|
+
"@vaadin/testing-helpers": "^1.0.0",
|
|
52
|
+
"sinon": "^18.0.0"
|
|
50
53
|
},
|
|
51
54
|
"web-types": [
|
|
52
55
|
"web-types.json",
|
|
53
56
|
"web-types.lit.json"
|
|
54
57
|
],
|
|
55
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "6f9c37308031af872a98017bfab4de89aeacda51"
|
|
56
59
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
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 type { DirectiveResult } from 'lit/directive.js';
|
|
7
|
+
import { LitRendererDirective, type LitRendererResult } from '@vaadin/lit-renderer';
|
|
8
|
+
import type { Popover } from '../vaadin-popover.js';
|
|
9
|
+
|
|
10
|
+
export type PopoverLitRenderer = (popover: Popover) => LitRendererResult;
|
|
11
|
+
|
|
12
|
+
export class PopoverRendererDirective extends LitRendererDirective<Popover, PopoverLitRenderer> {
|
|
13
|
+
/**
|
|
14
|
+
* Adds the renderer callback to the popover.
|
|
15
|
+
*/
|
|
16
|
+
addRenderer(): void;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Runs the renderer callback on the popover.
|
|
20
|
+
*/
|
|
21
|
+
runRenderer(): void;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Removes the renderer callback from the popover.
|
|
25
|
+
*/
|
|
26
|
+
removeRenderer(): void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A Lit directive for populating the content of the `<vaadin-popover-overlay>` element.
|
|
31
|
+
*
|
|
32
|
+
* The directive accepts a renderer callback returning a Lit template and assigns it to the popover
|
|
33
|
+
* via the `renderer` property. The renderer is called once to populate the content when assigned
|
|
34
|
+
* and whenever a single dependency or an array of dependencies changes.
|
|
35
|
+
* It is not guaranteed that the renderer will be called immediately (synchronously) in both cases.
|
|
36
|
+
*
|
|
37
|
+
* Dependencies can be a single value or an array of values.
|
|
38
|
+
* Values are checked against previous values with strict equality (`===`),
|
|
39
|
+
* so the check won't detect nested property changes inside objects or arrays.
|
|
40
|
+
* When dependencies are provided as an array, each item is checked against the previous value
|
|
41
|
+
* at the same index with strict equality. Nested arrays are also checked only by strict
|
|
42
|
+
* equality.
|
|
43
|
+
*
|
|
44
|
+
* Example of usage:
|
|
45
|
+
* ```js
|
|
46
|
+
* `<vaadin-popover
|
|
47
|
+
* ${popoverRenderer((popover) => html`...`)}
|
|
48
|
+
* ></vaadin-popover>`
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @param renderer the renderer callback that returns a Lit template.
|
|
52
|
+
* @param dependencies a single dependency or an array of dependencies
|
|
53
|
+
* which trigger a re-render when changed.
|
|
54
|
+
*/
|
|
55
|
+
export declare function popoverRenderer(
|
|
56
|
+
renderer: PopoverLitRenderer,
|
|
57
|
+
dependencies?: unknown,
|
|
58
|
+
): DirectiveResult<typeof PopoverRendererDirective>;
|
|
@@ -0,0 +1,60 @@
|
|
|
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 { directive } from 'lit/directive.js';
|
|
7
|
+
import { LitRendererDirective } from '@vaadin/lit-renderer';
|
|
8
|
+
|
|
9
|
+
export class PopoverRendererDirective extends LitRendererDirective {
|
|
10
|
+
/**
|
|
11
|
+
* Adds the renderer callback to the popover.
|
|
12
|
+
*/
|
|
13
|
+
addRenderer() {
|
|
14
|
+
this.element.renderer = (root, popover) => {
|
|
15
|
+
this.renderRenderer(root, popover);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Runs the renderer callback on the popover.
|
|
21
|
+
*/
|
|
22
|
+
runRenderer() {
|
|
23
|
+
this.element.requestContentUpdate();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Removes the renderer callback from the popover.
|
|
28
|
+
*/
|
|
29
|
+
removeRenderer() {
|
|
30
|
+
this.element.renderer = null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A Lit directive for populating the content of the `<vaadin-popover-overlay>` element.
|
|
36
|
+
*
|
|
37
|
+
* The directive accepts a renderer callback returning a Lit template and assigns it to the popover
|
|
38
|
+
* via the `renderer` property. The renderer is called once to populate the content when assigned
|
|
39
|
+
* and whenever a single dependency or an array of dependencies changes.
|
|
40
|
+
* It is not guaranteed that the renderer will be called immediately (synchronously) in both cases.
|
|
41
|
+
*
|
|
42
|
+
* Dependencies can be a single value or an array of values.
|
|
43
|
+
* Values are checked against previous values with strict equality (`===`),
|
|
44
|
+
* so the check won't detect nested property changes inside objects or arrays.
|
|
45
|
+
* When dependencies are provided as an array, each item is checked against the previous value
|
|
46
|
+
* at the same index with strict equality. Nested arrays are also checked only by strict
|
|
47
|
+
* equality.
|
|
48
|
+
*
|
|
49
|
+
* Example of usage:
|
|
50
|
+
* ```js
|
|
51
|
+
* `<vaadin-popover
|
|
52
|
+
* ${popoverRenderer((popover) => html`...`)}
|
|
53
|
+
* ></vaadin-popover>`
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @param renderer the renderer callback that returns a Lit template.
|
|
57
|
+
* @param dependencies a single dependency or an array of dependencies
|
|
58
|
+
* which trigger a re-render when changed.
|
|
59
|
+
*/
|
|
60
|
+
export const popoverRenderer = directive(PopoverRendererDirective);
|
|
@@ -59,6 +59,8 @@ export const PopoverOverlayMixin = (superClass) =>
|
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
this.removeAttribute('arrow-centered');
|
|
63
|
+
|
|
62
64
|
// Center the overlay horizontally
|
|
63
65
|
if (this.position === 'bottom' || this.position === 'top') {
|
|
64
66
|
const targetRect = this.positionTarget.getBoundingClientRect();
|
|
@@ -70,6 +72,8 @@ export const PopoverOverlayMixin = (superClass) =>
|
|
|
70
72
|
const left = overlayRect.left + offset;
|
|
71
73
|
if (left > 0) {
|
|
72
74
|
this.style.left = `${left}px`;
|
|
75
|
+
// Center the pointer arrow horizontally
|
|
76
|
+
this.setAttribute('arrow-centered', '');
|
|
73
77
|
}
|
|
74
78
|
}
|
|
75
79
|
|
|
@@ -77,6 +81,8 @@ export const PopoverOverlayMixin = (superClass) =>
|
|
|
77
81
|
const right = parseFloat(this.style.right) + offset;
|
|
78
82
|
if (right > 0) {
|
|
79
83
|
this.style.right = `${right}px`;
|
|
84
|
+
// Center the pointer arrow horizontally
|
|
85
|
+
this.setAttribute('arrow-centered', '');
|
|
80
86
|
}
|
|
81
87
|
}
|
|
82
88
|
}
|
|
@@ -60,10 +60,8 @@ class PopoverOverlay extends PopoverOverlayMixin(DirMixin(ThemableMixin(PolylitM
|
|
|
60
60
|
[part='overlay']::before {
|
|
61
61
|
position: absolute;
|
|
62
62
|
content: '';
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
inset-inline-start: calc(var(--vaadin-popover-offset-start, 0) * -1);
|
|
66
|
-
inset-inline-end: calc(var(--vaadin-popover-offset-end, 0) * -1);
|
|
63
|
+
inset-block: calc(var(--vaadin-popover-offset-top, 0) * -1) calc(var(--vaadin-popover-offset-bottom, 0) * -1);
|
|
64
|
+
inset-inline: calc(var(--vaadin-popover-offset-start, 0) * -1) calc(var(--vaadin-popover-offset-end, 0) * -1);
|
|
67
65
|
z-index: -1;
|
|
68
66
|
pointer-events: auto;
|
|
69
67
|
}
|
|
@@ -82,6 +80,17 @@ class PopoverOverlay extends PopoverOverlayMixin(DirMixin(ThemableMixin(PolylitM
|
|
|
82
80
|
:host([position^='end'][end-aligned]) [part='overlay'] {
|
|
83
81
|
margin-inline-end: var(--vaadin-popover-offset-end, 0);
|
|
84
82
|
}
|
|
83
|
+
|
|
84
|
+
[part='arrow'] {
|
|
85
|
+
display: none;
|
|
86
|
+
position: absolute;
|
|
87
|
+
height: 0;
|
|
88
|
+
width: 0;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
:host([theme~='arrow']) [part='arrow'] {
|
|
92
|
+
display: block;
|
|
93
|
+
}
|
|
85
94
|
`,
|
|
86
95
|
];
|
|
87
96
|
}
|
|
@@ -91,6 +100,7 @@ class PopoverOverlay extends PopoverOverlayMixin(DirMixin(ThemableMixin(PolylitM
|
|
|
91
100
|
return html`
|
|
92
101
|
<div id="backdrop" part="backdrop" hidden ?hidden="${!this.withBackdrop}"></div>
|
|
93
102
|
<div part="overlay" id="overlay" tabindex="0">
|
|
103
|
+
<div part="arrow"></div>
|
|
94
104
|
<div part="content" id="content"><slot></slot></div>
|
|
95
105
|
</div>
|
|
96
106
|
`;
|
|
@@ -39,6 +39,24 @@ export const PopoverTargetMixin = (superClass) =>
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/** @protected */
|
|
43
|
+
connectedCallback() {
|
|
44
|
+
super.connectedCallback();
|
|
45
|
+
|
|
46
|
+
if (this.target) {
|
|
47
|
+
this._addTargetListeners(this.target);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** @protected */
|
|
52
|
+
disconnectedCallback() {
|
|
53
|
+
super.disconnectedCallback();
|
|
54
|
+
|
|
55
|
+
if (this.target) {
|
|
56
|
+
this._removeTargetListeners(this.target);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
42
60
|
/** @private */
|
|
43
61
|
__forChanged(forId) {
|
|
44
62
|
if (forId) {
|
package/src/vaadin-popover.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export type PopoverOpenedChangedEvent = CustomEvent<{ value: boolean }>;
|
|
|
22
22
|
|
|
23
23
|
export interface PopoverCustomEventMap {
|
|
24
24
|
'opened-changed': PopoverOpenedChangedEvent;
|
|
25
|
+
|
|
26
|
+
closed: Event;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
export type PopoverEventMap = HTMLElementEventMap & PopoverCustomEventMap;
|
|
@@ -33,11 +35,66 @@ export type PopoverEventMap = HTMLElementEventMap & PopoverCustomEventMap;
|
|
|
33
35
|
* Unlike `<vaadin-tooltip>`, the popover supports rich content
|
|
34
36
|
* that can be provided by using `renderer` function.
|
|
35
37
|
*
|
|
38
|
+
* ### Styling
|
|
39
|
+
*
|
|
40
|
+
* `<vaadin-popover>` uses `<vaadin-popover-overlay>` internal
|
|
41
|
+
* themable component as the actual visible overlay.
|
|
42
|
+
*
|
|
43
|
+
* See [`<vaadin-overlay>`](#/elements/vaadin-overlay) documentation
|
|
44
|
+
* for `<vaadin-popover-overlay>` parts.
|
|
45
|
+
*
|
|
46
|
+
* In addition to `<vaadin-overlay>` parts, the following parts are available for styling:
|
|
47
|
+
*
|
|
48
|
+
* Part name | Description
|
|
49
|
+
* -----------------|-------------------------------------------
|
|
50
|
+
* `arrow` | Optional arrow pointing to the target when using `theme="arrow"`
|
|
51
|
+
*
|
|
52
|
+
* The following state attributes are available for styling:
|
|
53
|
+
*
|
|
54
|
+
* Attribute | Description
|
|
55
|
+
* -----------------|----------------------------------------
|
|
56
|
+
* `position` | Reflects the `position` property value.
|
|
57
|
+
*
|
|
58
|
+
* Note: the `theme` attribute value set on `<vaadin-popover>` is
|
|
59
|
+
* propagated to the internal `<vaadin-popover-overlay>` component.
|
|
60
|
+
*
|
|
61
|
+
* ### Custom CSS Properties
|
|
62
|
+
*
|
|
63
|
+
* The following custom CSS properties are available on the `<vaadin-popover>` element:
|
|
64
|
+
*
|
|
65
|
+
* Custom CSS property | Description
|
|
66
|
+
* ---------------------------------|-------------
|
|
67
|
+
* `--vaadin-popover-offset-top` | Used as an offset when the popover is aligned vertically below the target
|
|
68
|
+
* `--vaadin-popover-offset-bottom` | Used as an offset when the popover is aligned vertically above the target
|
|
69
|
+
* `--vaadin-popover-offset-start` | Used as an offset when the popover is aligned horizontally after the target
|
|
70
|
+
* `--vaadin-popover-offset-end` | Used as an offset when the popover is aligned horizontally before the target
|
|
71
|
+
*
|
|
72
|
+
* See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
|
|
73
|
+
*
|
|
36
74
|
* @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
|
|
75
|
+
* @fires {CustomEvent} closed - Fired when the popover is closed.
|
|
37
76
|
*/
|
|
38
77
|
declare class Popover extends PopoverPositionMixin(
|
|
39
78
|
PopoverTargetMixin(OverlayClassMixin(ThemePropertyMixin(ElementMixin(HTMLElement)))),
|
|
40
79
|
) {
|
|
80
|
+
/**
|
|
81
|
+
* Sets the default focus delay to be used by all popover instances,
|
|
82
|
+
* except for those that have focus delay configured using property.
|
|
83
|
+
*/
|
|
84
|
+
static setDefaultFocusDelay(focusDelay: number): void;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Sets the default hide delay to be used by all popover instances,
|
|
88
|
+
* except for those that have hide delay configured using property.
|
|
89
|
+
*/
|
|
90
|
+
static setDefaultHideDelay(hideDelay: number): void;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Sets the default hover delay to be used by all popover instances,
|
|
94
|
+
* except for those that have hover delay configured using property.
|
|
95
|
+
*/
|
|
96
|
+
static setDefaultHoverDelay(delay: number): void;
|
|
97
|
+
|
|
41
98
|
/**
|
|
42
99
|
* String used to label the overlay to screen reader users.
|
|
43
100
|
*
|
|
@@ -52,6 +109,12 @@ declare class Popover extends PopoverPositionMixin(
|
|
|
52
109
|
*/
|
|
53
110
|
accessibleNameRef: string | null | undefined;
|
|
54
111
|
|
|
112
|
+
/**
|
|
113
|
+
* When true, the popover content automatically receives focus after
|
|
114
|
+
* it is opened. Modal popovers use this behavior by default.
|
|
115
|
+
*/
|
|
116
|
+
autofocus: boolean;
|
|
117
|
+
|
|
55
118
|
/**
|
|
56
119
|
* Height to be set on the overlay content.
|
|
57
120
|
*
|
|
@@ -69,6 +132,9 @@ declare class Popover extends PopoverPositionMixin(
|
|
|
69
132
|
/**
|
|
70
133
|
* The delay in milliseconds before the popover is opened
|
|
71
134
|
* on focus when the corresponding trigger is used.
|
|
135
|
+
*
|
|
136
|
+
* When not specified, the global default (500ms) is used.
|
|
137
|
+
*
|
|
72
138
|
* @attr {number} focus-delay
|
|
73
139
|
*/
|
|
74
140
|
focusDelay: number;
|
|
@@ -77,6 +143,9 @@ declare class Popover extends PopoverPositionMixin(
|
|
|
77
143
|
* The delay in milliseconds before the popover is closed
|
|
78
144
|
* on losing hover, when the corresponding trigger is used.
|
|
79
145
|
* On blur, the popover is closed immediately.
|
|
146
|
+
*
|
|
147
|
+
* When not specified, the global default (500ms) is used.
|
|
148
|
+
*
|
|
80
149
|
* @attr {number} hide-delay
|
|
81
150
|
*/
|
|
82
151
|
hideDelay: number;
|
|
@@ -84,6 +153,9 @@ declare class Popover extends PopoverPositionMixin(
|
|
|
84
153
|
/**
|
|
85
154
|
* The delay in milliseconds before the popover is opened
|
|
86
155
|
* on hover when the corresponding trigger is used.
|
|
156
|
+
*
|
|
157
|
+
* When not specified, the global default (500ms) is used.
|
|
158
|
+
*
|
|
87
159
|
* @attr {number} hover-delay
|
|
88
160
|
*/
|
|
89
161
|
hoverDelay: number;
|