@proximus/lavender-dropdown 1.0.1 → 1.0.2
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 +2 -0
- package/dist/anchorPolyfill.d.ts +1 -1
- package/dist/index.es.js +63 -41
- package/package.json +1 -1
package/dist/Dropdown.d.ts
CHANGED
package/dist/anchorPolyfill.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { AnchorAlignment } from './common';
|
|
2
|
-
export declare function anchorPolyfill($trigger: HTMLElement, $popoverElement: HTMLElement, anchorAlignment: AnchorAlignment, computedStyle: CSSStyleDeclaration): void;
|
|
2
|
+
export declare function anchorPolyfill($trigger: HTMLElement, $popoverElement: HTMLElement, anchorAlignment: AnchorAlignment, computedStyle: CSSStyleDeclaration, usePolyfill?: boolean): void;
|
package/dist/index.es.js
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
var
|
|
1
|
+
var x = (o) => {
|
|
2
2
|
throw TypeError(o);
|
|
3
3
|
};
|
|
4
|
-
var
|
|
5
|
-
var s = (o, t, e) => (
|
|
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 } from "@proximus/lavender-common";
|
|
7
|
+
const P = ':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}}', S = [
|
|
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 || t.addEventListener("toggle", () => {
|
|
15
|
-
var
|
|
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
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(e) ? (t.style.bottom = `calc( ${g} + ${
|
|
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
|
-
|
|
24
|
+
const w = new CSSStyleSheet();
|
|
25
|
+
w.replaceSync(P);
|
|
26
26
|
const m = "bottom-left";
|
|
27
|
-
var p,
|
|
28
|
-
class T extends
|
|
27
|
+
var p, A, l, a, h, E;
|
|
28
|
+
class T extends C {
|
|
29
29
|
constructor() {
|
|
30
|
-
super(
|
|
30
|
+
super(w);
|
|
31
31
|
c(this, p);
|
|
32
|
+
c(this, l);
|
|
32
33
|
c(this, a);
|
|
33
34
|
c(this, h);
|
|
34
|
-
c(this, l);
|
|
35
35
|
this.template = () => `
|
|
36
36
|
<style>${this.css}</style>
|
|
37
37
|
<slot name="trigger"></slot>
|
|
38
|
-
<slot name="popover"></slot>`, this.isAboutToClose = !1,
|
|
38
|
+
<slot name="popover"></slot>`, this.isAboutToClose = !1, u(this, l, () => {
|
|
39
39
|
this.isAboutToClose || (this.$popoverElement.togglePopover({ source: this.$trigger }), this.$trigger.ariaExpanded = "true");
|
|
40
|
-
}),
|
|
40
|
+
}), u(this, a, () => {
|
|
41
41
|
this.$popoverElement.matches(":popover-open") && (this.isAboutToClose = !0, this.$trigger.ariaExpanded = "false");
|
|
42
|
-
}),
|
|
42
|
+
}), u(this, h, () => {
|
|
43
43
|
this.$popoverElement.matches(":popover-open") || setTimeout(() => {
|
|
44
44
|
this.isAboutToClose = !1;
|
|
45
45
|
});
|
|
@@ -84,31 +84,47 @@ class T extends N {
|
|
|
84
84
|
}`;
|
|
85
85
|
}
|
|
86
86
|
static get observedAttributes() {
|
|
87
|
-
return [
|
|
87
|
+
return [
|
|
88
|
+
...super.observedAttributes,
|
|
89
|
+
"id",
|
|
90
|
+
"anchoralignment",
|
|
91
|
+
"use-polyfill"
|
|
92
|
+
];
|
|
88
93
|
}
|
|
89
94
|
connectedCallback() {
|
|
90
95
|
this.getAttribute("id") || this.setAttribute(
|
|
91
96
|
"id",
|
|
92
97
|
`px-dropdown-${Math.random().toString(36).substring(2, 15)}`
|
|
93
|
-
), this.getAttribute("anchoralignment") || this.setAttribute("anchoralignment", m),
|
|
98
|
+
), this.getAttribute("anchoralignment") || this.setAttribute("anchoralignment", m), y(
|
|
94
99
|
this.$trigger,
|
|
95
100
|
this.$popoverElement,
|
|
96
101
|
this.anchorAlignment,
|
|
97
|
-
getComputedStyle(this)
|
|
102
|
+
getComputedStyle(this),
|
|
103
|
+
this.usePolyfill
|
|
98
104
|
);
|
|
99
105
|
}
|
|
100
|
-
attributeChangedCallback(e,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
attributeChangedCallback(e, i, d) {
|
|
107
|
+
if (i !== d)
|
|
108
|
+
switch (e) {
|
|
109
|
+
case "id":
|
|
110
|
+
this.initPopover();
|
|
111
|
+
break;
|
|
112
|
+
case "use-polyfill":
|
|
113
|
+
y(
|
|
114
|
+
this.$trigger,
|
|
115
|
+
this.$popoverElement,
|
|
116
|
+
this.anchorAlignment,
|
|
117
|
+
getComputedStyle(this),
|
|
118
|
+
this.usePolyfill
|
|
119
|
+
);
|
|
120
|
+
break;
|
|
121
|
+
default:
|
|
122
|
+
super.attributeChangedCallback(e, i, d);
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
109
125
|
}
|
|
110
126
|
initPopover() {
|
|
111
|
-
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,
|
|
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));
|
|
112
128
|
}
|
|
113
129
|
get popoverId() {
|
|
114
130
|
return `${this.getAttribute("id")}-popover`;
|
|
@@ -129,25 +145,31 @@ class T extends N {
|
|
|
129
145
|
return this.getAttribute("anchoralignment") || m;
|
|
130
146
|
}
|
|
131
147
|
set anchorAlignment(e) {
|
|
132
|
-
|
|
148
|
+
S.includes(e) ? this.setAttribute("anchoralignment", e) : (console.warn(
|
|
133
149
|
`Invalid anchor alignment value: ${e}. Using default ${m}.`
|
|
134
150
|
), this.setAttribute("anchoralignment", m));
|
|
135
151
|
}
|
|
152
|
+
get usePolyfill() {
|
|
153
|
+
return this.hasAttribute("use-polyfill");
|
|
154
|
+
}
|
|
155
|
+
set usePolyfill(e) {
|
|
156
|
+
e ? this.setAttribute("use-polyfill", "") : this.removeAttribute("use-polyfill");
|
|
157
|
+
}
|
|
136
158
|
}
|
|
137
|
-
p = new WeakSet(),
|
|
138
|
-
this.isAboutToClose = !1, this.$trigger.removeEventListener("click", s(this,
|
|
159
|
+
p = new WeakSet(), A = function() {
|
|
160
|
+
this.isAboutToClose = !1, this.$trigger.removeEventListener("click", s(this, l)), this.$popoverElement.removeEventListener(
|
|
139
161
|
"beforetoggle",
|
|
140
|
-
s(this,
|
|
141
|
-
), this.$popoverElement.removeEventListener("toggle", s(this,
|
|
142
|
-
},
|
|
162
|
+
s(this, a)
|
|
163
|
+
), this.$popoverElement.removeEventListener("toggle", s(this, h));
|
|
164
|
+
}, l = new WeakMap(), a = new WeakMap(), h = new WeakMap(), /**
|
|
143
165
|
* Handles the manual display of the popover when the trigger is clicked.
|
|
144
166
|
* This is necessary for cases where the trigger is not a button or input element.
|
|
145
167
|
* This method adds event listeners to the trigger element to toggle the popover.
|
|
146
168
|
* It also manages the state of whether the popover is about to close or not to avoid
|
|
147
169
|
* race conditions when the popover is toggled and the trigger click event is fired.
|
|
148
170
|
*/
|
|
149
|
-
|
|
150
|
-
this.$trigger && !["button", "input"].includes(this.$trigger.localName) && (this.$trigger.addEventListener("click", s(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)));
|
|
151
173
|
};
|
|
152
174
|
customElements.get("px-dropdown") || customElements.define("px-dropdown", T);
|
|
153
175
|
export {
|