@proximus/lavender-dropdown 2.0.0-alpha.165 → 2.0.0-alpha.169
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 -2
- package/dist/anchorPolyfill.d.ts +1 -1
- package/dist/index.es.js +132 -174
- package/package.json +1 -1
package/dist/Dropdown.d.ts
CHANGED
|
@@ -30,6 +30,6 @@ export declare class Dropdown extends WithExtraAttributes {
|
|
|
30
30
|
set usePolyfill(value: boolean);
|
|
31
31
|
get manualToggle(): boolean;
|
|
32
32
|
set manualToggle(value: boolean);
|
|
33
|
-
get popoverHeight(): string;
|
|
34
|
-
set popoverHeight(value: string);
|
|
33
|
+
get popoverHeight(): string | null;
|
|
34
|
+
set popoverHeight(value: string | null);
|
|
35
35
|
}
|
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, usePolyfill?: boolean): void;
|
|
2
|
+
export declare function anchorPolyfill($trigger: HTMLElement, $popoverElement: HTMLElement, anchorAlignment: AnchorAlignment | undefined, computedStyle: CSSStyleDeclaration, usePolyfill?: boolean): void;
|
package/dist/index.es.js
CHANGED
|
@@ -1,60 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
};
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"top-left",
|
|
9
|
-
"top-right",
|
|
10
|
-
"bottom-left",
|
|
11
|
-
"bottom-right"
|
|
1
|
+
import { WithExtraAttributes as e, log as t, propertyToAttributeSetter as n } from "@proximus/lavender-common";
|
|
2
|
+
//#region src/dropdown.css?inline
|
|
3
|
+
var r = ":host{position:relative}::slotted([slot=popover]){border-radius:var(--px-radius-main,8px);background:var(--px-color-background-container-light-default,#fff);padding:var(--px-padding-xs-mobile) 0;width:auto;max-height:var(--px-popover-max-height);border:0;margin:0;position:fixed;right:0;box-shadow:0 20px 25px -5px #25252514}:host([grow]) ::slotted([slot=trigger]):after{padding-right:var(--px-padding-xs-mobile);right:0}: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 (width<=47.938rem){::slotted([slot=trigger]){width:100%;display:block}: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 (width>=48rem){::slotted([slot=popover]){padding-block:var(--px-padding-s-desktop);width:auto;right:auto}}", i = [
|
|
4
|
+
"top-left",
|
|
5
|
+
"top-right",
|
|
6
|
+
"bottom-left",
|
|
7
|
+
"bottom-right"
|
|
12
8
|
];
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
});
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/anchorPolyfill.ts
|
|
11
|
+
function a(e, t, n = "bottom-left", r, i = !1) {
|
|
12
|
+
"anchorName" in document.documentElement.style && i === !1 || t.addEventListener("toggle", () => {
|
|
13
|
+
if (!e || !t) return;
|
|
14
|
+
let i = e.getBoundingClientRect(), a = window.visualViewport?.height ?? window.innerHeight, o = window.visualViewport?.width ?? window.innerWidth, s = r.getPropertyValue("--px-padding-s-mobile") || "16px", c = parseInt((r.getPropertyValue("--px-icon-size-xs-desktop") || "24").replace("px", ""));
|
|
15
|
+
["top-left", "top-right"].includes(n) ? (t.style.bottom = `calc( ${s} + ${a - i.top - window.scrollY}px)`, t.style.top = "auto", n === "top-left" ? t.style.left = o < 768 ? `${s}px` : `${i.left}px` : t.style.right = o < 768 ? `${s}px` : `${o - i.right}px`) : (t.style.top = `${i.bottom + window.scrollY}px`, n === "bottom-left" ? t.style.left = o < 768 ? `${s}px` : `${i.left}px` : t.style.right = o < 768 ? `${s}px` : `${o - i.right - c}px`);
|
|
16
|
+
});
|
|
23
17
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
d(this, h);
|
|
33
|
-
d(this, a);
|
|
34
|
-
this.template = () => `
|
|
35
|
-
<style>${this.css}</style>
|
|
36
|
-
<slot name="trigger"></slot>
|
|
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"));
|
|
45
|
-
}), u(this, a, () => {
|
|
46
|
-
this.$popoverElement.matches(":popover-open") || setTimeout(() => {
|
|
47
|
-
this.isAboutToClose = !1;
|
|
48
|
-
});
|
|
49
|
-
}), this.shadowRoot.innerHTML = this.template();
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Instance level styling for the dropdown component.
|
|
53
|
-
* This is used to set the anchor name and position of the popover.
|
|
54
|
-
* @private
|
|
55
|
-
*/
|
|
56
|
-
get css() {
|
|
57
|
-
return `::slotted([slot='trigger']) {
|
|
18
|
+
/* v8 ignore end */
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/Dropdown.ts
|
|
21
|
+
var o = new CSSStyleSheet();
|
|
22
|
+
o.replaceSync(r);
|
|
23
|
+
var s = "bottom-left", c = class extends e {
|
|
24
|
+
get css() {
|
|
25
|
+
return `::slotted([slot='trigger']) {
|
|
58
26
|
anchor-name: ${this.anchorName};
|
|
59
27
|
}
|
|
60
28
|
:host([anchoralignment="bottom-left"]) {
|
|
@@ -85,123 +53,113 @@ class S extends T {
|
|
|
85
53
|
right: anchor(${this.anchorName} right);
|
|
86
54
|
}
|
|
87
55
|
}`;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}, h = new WeakMap(), a = new WeakMap(), /**
|
|
195
|
-
* Handles the manual display of the popover when the trigger is clicked.
|
|
196
|
-
* This is necessary for cases where the trigger is not a button or input element.
|
|
197
|
-
* This method adds event listeners to the trigger element to toggle the popover.
|
|
198
|
-
* It also manages the state of whether the popover is about to close or not to avoid
|
|
199
|
-
* race conditions when the popover is toggled and the trigger click event is fired.
|
|
200
|
-
*/
|
|
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)));
|
|
203
|
-
};
|
|
204
|
-
customElements.get("px-dropdown") || customElements.define("px-dropdown", S);
|
|
205
|
-
export {
|
|
206
|
-
S as Dropdown
|
|
56
|
+
}
|
|
57
|
+
static get observedAttributes() {
|
|
58
|
+
return [
|
|
59
|
+
...super.observedAttributes,
|
|
60
|
+
"id",
|
|
61
|
+
"anchoralignment",
|
|
62
|
+
"use-polyfill",
|
|
63
|
+
"manual-toggle",
|
|
64
|
+
"popover-height"
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
constructor() {
|
|
68
|
+
super(o), this.template = () => `
|
|
69
|
+
<style>${this.css}</style>
|
|
70
|
+
<slot name="trigger"></slot>
|
|
71
|
+
<slot name="popover"></slot>`, this.isAboutToClose = !1, this.triggerPopoverDisplay = () => {
|
|
72
|
+
this.isAboutToClose || (this.$popoverElement.togglePopover({ source: this.$trigger }), this.manualToggle || (this.$trigger.ariaExpanded = "true"));
|
|
73
|
+
}, this.showPopover = () => {
|
|
74
|
+
this.isAboutToClose || this.$popoverElement.showPopover();
|
|
75
|
+
}, this.hidePopover = () => {
|
|
76
|
+
this.$popoverElement.hidePopover();
|
|
77
|
+
}, this.#t = () => {
|
|
78
|
+
this.$popoverElement.matches(":popover-open") && (this.isAboutToClose = !0, this.manualToggle || (this.$trigger.ariaExpanded = "false"));
|
|
79
|
+
}, this.#n = () => {
|
|
80
|
+
this.$popoverElement.matches(":popover-open") || setTimeout(() => {
|
|
81
|
+
this.isAboutToClose = !1;
|
|
82
|
+
});
|
|
83
|
+
}, this.shadowRoot.innerHTML = this.template();
|
|
84
|
+
}
|
|
85
|
+
connectedCallback() {
|
|
86
|
+
this.getAttribute("id") || this.setAttribute("id", `px-dropdown-${Math.random().toString(36).substring(2, 15)}`), this.getAttribute("anchoralignment") || this.setAttribute("anchoralignment", s), a(this.$trigger, this.$popoverElement, this.anchorAlignment, getComputedStyle(this), this.usePolyfill);
|
|
87
|
+
}
|
|
88
|
+
#e() {
|
|
89
|
+
this.isAboutToClose = !1, this.manualToggle || this.$trigger.removeEventListener("click", this.triggerPopoverDisplay), this.$popoverElement.removeEventListener("beforetoggle", this.#t), this.$popoverElement.removeEventListener("toggle", this.#n);
|
|
90
|
+
}
|
|
91
|
+
#t;
|
|
92
|
+
#n;
|
|
93
|
+
#r() {
|
|
94
|
+
this.$trigger && !["button", "input"].includes(this.$trigger.localName) && (this.manualToggle || this.$trigger.addEventListener("click", this.triggerPopoverDisplay), this.$popoverElement.addEventListener("beforetoggle", this.#t), this.$popoverElement.addEventListener("toggle", this.#n));
|
|
95
|
+
}
|
|
96
|
+
attributeChangedCallback(e, t, n) {
|
|
97
|
+
if (t !== n) switch (e) {
|
|
98
|
+
case "id":
|
|
99
|
+
this.initPopover();
|
|
100
|
+
break;
|
|
101
|
+
case "use-polyfill":
|
|
102
|
+
a(this.$trigger, this.$popoverElement, this.anchorAlignment, getComputedStyle(this), this.usePolyfill);
|
|
103
|
+
break;
|
|
104
|
+
case "manual-toggle":
|
|
105
|
+
n != null && this.$trigger?.removeAttribute("aria-expanded");
|
|
106
|
+
break;
|
|
107
|
+
case "popover-height":
|
|
108
|
+
this.updatePopoverHeight(n);
|
|
109
|
+
break;
|
|
110
|
+
default: super.attributeChangedCallback(e, t, n);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
updatePopoverHeight(e) {
|
|
114
|
+
e ? this.$popoverElement.style.setProperty("--px-popover-max-height", e) : this.$popoverElement.style.removeProperty("--px-popover-max-height");
|
|
115
|
+
}
|
|
116
|
+
initPopover() {
|
|
117
|
+
if (this.$trigger) {
|
|
118
|
+
this.$trigger.setAttribute("popovertarget", this.popoverId);
|
|
119
|
+
let e = this.getAttribute("id");
|
|
120
|
+
e && this.$trigger.setAttribute("aria-controls", e), 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, this.#e(), this.#r();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
get popoverId() {
|
|
124
|
+
return `${this.getAttribute("id")}-popover`;
|
|
125
|
+
}
|
|
126
|
+
get anchorName() {
|
|
127
|
+
return `--${this.getAttribute("id")}-anchor`;
|
|
128
|
+
}
|
|
129
|
+
get $style() {
|
|
130
|
+
return this.shadowRoot.querySelector("style");
|
|
131
|
+
}
|
|
132
|
+
get $trigger() {
|
|
133
|
+
return this.querySelector("[slot=\"trigger\"]");
|
|
134
|
+
}
|
|
135
|
+
get $popoverElement() {
|
|
136
|
+
return this.querySelector("[slot=\"popover\"]");
|
|
137
|
+
}
|
|
138
|
+
get anchorAlignment() {
|
|
139
|
+
return this.getAttribute("anchoralignment") || s;
|
|
140
|
+
}
|
|
141
|
+
set anchorAlignment(e) {
|
|
142
|
+
i.includes(e) ? this.setAttribute("anchoralignment", e) : (t(`Invalid anchor alignment value: ${e}. Using default ${s}.`), this.setAttribute("anchoralignment", s));
|
|
143
|
+
}
|
|
144
|
+
get usePolyfill() {
|
|
145
|
+
return this.hasAttribute("use-polyfill");
|
|
146
|
+
}
|
|
147
|
+
set usePolyfill(e) {
|
|
148
|
+
e ? this.setAttribute("use-polyfill", "") : this.removeAttribute("use-polyfill");
|
|
149
|
+
}
|
|
150
|
+
get manualToggle() {
|
|
151
|
+
return this.hasAttribute("manual-toggle");
|
|
152
|
+
}
|
|
153
|
+
set manualToggle(e) {
|
|
154
|
+
e ? this.setAttribute("manual-toggle", "") : this.removeAttribute("manual-toggle");
|
|
155
|
+
}
|
|
156
|
+
get popoverHeight() {
|
|
157
|
+
return this.getAttribute("popover-height");
|
|
158
|
+
}
|
|
159
|
+
set popoverHeight(e) {
|
|
160
|
+
n(this, "popover-height", e);
|
|
161
|
+
}
|
|
207
162
|
};
|
|
163
|
+
customElements.get("px-dropdown") || customElements.define("px-dropdown", c);
|
|
164
|
+
//#endregion
|
|
165
|
+
export { c as Dropdown };
|