@proximus/lavender-dropdown 1.0.0-alpha.9 → 1.0.0

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.
@@ -0,0 +1,25 @@
1
+ import { WithExtraAttributes } from '@proximus/lavender-common';
2
+ import { type AnchorAlignment } from './common.ts';
3
+ export declare class Dropdown extends WithExtraAttributes {
4
+ #private;
5
+ private template;
6
+ /**
7
+ * Instance level styling for the dropdown component.
8
+ * This is used to set the anchor name and position of the popover.
9
+ * @private
10
+ */
11
+ private get css();
12
+ static get observedAttributes(): string[];
13
+ constructor();
14
+ connectedCallback(): void;
15
+ private isAboutToClose;
16
+ attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
17
+ private initPopover;
18
+ private get popoverId();
19
+ private get anchorName();
20
+ private get $style();
21
+ get $trigger(): HTMLElement;
22
+ get $popoverElement(): HTMLElement;
23
+ get anchorAlignment(): AnchorAlignment;
24
+ set anchorAlignment(value: AnchorAlignment);
25
+ }
@@ -0,0 +1,2 @@
1
+ import { AnchorAlignment } from './common';
2
+ export declare function anchorPolyfill($trigger: HTMLElement, $popoverElement: HTMLElement, anchorAlignment: AnchorAlignment, computedStyle: CSSStyleDeclaration): void;
@@ -0,0 +1,2 @@
1
+ export declare const anchorAlignmentValues: readonly ["top-left", "top-right", "bottom-left", "bottom-right"];
2
+ export type AnchorAlignment = (typeof anchorAlignmentValues)[number];
@@ -0,0 +1 @@
1
+ export * from './Dropdown.ts';
package/dist/index.es.js CHANGED
@@ -1,30 +1,49 @@
1
- import { WithExtraAttributes as c } from "@proximus/lavender-common";
2
- const m = ':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}}', u = [
1
+ var $ = (o) => {
2
+ throw TypeError(o);
3
+ };
4
+ var u = (o, t, e) => t.has(o) || $("Cannot " + e);
5
+ var s = (o, t, e) => (u(o, t, "read from private field"), e ? e.call(o) : t.get(o)), c = (o, t, e) => t.has(o) ? $("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(o) : t.set(o, e), d = (o, t, e, r) => (u(o, t, "write to private field"), r ? r.call(o, e) : t.set(o, e), e), b = (o, t, e) => (u(o, t, "access private method"), e);
6
+ import { WithExtraAttributes as N } from "@proximus/lavender-common";
7
+ const k = ':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}}', C = [
3
8
  "top-left",
4
9
  "top-right",
5
10
  "bottom-left",
6
11
  "bottom-right"
7
12
  ];
8
- function b(a, t, e = "bottom-left", r) {
13
+ function S(o, t, e = "bottom-left", r) {
9
14
  "anchorName" in document.documentElement.style || t.addEventListener("toggle", () => {
10
- var l, h;
11
- if (!a || !t)
15
+ var f, v;
16
+ if (!o || !t)
12
17
  return;
13
- const o = a.getBoundingClientRect(), g = ((l = window.visualViewport) == null ? void 0 : l.height) ?? window.innerHeight, i = ((h = window.visualViewport) == null ? void 0 : h.width) ?? window.innerWidth, s = r.getPropertyValue("--px-padding-s-mobile") || "16px", d = parseInt(
18
+ const i = o.getBoundingClientRect(), A = ((f = window.visualViewport) == null ? void 0 : f.height) ?? window.innerHeight, n = ((v = window.visualViewport) == null ? void 0 : v.width) ?? window.innerWidth, g = r.getPropertyValue("--px-padding-s-mobile") || "16px", E = parseInt(
14
19
  (r.getPropertyValue("--px-icon-size-xs-desktop") || "24").replace("px", "")
15
20
  );
16
- ["top-left", "top-right"].includes(e) ? (t.style.bottom = `calc( ${s} + ${g - o.top - window.scrollY}px)`, t.style.top = "auto", e === "top-left" ? t.style.left = i < 768 ? `${s}px` : `${o.left}px` : t.style.right = i < 768 ? `${s}px` : `${i - o.right}px`) : (t.style.top = `${o.bottom + window.scrollY}px`, e === "bottom-left" ? t.style.left = i < 768 ? `${s}px` : `${o.left}px` : t.style.right = i < 768 ? `${s}px` : `${i - o.right - d}px`);
21
+ ["top-left", "top-right"].includes(e) ? (t.style.bottom = `calc( ${g} + ${A - i.top - window.scrollY}px)`, t.style.top = "auto", e === "top-left" ? t.style.left = n < 768 ? `${g}px` : `${i.left}px` : t.style.right = n < 768 ? `${g}px` : `${n - i.right}px`) : (t.style.top = `${i.bottom + window.scrollY}px`, e === "bottom-left" ? t.style.left = n < 768 ? `${g}px` : `${i.left}px` : t.style.right = n < 768 ? `${g}px` : `${n - i.right - E}px`);
17
22
  });
18
23
  }
19
- const p = new CSSStyleSheet();
20
- p.replaceSync(m);
21
- const n = "bottom-left";
22
- class f extends c {
24
+ const x = new CSSStyleSheet();
25
+ x.replaceSync(k);
26
+ const m = "bottom-left";
27
+ var p, w, a, h, l, y;
28
+ class T extends N {
23
29
  constructor() {
24
- super(p), this.template = () => `
30
+ super(x);
31
+ c(this, p);
32
+ c(this, a);
33
+ c(this, h);
34
+ c(this, l);
35
+ this.template = () => `
25
36
  <style>${this.css}</style>
26
37
  <slot name="trigger"></slot>
27
- <slot name="popover"></slot>`, this.isAboutToClose = !1, this.shadowRoot.innerHTML = this.template();
38
+ <slot name="popover"></slot>`, this.isAboutToClose = !1, d(this, a, () => {
39
+ this.isAboutToClose || (this.$popoverElement.togglePopover({ source: this.$trigger }), this.$trigger.ariaExpanded = "true");
40
+ }), d(this, h, () => {
41
+ this.$popoverElement.matches(":popover-open") && (this.isAboutToClose = !0, this.$trigger.ariaExpanded = "false");
42
+ }), d(this, l, () => {
43
+ this.$popoverElement.matches(":popover-open") || setTimeout(() => {
44
+ this.isAboutToClose = !1;
45
+ });
46
+ }), this.shadowRoot.innerHTML = this.template();
28
47
  }
29
48
  /**
30
49
  * Instance level styling for the dropdown component.
@@ -71,43 +90,25 @@ class f extends c {
71
90
  this.getAttribute("id") || this.setAttribute(
72
91
  "id",
73
92
  `px-dropdown-${Math.random().toString(36).substring(2, 15)}`
74
- ), this.getAttribute("anchoralignment") || this.setAttribute("anchoralignment", n), b(
93
+ ), this.getAttribute("anchoralignment") || this.setAttribute("anchoralignment", m), S(
75
94
  this.$trigger,
76
95
  this.$popoverElement,
77
96
  this.anchorAlignment,
78
97
  getComputedStyle(this)
79
98
  );
80
99
  }
81
- /**
82
- * Handles the manual display of the popover when the trigger is clicked.
83
- * This is necessary for cases where the trigger is not a button or input element.
84
- * This method adds event listeners to the trigger element to toggle the popover.
85
- * It also manages the state of whether the popover is about to close or not to avoid
86
- * race conditions when the popover is toggled and the trigger click event is fired.
87
- */
88
- handleManualPopoverDisplay() {
89
- this.$trigger && !["button", "input"].includes(this.$trigger.localName) && (this.$trigger.addEventListener("click", () => {
90
- this.isAboutToClose || (this.$popoverElement.togglePopover({ source: this.$trigger }), this.$trigger.ariaExpanded = "true");
91
- }), this.$popoverElement.addEventListener("beforetoggle", () => {
92
- this.$popoverElement.matches(":popover-open") && (this.isAboutToClose = !0, this.$trigger.ariaExpanded = "false");
93
- }), this.$popoverElement.addEventListener("toggle", () => {
94
- this.$popoverElement.matches(":popover-open") || setTimeout(() => {
95
- this.isAboutToClose = !1;
96
- });
97
- }));
98
- }
99
- attributeChangedCallback(t, e, r) {
100
- switch (t) {
100
+ attributeChangedCallback(e, r, i) {
101
+ switch (e) {
101
102
  case "id":
102
- e !== r && this.initPopover();
103
+ r !== i && this.initPopover();
103
104
  break;
104
105
  default:
105
- super.attributeChangedCallback(t, e, r);
106
+ super.attributeChangedCallback(e, r, i);
106
107
  break;
107
108
  }
108
109
  }
109
110
  initPopover() {
110
- 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, this.handleManualPopoverDisplay());
111
+ 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, b(this, p, w).call(this), b(this, p, y).call(this));
111
112
  }
112
113
  get popoverId() {
113
114
  return `${this.getAttribute("id")}-popover`;
@@ -125,15 +126,30 @@ class f extends c {
125
126
  return this.querySelector('[slot="popover"]');
126
127
  }
127
128
  get anchorAlignment() {
128
- return this.getAttribute("anchoralignment") || n;
129
+ return this.getAttribute("anchoralignment") || m;
129
130
  }
130
- set anchorAlignment(t) {
131
- u.includes(t) ? this.setAttribute("anchoralignment", t) : (console.warn(
132
- `Invalid anchor alignment value: ${t}. Using default ${n}.`
133
- ), this.setAttribute("anchoralignment", n));
131
+ set anchorAlignment(e) {
132
+ C.includes(e) ? this.setAttribute("anchoralignment", e) : (console.warn(
133
+ `Invalid anchor alignment value: ${e}. Using default ${m}.`
134
+ ), this.setAttribute("anchoralignment", m));
134
135
  }
135
136
  }
136
- customElements.get("px-dropdown") || customElements.define("px-dropdown", f);
137
+ p = new WeakSet(), w = function() {
138
+ this.isAboutToClose = !1, this.$trigger.removeEventListener("click", s(this, a)), this.$popoverElement.removeEventListener(
139
+ "beforetoggle",
140
+ s(this, h)
141
+ ), this.$popoverElement.removeEventListener("toggle", s(this, l));
142
+ }, a = new WeakMap(), h = new WeakMap(), l = new WeakMap(), /**
143
+ * Handles the manual display of the popover when the trigger is clicked.
144
+ * This is necessary for cases where the trigger is not a button or input element.
145
+ * This method adds event listeners to the trigger element to toggle the popover.
146
+ * It also manages the state of whether the popover is about to close or not to avoid
147
+ * race conditions when the popover is toggled and the trigger click event is fired.
148
+ */
149
+ y = function() {
150
+ this.$trigger && !["button", "input"].includes(this.$trigger.localName) && (this.$trigger.addEventListener("click", s(this, a)), this.$popoverElement.addEventListener("beforetoggle", s(this, h)), this.$popoverElement.addEventListener("toggle", s(this, l)));
151
+ };
152
+ customElements.get("px-dropdown") || customElements.define("px-dropdown", T);
137
153
  export {
138
- f as Dropdown
154
+ T as Dropdown
139
155
  };
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@proximus/lavender-dropdown",
3
- "version": "1.0.0-alpha.9",
3
+ "version": "1.0.0",
4
4
  "description": "",
5
5
  "main": "dist/index.es.js",
6
+ "types": "dist/index.d.ts",
6
7
  "files": [
7
8
  "dist"
8
9
  ],
@@ -10,10 +11,13 @@
10
11
  "scripts": {
11
12
  "transform-package-json": "node ../../../scripts/tranformPackageJson.js package.json dist/far/away",
12
13
  "clean": "rm -rf dist",
13
- "build": "npm run clean && tsc && NODE_ENV=development vite build && npm run transform-package-json",
14
- "test": "vitest run --coverage"
14
+ "build": "npm run clean && NODE_ENV=development vite build && tsc && npm run transform-package-json && npm run wc-manifest",
15
+ "test": "vitest run --coverage",
16
+ "wc-manifest": "cem analyze --globs \"src/*\" --config ../custom-elements-manifest.config.js --outdir dist"
15
17
  },
16
18
  "publishConfig": {
17
19
  "access": "public"
18
- }
20
+ },
21
+ "customElements": "dist/custom-elements.json",
22
+ "web-types": "./dist/web-types.json"
19
23
  }