@proximus/lavender-dropdown 2.0.0-alpha.96 → 2.0.0-alpha.98
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 +5 -0
- package/dist/index.es.js +64 -50
- package/package.json +1 -1
package/dist/Dropdown.d.ts
CHANGED
|
@@ -13,6 +13,9 @@ 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;
|
|
17
20
|
private initPopover;
|
|
18
21
|
private get popoverId();
|
|
@@ -24,4 +27,6 @@ export declare class Dropdown extends WithExtraAttributes {
|
|
|
24
27
|
set anchorAlignment(value: AnchorAlignment);
|
|
25
28
|
get usePolyfill(): boolean;
|
|
26
29
|
set usePolyfill(value: boolean);
|
|
30
|
+
get manualToggle(): boolean;
|
|
31
|
+
set manualToggle(value: boolean);
|
|
27
32
|
}
|
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 u = (o, e, t) => e.has(o) || $("Cannot " + t);
|
|
5
|
+
var g = (o, e, t) => (u(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), m = (o, e, t, s) => (u(o, e, "write to private field"), s ? s.call(o, t) : e.set(o, t), t), b = (o, e, t) => (u(o, e, "access private method"), t);
|
|
6
|
+
import { WithExtraAttributes as T, log as k } from "@proximus/lavender-common";
|
|
7
|
+
const C = ':host{position:relative}::slotted([slot="popover"]){position:absolute;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}: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}}', N = [
|
|
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", s, r = !1) {
|
|
14
|
+
"anchorName" in document.documentElement.style && r === !1 || e.addEventListener("toggle", () => {
|
|
15
|
+
var f, v;
|
|
16
|
+
if (!o || !e)
|
|
17
17
|
return;
|
|
18
|
-
const
|
|
19
|
-
(
|
|
18
|
+
const i = o.getBoundingClientRect(), E = ((f = window.visualViewport) == null ? void 0 : f.height) ?? window.innerHeight, l = ((v = window.visualViewport) == null ? void 0 : v.width) ?? window.innerWidth, p = s.getPropertyValue("--px-padding-s-mobile") || "16px", P = parseInt(
|
|
19
|
+
(s.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} + ${E - 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 - P}px`);
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
var
|
|
28
|
-
class
|
|
24
|
+
const y = new CSSStyleSheet();
|
|
25
|
+
y.replaceSync(C);
|
|
26
|
+
const c = "bottom-left";
|
|
27
|
+
var h, A, n, 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, h);
|
|
32
|
+
d(this, n);
|
|
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
|
+
}, m(this, n, () => {
|
|
44
|
+
this.$popoverElement.matches(":popover-open") && (this.isAboutToClose = !0, this.manualToggle || (this.$trigger.ariaExpanded = "false"));
|
|
40
45
|
}), m(this, a, () => {
|
|
41
|
-
this.$popoverElement.matches(":popover-open") && (this.isAboutToClose = !0, this.$trigger.ariaExpanded = "false");
|
|
42
|
-
}), m(this, h, () => {
|
|
43
46
|
this.$popoverElement.matches(":popover-open") || setTimeout(() => {
|
|
44
47
|
this.isAboutToClose = !1;
|
|
45
48
|
});
|
|
@@ -88,14 +91,15 @@ class L extends C {
|
|
|
88
91
|
...super.observedAttributes,
|
|
89
92
|
"id",
|
|
90
93
|
"anchoralignment",
|
|
91
|
-
"use-polyfill"
|
|
94
|
+
"use-polyfill",
|
|
95
|
+
"manual-toggle"
|
|
92
96
|
];
|
|
93
97
|
}
|
|
94
98
|
connectedCallback() {
|
|
95
99
|
this.getAttribute("id") || this.setAttribute(
|
|
96
100
|
"id",
|
|
97
101
|
`px-dropdown-${Math.random().toString(36).substring(2, 15)}`
|
|
98
|
-
), this.getAttribute("anchoralignment") || this.setAttribute("anchoralignment",
|
|
102
|
+
), this.getAttribute("anchoralignment") || this.setAttribute("anchoralignment", c), x(
|
|
99
103
|
this.$trigger,
|
|
100
104
|
this.$popoverElement,
|
|
101
105
|
this.anchorAlignment,
|
|
@@ -103,14 +107,15 @@ class L extends C {
|
|
|
103
107
|
this.usePolyfill
|
|
104
108
|
);
|
|
105
109
|
}
|
|
106
|
-
attributeChangedCallback(
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
attributeChangedCallback(t, s, r) {
|
|
111
|
+
var i;
|
|
112
|
+
if (s !== r)
|
|
113
|
+
switch (t) {
|
|
109
114
|
case "id":
|
|
110
115
|
this.initPopover();
|
|
111
116
|
break;
|
|
112
117
|
case "use-polyfill":
|
|
113
|
-
|
|
118
|
+
x(
|
|
114
119
|
this.$trigger,
|
|
115
120
|
this.$popoverElement,
|
|
116
121
|
this.anchorAlignment,
|
|
@@ -118,13 +123,16 @@ class L extends C {
|
|
|
118
123
|
this.usePolyfill
|
|
119
124
|
);
|
|
120
125
|
break;
|
|
126
|
+
case "manual-toggle":
|
|
127
|
+
r != null && ((i = this.$trigger) == null || i.removeAttribute("aria-expanded"));
|
|
128
|
+
break;
|
|
121
129
|
default:
|
|
122
|
-
super.attributeChangedCallback(
|
|
130
|
+
super.attributeChangedCallback(t, s, r);
|
|
123
131
|
break;
|
|
124
132
|
}
|
|
125
133
|
}
|
|
126
134
|
initPopover() {
|
|
127
|
-
this.$trigger && (this.$trigger.setAttribute("popovertarget", this.popoverId), this.$trigger.setAttribute("aria-controls", this.
|
|
135
|
+
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, b(this, h, A).call(this), b(this, h, w).call(this));
|
|
128
136
|
}
|
|
129
137
|
get popoverId() {
|
|
130
138
|
return `${this.getAttribute("id")}-popover`;
|
|
@@ -142,36 +150,42 @@ class L extends C {
|
|
|
142
150
|
return this.querySelector('[slot="popover"]');
|
|
143
151
|
}
|
|
144
152
|
get anchorAlignment() {
|
|
145
|
-
return this.getAttribute("anchoralignment") ||
|
|
153
|
+
return this.getAttribute("anchoralignment") || c;
|
|
146
154
|
}
|
|
147
|
-
set anchorAlignment(
|
|
148
|
-
|
|
149
|
-
`Invalid anchor alignment value: ${
|
|
150
|
-
), this.setAttribute("anchoralignment",
|
|
155
|
+
set anchorAlignment(t) {
|
|
156
|
+
N.includes(t) ? this.setAttribute("anchoralignment", t) : (k(
|
|
157
|
+
`Invalid anchor alignment value: ${t}. Using default ${c}.`
|
|
158
|
+
), this.setAttribute("anchoralignment", c));
|
|
151
159
|
}
|
|
152
160
|
get usePolyfill() {
|
|
153
161
|
return this.hasAttribute("use-polyfill");
|
|
154
162
|
}
|
|
155
|
-
set usePolyfill(
|
|
156
|
-
|
|
163
|
+
set usePolyfill(t) {
|
|
164
|
+
t ? this.setAttribute("use-polyfill", "") : this.removeAttribute("use-polyfill");
|
|
165
|
+
}
|
|
166
|
+
get manualToggle() {
|
|
167
|
+
return this.hasAttribute("manual-toggle");
|
|
168
|
+
}
|
|
169
|
+
set manualToggle(t) {
|
|
170
|
+
t ? this.setAttribute("manual-toggle", "") : this.removeAttribute("manual-toggle");
|
|
157
171
|
}
|
|
158
172
|
}
|
|
159
|
-
|
|
160
|
-
this.isAboutToClose = !1, this.$trigger.removeEventListener("click",
|
|
173
|
+
h = new WeakSet(), A = function() {
|
|
174
|
+
this.isAboutToClose = !1, this.manualToggle || this.$trigger.removeEventListener("click", this.triggerPopoverDisplay), this.$popoverElement.removeEventListener(
|
|
161
175
|
"beforetoggle",
|
|
162
|
-
|
|
163
|
-
), this.$popoverElement.removeEventListener("toggle",
|
|
164
|
-
},
|
|
176
|
+
g(this, n)
|
|
177
|
+
), this.$popoverElement.removeEventListener("toggle", g(this, a));
|
|
178
|
+
}, n = new WeakMap(), a = new WeakMap(), /**
|
|
165
179
|
* Handles the manual display of the popover when the trigger is clicked.
|
|
166
180
|
* This is necessary for cases where the trigger is not a button or input element.
|
|
167
181
|
* This method adds event listeners to the trigger element to toggle the popover.
|
|
168
182
|
* It also manages the state of whether the popover is about to close or not to avoid
|
|
169
183
|
* race conditions when the popover is toggled and the trigger click event is fired.
|
|
170
184
|
*/
|
|
171
|
-
|
|
172
|
-
this.$trigger &&
|
|
185
|
+
w = function() {
|
|
186
|
+
this.$trigger && (this.manualToggle || this.$trigger.addEventListener("click", this.triggerPopoverDisplay), this.$popoverElement.addEventListener("beforetoggle", g(this, n)), this.$popoverElement.addEventListener("toggle", g(this, a)));
|
|
173
187
|
};
|
|
174
|
-
customElements.get("px-dropdown") || customElements.define("px-dropdown",
|
|
188
|
+
customElements.get("px-dropdown") || customElements.define("px-dropdown", S);
|
|
175
189
|
export {
|
|
176
|
-
|
|
190
|
+
S as Dropdown
|
|
177
191
|
};
|