@proximus/lavender-dropdown 2.0.0-alpha.97 → 2.0.0-alpha.98

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