@vaadin/component-base 24.0.0-alpha8 → 24.0.0-alpha9
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/component-base",
|
|
3
|
-
"version": "24.0.0-
|
|
3
|
+
"version": "24.0.0-alpha9",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"@vaadin/testing-helpers": "^0.3.2",
|
|
43
43
|
"sinon": "^13.0.2"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "cc3f747164041566b300bde4b105d2475649e93f"
|
|
46
46
|
}
|
package/src/element-mixin.js
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2023 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import type { Constructor } from '@open-wc/dedupe-mixin';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A mixin that forwards CSS class names to the internal overlay element
|
|
10
|
+
* by setting the `overlayClass` property or `overlay-class` attribute.
|
|
11
|
+
*/
|
|
12
|
+
export declare function OverlayClassMixin<T extends Constructor<HTMLElement>>(
|
|
13
|
+
base: T,
|
|
14
|
+
): Constructor<OverlayClassMixinClass> & T;
|
|
15
|
+
|
|
16
|
+
export declare class OverlayClassMixinClass {
|
|
17
|
+
/**
|
|
18
|
+
* A space-delimited list of CSS class names to set on the overlay element.
|
|
19
|
+
* This property does not affect other CSS class names set manually via JS.
|
|
20
|
+
*
|
|
21
|
+
* Note, if the CSS class name was set with this property, clearing it will
|
|
22
|
+
* remove it from the overlay, even if the same class name was also added
|
|
23
|
+
* manually, e.g. by using `classList.add()` in the `renderer` function.
|
|
24
|
+
*
|
|
25
|
+
* @attr {string} overlay-class
|
|
26
|
+
*/
|
|
27
|
+
overlayClass: string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* An overlay element on which CSS class names are set.
|
|
31
|
+
*/
|
|
32
|
+
protected _overlayElement: HTMLElement;
|
|
33
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2023 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A mixin that forwards CSS class names to the internal overlay element
|
|
9
|
+
* by setting the `overlayClass` property or `overlay-class` attribute.
|
|
10
|
+
*
|
|
11
|
+
* @polymerMixin
|
|
12
|
+
*/
|
|
13
|
+
export const OverlayClassMixin = (superclass) =>
|
|
14
|
+
class OverlayClassMixinClass extends superclass {
|
|
15
|
+
static get properties() {
|
|
16
|
+
return {
|
|
17
|
+
/**
|
|
18
|
+
* A space-delimited list of CSS class names to set on the overlay element.
|
|
19
|
+
* This property does not affect other CSS class names set manually via JS.
|
|
20
|
+
*
|
|
21
|
+
* Note, if the CSS class name was set with this property, clearing it will
|
|
22
|
+
* remove it from the overlay, even if the same class name was also added
|
|
23
|
+
* manually, e.g. by using `classList.add()` in the `renderer` function.
|
|
24
|
+
*
|
|
25
|
+
* @attr {string} overlay-class
|
|
26
|
+
*/
|
|
27
|
+
overlayClass: {
|
|
28
|
+
type: String,
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* An overlay element on which CSS class names are set.
|
|
33
|
+
*
|
|
34
|
+
* @protected
|
|
35
|
+
*/
|
|
36
|
+
_overlayElement: {
|
|
37
|
+
type: Object,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static get observers() {
|
|
43
|
+
return ['__updateOverlayClassNames(overlayClass, _overlayElement)'];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** @private */
|
|
47
|
+
__updateOverlayClassNames(overlayClass, overlayElement) {
|
|
48
|
+
if (!overlayElement) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Overlay is set but overlayClass is not set
|
|
53
|
+
if (overlayClass === undefined) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const { classList } = overlayElement;
|
|
58
|
+
|
|
59
|
+
if (!this.__initialClasses) {
|
|
60
|
+
this.__initialClasses = new Set(classList);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (Array.isArray(this.__previousClasses)) {
|
|
64
|
+
// Remove old classes that no longer apply
|
|
65
|
+
const classesToRemove = this.__previousClasses.filter((name) => !this.__initialClasses.has(name));
|
|
66
|
+
if (classesToRemove.length > 0) {
|
|
67
|
+
classList.remove(...classesToRemove);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Add new classes based on the overlayClass
|
|
72
|
+
const classesToAdd = typeof overlayClass === 'string' ? overlayClass.split(' ') : [];
|
|
73
|
+
if (classesToAdd.length > 0) {
|
|
74
|
+
classList.add(...classesToAdd);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
this.__previousClasses = classesToAdd;
|
|
78
|
+
}
|
|
79
|
+
};
|