@proximus/lavender-dropdown 2.0.0-alpha.18 → 2.0.0-alpha.180
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 +8 -0
- package/dist/anchorPolyfill.d.ts +1 -1
- package/dist/index.es.js +133 -145
- package/package.json +2 -2
package/dist/Dropdown.d.ts
CHANGED
|
@@ -13,7 +13,11 @@ 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;
|
|
20
|
+
updatePopoverHeight(newValue?: string): void;
|
|
17
21
|
private initPopover;
|
|
18
22
|
private get popoverId();
|
|
19
23
|
private get anchorName();
|
|
@@ -24,4 +28,8 @@ export declare class Dropdown extends WithExtraAttributes {
|
|
|
24
28
|
set anchorAlignment(value: AnchorAlignment);
|
|
25
29
|
get usePolyfill(): boolean;
|
|
26
30
|
set usePolyfill(value: boolean);
|
|
31
|
+
get manualToggle(): boolean;
|
|
32
|
+
set manualToggle(value: boolean);
|
|
33
|
+
get popoverHeight(): string | null;
|
|
34
|
+
set popoverHeight(value: string | null);
|
|
27
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,61 +1,32 @@
|
|
|
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(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
|
-
});
|
|
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
|
-
c(this, l);
|
|
33
|
-
c(this, a);
|
|
34
|
-
c(this, h);
|
|
35
|
-
this.template = () => `
|
|
36
|
-
<style>${this.css}</style>
|
|
37
|
-
<slot name="trigger"></slot>
|
|
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, () => {
|
|
43
|
-
this.$popoverElement.matches(":popover-open") || setTimeout(() => {
|
|
44
|
-
this.isAboutToClose = !1;
|
|
45
|
-
});
|
|
46
|
-
}), this.shadowRoot.innerHTML = this.template();
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Instance level styling for the dropdown component.
|
|
50
|
-
* This is used to set the anchor name and position of the popover.
|
|
51
|
-
* @private
|
|
52
|
-
*/
|
|
53
|
-
get css() {
|
|
54
|
-
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']) {
|
|
55
26
|
anchor-name: ${this.anchorName};
|
|
56
27
|
}
|
|
57
28
|
:host([anchoralignment="bottom-left"]) {
|
|
58
|
-
::slotted([
|
|
29
|
+
::slotted([popover]) {
|
|
59
30
|
position-anchor: ${this.anchorName};
|
|
60
31
|
top: anchor(${this.anchorName} bottom);
|
|
61
32
|
left: anchor(${this.anchorName} left);
|
|
@@ -82,96 +53,113 @@ class L extends C {
|
|
|
82
53
|
right: anchor(${this.anchorName} right);
|
|
83
54
|
}
|
|
84
55
|
}`;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
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
|
+
}
|
|
177
162
|
};
|
|
163
|
+
customElements.get("px-dropdown") || customElements.define("px-dropdown", c);
|
|
164
|
+
//#endregion
|
|
165
|
+
export { c as Dropdown };
|
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.180",
|
|
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"
|