@proximus/lavender-dropdown 2.0.0-alpha.1 → 2.0.0-alpha.100
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 +7 -0
- package/dist/anchorPolyfill.d.ts +1 -1
- package/dist/index.es.js +88 -52
- package/package.json +2 -2
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();
|
|
@@ -22,4 +25,8 @@ export declare class Dropdown extends WithExtraAttributes {
|
|
|
22
25
|
get $popoverElement(): HTMLElement;
|
|
23
26
|
get anchorAlignment(): AnchorAlignment;
|
|
24
27
|
set anchorAlignment(value: AnchorAlignment);
|
|
28
|
+
get usePolyfill(): boolean;
|
|
29
|
+
set usePolyfill(value: boolean);
|
|
30
|
+
get manualToggle(): boolean;
|
|
31
|
+
set manualToggle(value: boolean);
|
|
25
32
|
}
|
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,48 @@
|
|
|
1
1
|
var $ = (o) => {
|
|
2
2
|
throw TypeError(o);
|
|
3
3
|
};
|
|
4
|
-
var u = (o,
|
|
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 ||
|
|
13
|
+
function x(o, e, t = "bottom-left", s, r = !1) {
|
|
14
|
+
"anchorName" in document.documentElement.style && r === !1 || e.addEventListener("toggle", () => {
|
|
15
15
|
var f, v;
|
|
16
|
-
if (!o || !
|
|
16
|
+
if (!o || !e)
|
|
17
17
|
return;
|
|
18
|
-
const i = o.getBoundingClientRect(),
|
|
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, l);
|
|
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");
|
|
40
|
-
}
|
|
41
|
-
this
|
|
42
|
-
}
|
|
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"));
|
|
45
|
+
}), m(this, a, () => {
|
|
43
46
|
this.$popoverElement.matches(":popover-open") || setTimeout(() => {
|
|
44
47
|
this.isAboutToClose = !1;
|
|
45
48
|
});
|
|
@@ -84,31 +87,52 @@ class T extends N {
|
|
|
84
87
|
}`;
|
|
85
88
|
}
|
|
86
89
|
static get observedAttributes() {
|
|
87
|
-
return [
|
|
90
|
+
return [
|
|
91
|
+
...super.observedAttributes,
|
|
92
|
+
"id",
|
|
93
|
+
"anchoralignment",
|
|
94
|
+
"use-polyfill",
|
|
95
|
+
"manual-toggle"
|
|
96
|
+
];
|
|
88
97
|
}
|
|
89
98
|
connectedCallback() {
|
|
90
99
|
this.getAttribute("id") || this.setAttribute(
|
|
91
100
|
"id",
|
|
92
101
|
`px-dropdown-${Math.random().toString(36).substring(2, 15)}`
|
|
93
|
-
), this.getAttribute("anchoralignment") || this.setAttribute("anchoralignment",
|
|
102
|
+
), this.getAttribute("anchoralignment") || this.setAttribute("anchoralignment", c), x(
|
|
94
103
|
this.$trigger,
|
|
95
104
|
this.$popoverElement,
|
|
96
105
|
this.anchorAlignment,
|
|
97
|
-
getComputedStyle(this)
|
|
106
|
+
getComputedStyle(this),
|
|
107
|
+
this.usePolyfill
|
|
98
108
|
);
|
|
99
109
|
}
|
|
100
|
-
attributeChangedCallback(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
attributeChangedCallback(t, s, r) {
|
|
111
|
+
var i;
|
|
112
|
+
if (s !== r)
|
|
113
|
+
switch (t) {
|
|
114
|
+
case "id":
|
|
115
|
+
this.initPopover();
|
|
116
|
+
break;
|
|
117
|
+
case "use-polyfill":
|
|
118
|
+
x(
|
|
119
|
+
this.$trigger,
|
|
120
|
+
this.$popoverElement,
|
|
121
|
+
this.anchorAlignment,
|
|
122
|
+
getComputedStyle(this),
|
|
123
|
+
this.usePolyfill
|
|
124
|
+
);
|
|
125
|
+
break;
|
|
126
|
+
case "manual-toggle":
|
|
127
|
+
r != null && ((i = this.$trigger) == null || i.removeAttribute("aria-expanded"));
|
|
128
|
+
break;
|
|
129
|
+
default:
|
|
130
|
+
super.attributeChangedCallback(t, s, r);
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
109
133
|
}
|
|
110
134
|
initPopover() {
|
|
111
|
-
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));
|
|
112
136
|
}
|
|
113
137
|
get popoverId() {
|
|
114
138
|
return `${this.getAttribute("id")}-popover`;
|
|
@@ -126,30 +150,42 @@ class T extends N {
|
|
|
126
150
|
return this.querySelector('[slot="popover"]');
|
|
127
151
|
}
|
|
128
152
|
get anchorAlignment() {
|
|
129
|
-
return this.getAttribute("anchoralignment") ||
|
|
153
|
+
return this.getAttribute("anchoralignment") || c;
|
|
154
|
+
}
|
|
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));
|
|
159
|
+
}
|
|
160
|
+
get usePolyfill() {
|
|
161
|
+
return this.hasAttribute("use-polyfill");
|
|
162
|
+
}
|
|
163
|
+
set usePolyfill(t) {
|
|
164
|
+
t ? this.setAttribute("use-polyfill", "") : this.removeAttribute("use-polyfill");
|
|
165
|
+
}
|
|
166
|
+
get manualToggle() {
|
|
167
|
+
return this.hasAttribute("manual-toggle");
|
|
130
168
|
}
|
|
131
|
-
set
|
|
132
|
-
|
|
133
|
-
`Invalid anchor alignment value: ${e}. Using default ${m}.`
|
|
134
|
-
), this.setAttribute("anchoralignment", m));
|
|
169
|
+
set manualToggle(t) {
|
|
170
|
+
t ? this.setAttribute("manual-toggle", "") : this.removeAttribute("manual-toggle");
|
|
135
171
|
}
|
|
136
172
|
}
|
|
137
|
-
|
|
138
|
-
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(
|
|
139
175
|
"beforetoggle",
|
|
140
|
-
|
|
141
|
-
), this.$popoverElement.removeEventListener("toggle",
|
|
142
|
-
},
|
|
176
|
+
g(this, n)
|
|
177
|
+
), this.$popoverElement.removeEventListener("toggle", g(this, a));
|
|
178
|
+
}, n = new WeakMap(), a = new WeakMap(), /**
|
|
143
179
|
* Handles the manual display of the popover when the trigger is clicked.
|
|
144
180
|
* This is necessary for cases where the trigger is not a button or input element.
|
|
145
181
|
* This method adds event listeners to the trigger element to toggle the popover.
|
|
146
182
|
* It also manages the state of whether the popover is about to close or not to avoid
|
|
147
183
|
* race conditions when the popover is toggled and the trigger click event is fired.
|
|
148
184
|
*/
|
|
149
|
-
|
|
150
|
-
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)));
|
|
151
187
|
};
|
|
152
|
-
customElements.get("px-dropdown") || customElements.define("px-dropdown",
|
|
188
|
+
customElements.get("px-dropdown") || customElements.define("px-dropdown", S);
|
|
153
189
|
export {
|
|
154
|
-
|
|
190
|
+
S as Dropdown
|
|
155
191
|
};
|
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.100",
|
|
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"
|