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