@proximus/lavender-dropdown 2.0.0-alpha.13 → 2.0.0-alpha.130

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.
@@ -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;
34
+ set popoverHeight(value: string);
27
35
  }
package/dist/index.es.js CHANGED
@@ -1,45 +1,48 @@
1
- var x = (o) => {
1
+ var $ = (o) => {
2
2
  throw TypeError(o);
3
3
  };
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 = [
4
+ var m = (o, e, t) => e.has(o) || $("Cannot " + t);
5
+ var g = (o, e, t) => (m(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), u = (o, e, t, r) => (m(o, e, "write to private field"), r ? r.call(o, t) : e.set(o, t), t), v = (o, e, t) => (m(o, e, "access private method"), t);
6
+ import { WithExtraAttributes as T, log as k } from "@proximus/lavender-common";
7
+ const N = ':host{position:relative}::slotted([slot="popover"]){position:fixed;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;max-height:var(--px-popover-max-height)}: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}}', C = [
8
8
  "top-left",
9
9
  "top-right",
10
10
  "bottom-left",
11
11
  "bottom-right"
12
12
  ];
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)
13
+ function x(o, e, t = "bottom-left", r, s = !1) {
14
+ "anchorName" in document.documentElement.style && s === !1 || e.addEventListener("toggle", () => {
15
+ var b, f;
16
+ if (!o || !e)
17
17
  return;
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", "")
18
+ const i = o.getBoundingClientRect(), P = ((b = window.visualViewport) == null ? void 0 : b.height) ?? window.innerHeight, l = ((f = window.visualViewport) == null ? void 0 : f.width) ?? window.innerWidth, p = r.getPropertyValue("--px-padding-s-mobile") || "16px", E = parseInt(
19
+ (r.getPropertyValue("--px-icon-size-xs-desktop") || "24").replace("px", "")
20
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`);
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
22
  });
23
23
  }
24
- const w = new CSSStyleSheet();
25
- w.replaceSync(P);
26
- const m = "bottom-left";
27
- var p, A, l, a, h, E;
28
- class T extends C {
24
+ const y = new CSSStyleSheet();
25
+ y.replaceSync(N);
26
+ const c = "bottom-left";
27
+ var n, A, h, a, w;
28
+ class S extends T {
29
29
  constructor() {
30
- super(w);
31
- c(this, p);
32
- c(this, l);
33
- c(this, a);
34
- c(this, h);
30
+ super(y);
31
+ d(this, n);
32
+ d(this, h);
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, u(this, l, () => {
39
- this.isAboutToClose || (this.$popoverElement.togglePopover({ source: this.$trigger }), this.$trigger.ariaExpanded = "true");
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"));
40
45
  }), u(this, a, () => {
41
- this.$popoverElement.matches(":popover-open") && (this.isAboutToClose = !0, this.$trigger.ariaExpanded = "false");
42
- }), u(this, h, () => {
43
46
  this.$popoverElement.matches(":popover-open") || setTimeout(() => {
44
47
  this.isAboutToClose = !1;
45
48
  });
@@ -55,7 +58,7 @@ class T extends C {
55
58
  anchor-name: ${this.anchorName};
56
59
  }
57
60
  :host([anchoralignment="bottom-left"]) {
58
- ::slotted([slot="popover"]) {
61
+ ::slotted([popover]) {
59
62
  position-anchor: ${this.anchorName};
60
63
  top: anchor(${this.anchorName} bottom);
61
64
  left: anchor(${this.anchorName} left);
@@ -88,14 +91,16 @@ class T extends C {
88
91
  ...super.observedAttributes,
89
92
  "id",
90
93
  "anchoralignment",
91
- "use-polyfill"
94
+ "use-polyfill",
95
+ "manual-toggle",
96
+ "popover-height"
92
97
  ];
93
98
  }
94
99
  connectedCallback() {
95
100
  this.getAttribute("id") || this.setAttribute(
96
101
  "id",
97
102
  `px-dropdown-${Math.random().toString(36).substring(2, 15)}`
98
- ), this.getAttribute("anchoralignment") || this.setAttribute("anchoralignment", m), y(
103
+ ), this.getAttribute("anchoralignment") || this.setAttribute("anchoralignment", c), x(
99
104
  this.$trigger,
100
105
  this.$popoverElement,
101
106
  this.anchorAlignment,
@@ -103,14 +108,15 @@ class T extends C {
103
108
  this.usePolyfill
104
109
  );
105
110
  }
106
- attributeChangedCallback(e, i, d) {
107
- if (i !== d)
108
- switch (e) {
111
+ attributeChangedCallback(t, r, s) {
112
+ var i;
113
+ if (r !== s)
114
+ switch (t) {
109
115
  case "id":
110
116
  this.initPopover();
111
117
  break;
112
118
  case "use-polyfill":
113
- y(
119
+ x(
114
120
  this.$trigger,
115
121
  this.$popoverElement,
116
122
  this.anchorAlignment,
@@ -118,13 +124,25 @@ class T extends C {
118
124
  this.usePolyfill
119
125
  );
120
126
  break;
127
+ case "manual-toggle":
128
+ s != null && ((i = this.$trigger) == null || i.removeAttribute("aria-expanded"));
129
+ break;
130
+ case "popover-height":
131
+ this.updatePopoverHeight(s);
132
+ break;
121
133
  default:
122
- super.attributeChangedCallback(e, i, d);
134
+ super.attributeChangedCallback(t, r, s);
123
135
  break;
124
136
  }
125
137
  }
138
+ updatePopoverHeight(t) {
139
+ t ? this.$popoverElement.style.setProperty(
140
+ "--px-popover-max-height",
141
+ t
142
+ ) : this.$popoverElement.style.removeProperty("--px-popover-max-height");
143
+ }
126
144
  initPopover() {
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));
145
+ 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, v(this, n, A).call(this), v(this, n, w).call(this));
128
146
  }
129
147
  get popoverId() {
130
148
  return `${this.getAttribute("id")}-popover`;
@@ -142,36 +160,48 @@ class T extends C {
142
160
  return this.querySelector('[slot="popover"]');
143
161
  }
144
162
  get anchorAlignment() {
145
- return this.getAttribute("anchoralignment") || m;
163
+ return this.getAttribute("anchoralignment") || c;
146
164
  }
147
- set anchorAlignment(e) {
148
- S.includes(e) ? this.setAttribute("anchoralignment", e) : (console.warn(
149
- `Invalid anchor alignment value: ${e}. Using default ${m}.`
150
- ), this.setAttribute("anchoralignment", m));
165
+ set anchorAlignment(t) {
166
+ C.includes(t) ? this.setAttribute("anchoralignment", t) : (k(
167
+ `Invalid anchor alignment value: ${t}. Using default ${c}.`
168
+ ), this.setAttribute("anchoralignment", c));
151
169
  }
152
170
  get usePolyfill() {
153
171
  return this.hasAttribute("use-polyfill");
154
172
  }
155
- set usePolyfill(e) {
156
- e ? this.setAttribute("use-polyfill", "") : this.removeAttribute("use-polyfill");
173
+ set usePolyfill(t) {
174
+ t ? this.setAttribute("use-polyfill", "") : this.removeAttribute("use-polyfill");
175
+ }
176
+ get manualToggle() {
177
+ return this.hasAttribute("manual-toggle");
178
+ }
179
+ set manualToggle(t) {
180
+ t ? this.setAttribute("manual-toggle", "") : this.removeAttribute("manual-toggle");
181
+ }
182
+ get popoverHeight() {
183
+ return this.getAttribute("popover-height");
184
+ }
185
+ set popoverHeight(t) {
186
+ t ? this.setAttribute("popover-height", t) : this.removeAttribute("popover-height");
157
187
  }
158
188
  }
159
- p = new WeakSet(), A = function() {
160
- this.isAboutToClose = !1, this.$trigger.removeEventListener("click", s(this, l)), this.$popoverElement.removeEventListener(
189
+ n = new WeakSet(), A = function() {
190
+ this.isAboutToClose = !1, this.manualToggle || this.$trigger.removeEventListener("click", this.triggerPopoverDisplay), this.$popoverElement.removeEventListener(
161
191
  "beforetoggle",
162
- s(this, a)
163
- ), this.$popoverElement.removeEventListener("toggle", s(this, h));
164
- }, l = new WeakMap(), a = new WeakMap(), h = new WeakMap(), /**
192
+ g(this, h)
193
+ ), this.$popoverElement.removeEventListener("toggle", g(this, a));
194
+ }, h = new WeakMap(), a = new WeakMap(), /**
165
195
  * Handles the manual display of the popover when the trigger is clicked.
166
196
  * This is necessary for cases where the trigger is not a button or input element.
167
197
  * This method adds event listeners to the trigger element to toggle the popover.
168
198
  * It also manages the state of whether the popover is about to close or not to avoid
169
199
  * race conditions when the popover is toggled and the trigger click event is fired.
170
200
  */
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)));
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)));
173
203
  };
174
- customElements.get("px-dropdown") || customElements.define("px-dropdown", T);
204
+ customElements.get("px-dropdown") || customElements.define("px-dropdown", S);
175
205
  export {
176
- T as Dropdown
206
+ S as Dropdown
177
207
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proximus/lavender-dropdown",
3
- "version": "2.0.0-alpha.13",
3
+ "version": "2.0.0-alpha.130",
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 ../custom-elements-manifest.config.js --outdir dist"
16
+ "wc-manifest": "cem analyze --globs \"src/*\" --config ../../custom-elements-manifest.config.js --outdir dist"
17
17
  },
18
18
  "publishConfig": {
19
19
  "access": "public"