@vaadin/component-base 23.0.0-beta2 → 23.0.0-beta3
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": "23.0.0-
|
|
3
|
+
"version": "23.0.0-beta3",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"@vaadin/testing-helpers": "^0.3.2",
|
|
43
43
|
"sinon": "^9.2.4"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "4c87216666541f9eb58f56c475964727822aad53"
|
|
46
46
|
}
|
package/src/element-mixin.js
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { ReactiveController } from 'lit';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A controller for listening on media query changes.
|
|
10
|
+
*/
|
|
11
|
+
export class MediaQueryController implements ReactiveController {
|
|
12
|
+
/**
|
|
13
|
+
* @param {HTMLElement} host
|
|
14
|
+
*/
|
|
15
|
+
constructor(query: string, callback: (matches: boolean) => void);
|
|
16
|
+
|
|
17
|
+
hostConnected(): void;
|
|
18
|
+
|
|
19
|
+
hostDisconnected(): void;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The CSS media query to evaluate.
|
|
23
|
+
*/
|
|
24
|
+
protected query: string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Function to call when media query changes.
|
|
28
|
+
*/
|
|
29
|
+
protected callback: (matches: boolean) => void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A controller for listening on media query changes.
|
|
9
|
+
*/
|
|
10
|
+
export class MediaQueryController {
|
|
11
|
+
constructor(query, callback) {
|
|
12
|
+
/**
|
|
13
|
+
* The CSS media query to evaluate.
|
|
14
|
+
*
|
|
15
|
+
* @type {string}
|
|
16
|
+
* @protected
|
|
17
|
+
*/
|
|
18
|
+
this.query = query;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Function to call when media query changes.
|
|
22
|
+
*
|
|
23
|
+
* @type {Function}
|
|
24
|
+
* @protected
|
|
25
|
+
*/
|
|
26
|
+
this.callback = callback;
|
|
27
|
+
|
|
28
|
+
this._boundQueryHandler = this._queryHandler.bind(this);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
hostConnected() {
|
|
32
|
+
this._removeListener();
|
|
33
|
+
|
|
34
|
+
this._mediaQuery = window.matchMedia(this.query);
|
|
35
|
+
|
|
36
|
+
this._addListener();
|
|
37
|
+
|
|
38
|
+
this._queryHandler(this._mediaQuery);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
hostDisconnected() {
|
|
42
|
+
this._removeListener();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** @private */
|
|
46
|
+
_addListener() {
|
|
47
|
+
if (this._mediaQuery) {
|
|
48
|
+
this._mediaQuery.addListener(this._boundQueryHandler);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** @private */
|
|
53
|
+
_removeListener() {
|
|
54
|
+
if (this._mediaQuery) {
|
|
55
|
+
this._mediaQuery.removeListener(this._boundQueryHandler);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
this._mediaQuery = null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** @private */
|
|
62
|
+
_queryHandler(mediaQuery) {
|
|
63
|
+
if (typeof this.callback === 'function') {
|
|
64
|
+
this.callback(mediaQuery.matches);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|