@proximus/lavender-dropdown 2.0.0-alpha.13 → 2.0.0-alpha.130
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/dist/Dropdown.d.ts +8 -0
- package/dist/index.es.js +81 -51
- package/package.json +2 -2
package/dist/Dropdown.d.ts
CHANGED
|
@@ -13,7 +13,11 @@ export declare class Dropdown extends WithExtraAttributes {
|
|
|
13
13
|
constructor();
|
|
14
14
|
connectedCallback(): void;
|
|
15
15
|
private isAboutToClose;
|
|
16
|
+
triggerPopoverDisplay: () => void;
|
|
17
|
+
showPopover: () => void;
|
|
18
|
+
hidePopover: () => void;
|
|
16
19
|
attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
|
|
20
|
+
updatePopoverHeight(newValue?: string): void;
|
|
17
21
|
private initPopover;
|
|
18
22
|
private get popoverId();
|
|
19
23
|
private get anchorName();
|
|
@@ -24,4 +28,8 @@ export declare class Dropdown extends WithExtraAttributes {
|
|
|
24
28
|
set anchorAlignment(value: AnchorAlignment);
|
|
25
29
|
get usePolyfill(): boolean;
|
|
26
30
|
set usePolyfill(value: boolean);
|
|
31
|
+
get manualToggle(): boolean;
|
|
32
|
+
set manualToggle(value: boolean);
|
|
33
|
+
get popoverHeight(): string;
|
|
34
|
+
set popoverHeight(value: string);
|
|
27
35
|
}
|
package/dist/index.es.js
CHANGED
|
@@ -1,45 +1,48 @@
|
|
|
1
|
-
var
|
|
1
|
+
var $ = (o) => {
|
|
2
2
|
throw TypeError(o);
|
|
3
3
|
};
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
import { WithExtraAttributes as
|
|
7
|
-
const
|
|
4
|
+
var m = (o, e, t) => e.has(o) || $("Cannot " + t);
|
|
5
|
+
var g = (o, e, t) => (m(o, e, "read from private field"), t ? t.call(o) : e.get(o)), d = (o, e, t) => e.has(o) ? $("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(o) : e.set(o, t), u = (o, e, t, r) => (m(o, e, "write to private field"), r ? r.call(o, t) : e.set(o, t), t), v = (o, e, t) => (m(o, e, "access private method"), t);
|
|
6
|
+
import { WithExtraAttributes as T, log as k } from "@proximus/lavender-common";
|
|
7
|
+
const N = ':host{position:relative}::slotted([slot="popover"]){position:fixed;border-radius:var(--px-radius-main, 8px);background:var(--px-color-background-container-light-default, #fff);box-shadow:0 20px 25px -5px #25252514;margin:0;padding:var(--px-padding-xs-mobile) 0;border:0;right:0;width:auto;max-height:var(--px-popover-max-height)}:host([grow]) ::slotted([slot="trigger"]):after{right:0;padding-right:var(--px-padding-xs-mobile)}:host([anchoralignment="top-left"]) ::slotted([slot="popover"]){top:auto}:host([anchoralignment="top-right"]) ::slotted([slot="popover"]){top:auto}:host([anchoralignment="bottom-right"]) ::slotted([slot="popover"]){left:auto}@media screen and (max-width: 47.938rem){::slotted([slot="trigger"]){display:block;width:100%}:host([anchoralignment="top-left"]) ::slotted([slot="popover"]){left:var(--px-padding-s-mobile)}:host([anchoralignment="top-right"]) ::slotted([slot="popover"]){left:var(--px-padding-s-mobile)}}@media screen and (min-width: 48rem){::slotted([slot="popover"]){padding-block:var(--px-padding-s-desktop);right:auto;width:auto}}', C = [
|
|
8
8
|
"top-left",
|
|
9
9
|
"top-right",
|
|
10
10
|
"bottom-left",
|
|
11
11
|
"bottom-right"
|
|
12
12
|
];
|
|
13
|
-
function
|
|
14
|
-
"anchorName" in document.documentElement.style &&
|
|
15
|
-
var
|
|
16
|
-
if (!o || !
|
|
13
|
+
function x(o, e, t = "bottom-left", r, s = !1) {
|
|
14
|
+
"anchorName" in document.documentElement.style && s === !1 || e.addEventListener("toggle", () => {
|
|
15
|
+
var b, f;
|
|
16
|
+
if (!o || !e)
|
|
17
17
|
return;
|
|
18
|
-
const
|
|
19
|
-
(
|
|
18
|
+
const i = o.getBoundingClientRect(), P = ((b = window.visualViewport) == null ? void 0 : b.height) ?? window.innerHeight, l = ((f = window.visualViewport) == null ? void 0 : f.width) ?? window.innerWidth, p = r.getPropertyValue("--px-padding-s-mobile") || "16px", E = parseInt(
|
|
19
|
+
(r.getPropertyValue("--px-icon-size-xs-desktop") || "24").replace("px", "")
|
|
20
20
|
);
|
|
21
|
-
["top-left", "top-right"].includes(
|
|
21
|
+
["top-left", "top-right"].includes(t) ? (e.style.bottom = `calc( ${p} + ${P - i.top - window.scrollY}px)`, e.style.top = "auto", t === "top-left" ? e.style.left = l < 768 ? `${p}px` : `${i.left}px` : e.style.right = l < 768 ? `${p}px` : `${l - i.right}px`) : (e.style.top = `${i.bottom + window.scrollY}px`, t === "bottom-left" ? e.style.left = l < 768 ? `${p}px` : `${i.left}px` : e.style.right = l < 768 ? `${p}px` : `${l - i.right - E}px`);
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
var
|
|
28
|
-
class
|
|
24
|
+
const y = new CSSStyleSheet();
|
|
25
|
+
y.replaceSync(N);
|
|
26
|
+
const c = "bottom-left";
|
|
27
|
+
var n, A, h, a, w;
|
|
28
|
+
class S extends T {
|
|
29
29
|
constructor() {
|
|
30
|
-
super(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
c(this, h);
|
|
30
|
+
super(y);
|
|
31
|
+
d(this, n);
|
|
32
|
+
d(this, h);
|
|
33
|
+
d(this, a);
|
|
35
34
|
this.template = () => `
|
|
36
35
|
<style>${this.css}</style>
|
|
37
36
|
<slot name="trigger"></slot>
|
|
38
|
-
<slot name="popover"></slot>`, this.isAboutToClose = !1,
|
|
39
|
-
this.isAboutToClose || (this.$popoverElement.togglePopover({ source: this.$trigger }), this.$trigger.ariaExpanded = "true");
|
|
37
|
+
<slot name="popover"></slot>`, this.isAboutToClose = !1, this.triggerPopoverDisplay = () => {
|
|
38
|
+
this.isAboutToClose || (this.$popoverElement.togglePopover({ source: this.$trigger }), this.manualToggle || (this.$trigger.ariaExpanded = "true"));
|
|
39
|
+
}, this.showPopover = () => {
|
|
40
|
+
this.isAboutToClose || this.$popoverElement.showPopover();
|
|
41
|
+
}, this.hidePopover = () => {
|
|
42
|
+
this.$popoverElement.hidePopover();
|
|
43
|
+
}, u(this, h, () => {
|
|
44
|
+
this.$popoverElement.matches(":popover-open") && (this.isAboutToClose = !0, this.manualToggle || (this.$trigger.ariaExpanded = "false"));
|
|
40
45
|
}), u(this, a, () => {
|
|
41
|
-
this.$popoverElement.matches(":popover-open") && (this.isAboutToClose = !0, this.$trigger.ariaExpanded = "false");
|
|
42
|
-
}), u(this, h, () => {
|
|
43
46
|
this.$popoverElement.matches(":popover-open") || setTimeout(() => {
|
|
44
47
|
this.isAboutToClose = !1;
|
|
45
48
|
});
|
|
@@ -55,7 +58,7 @@ class T extends C {
|
|
|
55
58
|
anchor-name: ${this.anchorName};
|
|
56
59
|
}
|
|
57
60
|
:host([anchoralignment="bottom-left"]) {
|
|
58
|
-
::slotted([
|
|
61
|
+
::slotted([popover]) {
|
|
59
62
|
position-anchor: ${this.anchorName};
|
|
60
63
|
top: anchor(${this.anchorName} bottom);
|
|
61
64
|
left: anchor(${this.anchorName} left);
|
|
@@ -88,14 +91,16 @@ class T extends C {
|
|
|
88
91
|
...super.observedAttributes,
|
|
89
92
|
"id",
|
|
90
93
|
"anchoralignment",
|
|
91
|
-
"use-polyfill"
|
|
94
|
+
"use-polyfill",
|
|
95
|
+
"manual-toggle",
|
|
96
|
+
"popover-height"
|
|
92
97
|
];
|
|
93
98
|
}
|
|
94
99
|
connectedCallback() {
|
|
95
100
|
this.getAttribute("id") || this.setAttribute(
|
|
96
101
|
"id",
|
|
97
102
|
`px-dropdown-${Math.random().toString(36).substring(2, 15)}`
|
|
98
|
-
), this.getAttribute("anchoralignment") || this.setAttribute("anchoralignment",
|
|
103
|
+
), this.getAttribute("anchoralignment") || this.setAttribute("anchoralignment", c), x(
|
|
99
104
|
this.$trigger,
|
|
100
105
|
this.$popoverElement,
|
|
101
106
|
this.anchorAlignment,
|
|
@@ -103,14 +108,15 @@ class T extends C {
|
|
|
103
108
|
this.usePolyfill
|
|
104
109
|
);
|
|
105
110
|
}
|
|
106
|
-
attributeChangedCallback(
|
|
107
|
-
|
|
108
|
-
|
|
111
|
+
attributeChangedCallback(t, r, s) {
|
|
112
|
+
var i;
|
|
113
|
+
if (r !== s)
|
|
114
|
+
switch (t) {
|
|
109
115
|
case "id":
|
|
110
116
|
this.initPopover();
|
|
111
117
|
break;
|
|
112
118
|
case "use-polyfill":
|
|
113
|
-
|
|
119
|
+
x(
|
|
114
120
|
this.$trigger,
|
|
115
121
|
this.$popoverElement,
|
|
116
122
|
this.anchorAlignment,
|
|
@@ -118,13 +124,25 @@ class T extends C {
|
|
|
118
124
|
this.usePolyfill
|
|
119
125
|
);
|
|
120
126
|
break;
|
|
127
|
+
case "manual-toggle":
|
|
128
|
+
s != null && ((i = this.$trigger) == null || i.removeAttribute("aria-expanded"));
|
|
129
|
+
break;
|
|
130
|
+
case "popover-height":
|
|
131
|
+
this.updatePopoverHeight(s);
|
|
132
|
+
break;
|
|
121
133
|
default:
|
|
122
|
-
super.attributeChangedCallback(
|
|
134
|
+
super.attributeChangedCallback(t, r, s);
|
|
123
135
|
break;
|
|
124
136
|
}
|
|
125
137
|
}
|
|
138
|
+
updatePopoverHeight(t) {
|
|
139
|
+
t ? this.$popoverElement.style.setProperty(
|
|
140
|
+
"--px-popover-max-height",
|
|
141
|
+
t
|
|
142
|
+
) : this.$popoverElement.style.removeProperty("--px-popover-max-height");
|
|
143
|
+
}
|
|
126
144
|
initPopover() {
|
|
127
|
-
this.$trigger && (this.$trigger.setAttribute("popovertarget", this.popoverId), this.$trigger.setAttribute("aria-controls", this.
|
|
145
|
+
this.$trigger && (this.$trigger.setAttribute("popovertarget", this.popoverId), this.$trigger.setAttribute("aria-controls", this.getAttribute("id")), this.hasAttribute("manual-toggle") || this.$trigger.setAttribute("aria-expanded", "false"), this.$popoverElement.setAttribute("id", this.popoverId), this.$popoverElement.setAttribute("popover", ""), this.$style.innerHTML = this.css, v(this, n, A).call(this), v(this, n, w).call(this));
|
|
128
146
|
}
|
|
129
147
|
get popoverId() {
|
|
130
148
|
return `${this.getAttribute("id")}-popover`;
|
|
@@ -142,36 +160,48 @@ class T extends C {
|
|
|
142
160
|
return this.querySelector('[slot="popover"]');
|
|
143
161
|
}
|
|
144
162
|
get anchorAlignment() {
|
|
145
|
-
return this.getAttribute("anchoralignment") ||
|
|
163
|
+
return this.getAttribute("anchoralignment") || c;
|
|
146
164
|
}
|
|
147
|
-
set anchorAlignment(
|
|
148
|
-
|
|
149
|
-
`Invalid anchor alignment value: ${
|
|
150
|
-
), this.setAttribute("anchoralignment",
|
|
165
|
+
set anchorAlignment(t) {
|
|
166
|
+
C.includes(t) ? this.setAttribute("anchoralignment", t) : (k(
|
|
167
|
+
`Invalid anchor alignment value: ${t}. Using default ${c}.`
|
|
168
|
+
), this.setAttribute("anchoralignment", c));
|
|
151
169
|
}
|
|
152
170
|
get usePolyfill() {
|
|
153
171
|
return this.hasAttribute("use-polyfill");
|
|
154
172
|
}
|
|
155
|
-
set usePolyfill(
|
|
156
|
-
|
|
173
|
+
set usePolyfill(t) {
|
|
174
|
+
t ? this.setAttribute("use-polyfill", "") : this.removeAttribute("use-polyfill");
|
|
175
|
+
}
|
|
176
|
+
get manualToggle() {
|
|
177
|
+
return this.hasAttribute("manual-toggle");
|
|
178
|
+
}
|
|
179
|
+
set manualToggle(t) {
|
|
180
|
+
t ? this.setAttribute("manual-toggle", "") : this.removeAttribute("manual-toggle");
|
|
181
|
+
}
|
|
182
|
+
get popoverHeight() {
|
|
183
|
+
return this.getAttribute("popover-height");
|
|
184
|
+
}
|
|
185
|
+
set popoverHeight(t) {
|
|
186
|
+
t ? this.setAttribute("popover-height", t) : this.removeAttribute("popover-height");
|
|
157
187
|
}
|
|
158
188
|
}
|
|
159
|
-
|
|
160
|
-
this.isAboutToClose = !1, this.$trigger.removeEventListener("click",
|
|
189
|
+
n = new WeakSet(), A = function() {
|
|
190
|
+
this.isAboutToClose = !1, this.manualToggle || this.$trigger.removeEventListener("click", this.triggerPopoverDisplay), this.$popoverElement.removeEventListener(
|
|
161
191
|
"beforetoggle",
|
|
162
|
-
|
|
163
|
-
), this.$popoverElement.removeEventListener("toggle",
|
|
164
|
-
},
|
|
192
|
+
g(this, h)
|
|
193
|
+
), this.$popoverElement.removeEventListener("toggle", g(this, a));
|
|
194
|
+
}, h = new WeakMap(), a = new WeakMap(), /**
|
|
165
195
|
* Handles the manual display of the popover when the trigger is clicked.
|
|
166
196
|
* This is necessary for cases where the trigger is not a button or input element.
|
|
167
197
|
* This method adds event listeners to the trigger element to toggle the popover.
|
|
168
198
|
* It also manages the state of whether the popover is about to close or not to avoid
|
|
169
199
|
* race conditions when the popover is toggled and the trigger click event is fired.
|
|
170
200
|
*/
|
|
171
|
-
|
|
172
|
-
this.$trigger && !["button", "input"].includes(this.$trigger.localName) && (this.$trigger.addEventListener("click",
|
|
201
|
+
w = function() {
|
|
202
|
+
this.$trigger && !["button", "input"].includes(this.$trigger.localName) && (this.manualToggle || this.$trigger.addEventListener("click", this.triggerPopoverDisplay), this.$popoverElement.addEventListener("beforetoggle", g(this, h)), this.$popoverElement.addEventListener("toggle", g(this, a)));
|
|
173
203
|
};
|
|
174
|
-
customElements.get("px-dropdown") || customElements.define("px-dropdown",
|
|
204
|
+
customElements.get("px-dropdown") || customElements.define("px-dropdown", S);
|
|
175
205
|
export {
|
|
176
|
-
|
|
206
|
+
S as Dropdown
|
|
177
207
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proximus/lavender-dropdown",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.130",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.es.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"clean": "rm -rf dist",
|
|
14
14
|
"build": "npm run clean && NODE_ENV=development vite build && tsc && npm run transform-package-json && npm run wc-manifest",
|
|
15
15
|
"test": "vitest run --coverage",
|
|
16
|
-
"wc-manifest": "cem analyze --globs \"src/*\" --config
|
|
16
|
+
"wc-manifest": "cem analyze --globs \"src/*\" --config ../../custom-elements-manifest.config.js --outdir dist"
|
|
17
17
|
},
|
|
18
18
|
"publishConfig": {
|
|
19
19
|
"access": "public"
|