@proximus/lavender-tabs 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/Tab.d.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  export declare const TAB_SELECTED_EVENT = "px.lavender.tab.selected";
2
2
  export declare const TAB_CONNECTED_EVENT = "px-tab-connected";
3
+ export type TabSelectedDetail = {
4
+ tabId: string;
5
+ targetId: string;
6
+ };
3
7
  export declare class Tab extends HTMLElement {
4
8
  internals: ElementInternals;
5
9
  template: () => string;
@@ -11,9 +15,7 @@ export declare class Tab extends HTMLElement {
11
15
  get selected(): boolean;
12
16
  set selected(value: boolean);
13
17
  get inverted(): boolean;
14
- set id(value: string);
15
- get id(): string;
16
- set target(value: string);
17
- get target(): string;
18
+ set target(value: string | null);
19
+ get target(): string | null;
18
20
  handleSelected(value: string): void;
19
21
  }
@@ -4,8 +4,8 @@ export declare class TabPanel extends HTMLElement {
4
4
  constructor();
5
5
  attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
6
6
  connectedCallback(): void;
7
- get panelId(): string;
8
- set panelId(value: string);
7
+ get panelId(): string | null;
8
+ set panelId(value: string | null);
9
9
  set selected(value: boolean);
10
10
  get selected(): boolean;
11
11
  get $panel(): HTMLElement;
package/dist/Tabs.d.ts CHANGED
@@ -1,9 +1,12 @@
1
1
  import '@proximus/lavender-button-icon';
2
2
  import { type Tab } from './Tab.ts';
3
3
  import { type TabPanel } from './TabPanel.ts';
4
+ import type { TabsEventMap } from './events.ts';
4
5
  export declare class Tabs extends HTMLElement {
5
6
  #private;
6
7
  internals: ElementInternals;
8
+ /** Narrows listener types for the Tabs specific custom events. */
9
+ addEventListener: <K extends keyof TabsEventMap>(type: K, listener: (ev: TabsEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions) => void;
7
10
  template: () => string;
8
11
  static get observedAttributes(): string[];
9
12
  constructor();
@@ -27,8 +30,8 @@ export declare class Tabs extends HTMLElement {
27
30
  set hideControls(value: boolean);
28
31
  get inverted(): boolean;
29
32
  set inverted(value: boolean);
30
- get nextAriaLabel(): string;
31
- set nextAriaLabel(value: string);
32
- get previousAriaLabel(): string;
33
- set previousAriaLabel(value: string);
33
+ get nextAriaLabel(): string | null;
34
+ set nextAriaLabel(value: string | null);
35
+ get previousAriaLabel(): string | null;
36
+ set previousAriaLabel(value: string | null);
34
37
  }
@@ -0,0 +1,11 @@
1
+ import { TAB_CONNECTED_EVENT, TAB_SELECTED_EVENT, type TabSelectedDetail } from './Tab.ts';
2
+ export type { TabSelectedDetail };
3
+ /**
4
+ * Custom events handled by the Tabs, on top of the standard DOM events.
5
+ * Declared locally (instead of augmenting the global `HTMLElementEventMap`)
6
+ * so these event names are only typed on the elements that actually use them.
7
+ */
8
+ export interface TabsEventMap extends HTMLElementEventMap {
9
+ [TAB_SELECTED_EVENT]: CustomEvent<TabSelectedDetail>;
10
+ [TAB_CONNECTED_EVENT]: CustomEvent;
11
+ }
package/dist/index.es.js CHANGED
@@ -1,300 +1,247 @@
1
- var f = (r) => {
2
- throw TypeError(r);
3
- };
4
- var S = (r, e, t) => e.has(r) || f("Cannot " + t);
5
- var x = (r, e, t) => e.has(r) ? f("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(r) : e.set(r, t);
6
- var n = (r, e, t) => (S(r, e, "access private method"), t);
7
1
  import "@proximus/lavender-button-icon";
8
- const k = "*{font-family:var(--px-font-family)}:host{background-color:var(--px-color-background-container-default-default)}:host(:first-child),:host(:first-child) .tab-btn{border-radius:var(--px-radius-main) var(--px-radius-none) var(--px-radius-none) var(--px-radius-main)}:host(:last-of-type),:host(:last-of-type) .tab-btn{border-radius:var(--px-radius-none) var(--px-radius-main) var(--px-radius-main) var(--px-radius-none)}:host([selected]){background-color:var(--px-color-background-state-active-default);border-radius:var(--px-radius-main)!important}:host([selected])>.tab-btn{cursor:auto;padding-block:var(--px-padding-m-mobile);color:var(--px-color-text-neutral-inverted)}.tab-btn{background:none;border:none;margin:0;padding:var(--px-padding-s-mobile);cursor:pointer;height:inherit;width:inherit;font-size:var(--px-text-size-label-l-mobile);font-weight:var(--px-font-weight-title);text-wrap:nowrap;color:var(--px-color-text-neutral-default);outline:none}:host(:focus-visible){outline-offset:var(--px-focus-offset-mobile);outline:var(--px-focus-outline-mobile) solid var(--px-color-border-focus-outline-default)}:host(:not([selected])) .tab-btn:hover{background-color:var(--px-color-background-state-hover-default)}:host([inverted]) .tab-btn{color:var(--px-color-text-neutral-inverted)}:host([inverted]:not([selected])) .tab-btn:hover{background-color:var(--px-color-background-state-hover-inverted)}:host([inverted][selected]) .tab-btn{color:var(--px-color-text-brand-default)}:host([inverted]:focus-visible){outline-color:var(--px-color-border-focus-outline-inverted)}@media screen and (min-width: 48rem){.tab-btn{padding:var(--px-padding-s-desktop);font-size:var(--px-text-size-label-l-desktop)}:host[selected]>.tab-btn{padding-block:var(--px-padding-m-desktop)}}@media screen and (min-width: 64.0625rem){.tab-btn{padding:var(--px-padding-s-desktop);font-size:var(--px-text-size-label-l-desktop)}:host[selected]>.tab-btn{padding-block:var(--px-padding-m-desktop)}}", g = new CSSStyleSheet();
9
- g.replaceSync(k);
10
- const m = "px.lavender.tab.selected", A = "px-tab-connected";
11
- class L extends HTMLElement {
12
- constructor() {
13
- var e;
14
- super(), this.template = () => `
15
- <div class="tab-btn"><slot></slot></div>
16
- `, this.attachShadow({ mode: "open" }), this.shadowRoot.innerHTML = this.template(), this.shadowRoot.adoptedStyleSheets = [g], this.internals = (e = this.attachInternals) == null ? void 0 : e.call(this);
17
- }
18
- static get observedAttributes() {
19
- return ["selected", "target", "id", "inverted"];
20
- }
21
- connectedCallback() {
22
- this.role = "tab", this.internals && (this.internals.role = "tab"), this.ariaSelected = `${this.selected}`, this.slot = "tabs", this.dispatchEvent(
23
- new CustomEvent(A, { bubbles: !0, composed: !0 })
24
- ), this.addEventListener("click", () => {
25
- this.selected = !0;
26
- });
27
- }
28
- attributeChangedCallback(e, t, s) {
29
- e === "selected" ? this.handleSelected(s) : e === "id" ? this.$tabBtn.setAttribute("id", s) : e === "target" ? this.setAttribute("aria-controls", s) : e === "inverted" && (s === "" ? this.$tabBtn.setAttribute("inverted", "") : this.$tabBtn.removeAttribute("inverted"));
30
- }
31
- get $tabBtn() {
32
- return this.shadowRoot.querySelector(".tab-btn");
33
- }
34
- get selected() {
35
- return this.hasAttribute("selected");
36
- }
37
- set selected(e) {
38
- e ? this.setAttribute("selected", "") : this.removeAttribute("selected");
39
- }
40
- get inverted() {
41
- return this.hasAttribute("inverted");
42
- }
43
- set id(e) {
44
- this.setAttribute("id", e);
45
- }
46
- get id() {
47
- return this.getAttribute("id");
48
- }
49
- set target(e) {
50
- this.setAttribute("target", e);
51
- }
52
- get target() {
53
- return this.getAttribute("target");
54
- }
55
- handleSelected(e) {
56
- e !== "" ? (this.tabIndex = -1, this.internals && (this.internals.ariaSelected = "false"), this.ariaSelected = "false") : (setTimeout(() => {
57
- this.dispatchEvent(
58
- new CustomEvent(m, {
59
- bubbles: !0,
60
- composed: !0,
61
- detail: {
62
- tabId: this.id,
63
- targetId: this.target
64
- }
65
- })
66
- );
67
- }), this.focus(), this.tabIndex = 0, this.internals && (this.internals.ariaSelected = "true"), this.ariaSelected = "true");
68
- }
69
- }
70
- const T = '*{font-family:var(--px-font-family)}#container{display:flex;flex-direction:column;align-items:flex-start;gap:var(--px-spacing-default-mobile)}#tab-container{position:relative;width:100%}#tab-container>#previous{position:absolute;top:12px;left:-24px}#tab-container>#next{position:absolute;top:12px;right:-24px}#panels{width:100%}#tablist{display:flex;align-items:center;scrollbar-width:none;overflow:scroll;width:100%;box-sizing:border-box;margin:calc(calc(var(--px-focus-outline-mobile) + var(--px-focus-offset-mobile)) * -1);padding:calc(var(--px-focus-outline-mobile) + var(--px-focus-offset-mobile))}#tablist::-webkit-scrollbar{display:none}:host([inverted]) #tablist ::slotted(px-tab){background-color:var(--px-color-background-container-default-inverted)}:host([inverted]) #tablist ::slotted(px-tab[selected=""]){background-color:var(--px-color-background-state-active-inverted)}:host([inverted]) #tablist ::slotted(px-tab[selected=""])>button{color:var(--px-color-text-brand-default)}:host([inverted]) button[role=tab]{color:var(--px-color-text-neutral-inverted)}:host([inverted]) button[aria-selected=""]{color:var(--px-color-text-brand-default)}@media screen and (min-width: 48rem){#container{gap:var(--px-spacing-default-desktop)}#tablist{margin:calc(calc(var(--px-focus-outline-tablet) + var(--px-focus-offset-tablet)) * -1);padding:calc(var(--px-focus-outline-tablet) + var(--px-focus-offset-tablet))}}@media screen and (min-width: 64.0625rem){#container{gap:var(--px-spacing-default-desktop)}#tablist{margin:calc(calc(var(--px-focus-outline-desktop) + var(--px-focus-offset-desktop)) * -1);padding:calc(var(--px-focus-outline-desktop) + var(--px-focus-offset-desktop))}}', b = new CSSStyleSheet();
71
- b.replaceSync(T);
72
- var o, d, $;
73
- class E extends HTMLElement {
74
- constructor() {
75
- var t;
76
- super();
77
- x(this, o);
78
- this.template = () => `
79
- <div id="container">
80
- <div id="tab-container">
81
- <px-button-icon id="previous" hidden--mobile hidden--tablet>
82
- <px-icon name="chevron_left" from="lavender"></px-icon>
83
- </px-button-icon>
84
- <div id="tablist">
85
- <slot name="tabs"></slot>
86
- </div>
87
- <px-button-icon id="next" hidden--mobile hidden--tablet>
88
- <px-icon name="chevron_right" from="lavender"></px-icon>
89
- </px-button-icon>
90
- </div>
91
- <div id="panels">
92
- <slot name="tabpanels"></slot>
93
- </div>
94
- </div>
95
- `, this.handleNextPreviousDisplay = () => {
96
- this.$prefixButton && this.$suffixButton && (this.$prefixButton.style.display = this.shouldDisplayScrollLeftButton() ? "" : "none", this.$suffixButton.style.display = this.shouldDisplayScrollRightButton() ? "" : "none");
97
- }, this.attachShadow({ mode: "open" }), this.shadowRoot.innerHTML = this.template(), this.shadowRoot.adoptedStyleSheets = [b], this.internals = (t = this.attachInternals) == null ? void 0 : t.call(this);
98
- }
99
- static get observedAttributes() {
100
- return [
101
- "inverted",
102
- "next-aria-label",
103
- "previous-aria-label",
104
- "hide-controls"
105
- ];
106
- }
107
- attributeChangedCallback(t, s, i) {
108
- switch (t) {
109
- case "next-aria-label":
110
- this.hasAttribute("hide-controls") || this.$suffixButton.setAttribute("aria-label", i);
111
- break;
112
- case "previous-aria-label":
113
- this.hasAttribute("hide-controls") || this.$prefixButton.setAttribute("aria-label", i);
114
- break;
115
- case "hide-controls":
116
- n(this, o, $).call(this, i);
117
- break;
118
- case "inverted":
119
- n(this, o, d).call(this, i);
120
- break;
121
- }
122
- }
123
- connectedCallback() {
124
- var t, s;
125
- this.$tabList.role = "tablist", this.addEventListener(
126
- m,
127
- (i) => {
128
- [...this.$tabPanels].forEach((a) => {
129
- a.getAttribute("panel-id") !== i.detail.targetId && a.hasAttribute("selected") && (a.removeAttribute("selected"), a.removeAttribute("aria-labelledby")), a.getAttribute("panel-id") === i.detail.targetId && (a.setAttribute("selected", ""), a.setAttribute("aria-labelledby", i.detail.tabId));
130
- }), [...this.$tabs].forEach((a) => {
131
- a.getAttribute("id") !== i.detail.tabId && a.hasAttribute("selected") && a.removeAttribute("selected");
132
- });
133
- }
134
- ), this.addEventListener(A, () => {
135
- this.handleNextPreviousDisplay(), this.inverted && n(this, o, d).call(this, this.getAttribute("inverted"));
136
- }), this.handleNextPreviousDisplay(), n(this, o, d).call(this, this.getAttribute("inverted")), this.addEventListener("keydown", (i) => {
137
- var a, l;
138
- (i.key === "ArrowRight" || i.key === "ArrowLeft") && ((l = (a = document.activeElement) == null ? void 0 : a.localName) != null && l.endsWith("-tab")) && this.navigateToTab(i.key === "ArrowRight" ? "right" : "left");
139
- }), (t = this.$prefixButton) == null || t.addEventListener("click", (i) => {
140
- i.stopPropagation(), this.$tabList.scrollTo({
141
- left: this.$tabList.scrollLeft - 100,
142
- behavior: "smooth"
143
- });
144
- }), (s = this.$suffixButton) == null || s.addEventListener("click", (i) => {
145
- i.stopPropagation(), this.$tabList.scrollTo({
146
- left: this.$tabList.scrollLeft + 100,
147
- behavior: "smooth"
148
- });
149
- }), window.addEventListener("resize", this.handleNextPreviousDisplay), this.$tabList.addEventListener("scroll", this.handleNextPreviousDisplay);
150
- }
151
- disconnectedCallback() {
152
- window.addEventListener("resize", this.handleNextPreviousDisplay);
153
- }
154
- navigateToTab(t) {
155
- const s = this.$nextTab, i = this.$previousTab;
156
- this.$activePanel.selected = !1, this.$activeTab.selected = !1, t === "right" ? (s.selected = !0, s.focus()) : t === "left" && (i.selected = !0, i.focus()), this.$activePanel.selected = !0;
157
- }
158
- shouldDisplayScrollRightButton() {
159
- return this.$tabList.scrollWidth > this.$tabList.clientWidth && this.$tabList.scrollWidth - this.$tabList.scrollLeft !== this.$tabList.clientWidth;
160
- }
161
- shouldDisplayScrollLeftButton() {
162
- return this.$tabList.scrollLeft > 0;
163
- }
164
- get $activeTab() {
165
- return this.querySelector('[selected=""][slot="tabs"]');
166
- }
167
- get $nextTab() {
168
- const t = this.$activeTab.nextElementSibling;
169
- return t.slot !== "tabs" ? this.querySelector('[slot="tabs"]') : t;
170
- }
171
- get $previousTab() {
172
- const t = this.$activeTab.previousElementSibling;
173
- return t || Array.from(this.querySelectorAll('[slot="tabs"]')).pop();
174
- }
175
- get $activePanel() {
176
- var t;
177
- return this.querySelector(
178
- `[panel-id="${(t = this.$activeTab) == null ? void 0 : t.target}"]`
179
- );
180
- }
181
- get $tabList() {
182
- return this.shadowRoot.querySelector("#tablist");
183
- }
184
- get $tabs() {
185
- return this.querySelectorAll('[slot="tabs"]');
186
- }
187
- get $tabPanels() {
188
- return this.querySelectorAll('[slot="tabpanels"]');
189
- }
190
- get $prefixButton() {
191
- return this.shadowRoot.querySelector("#previous");
192
- }
193
- get $suffixButton() {
194
- return this.shadowRoot.querySelector("#next");
195
- }
196
- get hideControls() {
197
- return this.hasAttribute("hide-controls");
198
- }
199
- set hideControls(t) {
200
- t ? this.setAttribute("hide-controls", "") : this.removeAttribute("hide-controls");
201
- }
202
- get inverted() {
203
- return this.hasAttribute("inverted");
204
- }
205
- set inverted(t) {
206
- t ? this.setAttribute("inverted", "") : this.removeAttribute("inverted");
207
- }
208
- get nextAriaLabel() {
209
- return this.getAttribute("next-aria-label");
210
- }
211
- set nextAriaLabel(t) {
212
- this.setAttribute("next-aria-label", t);
213
- }
214
- get previousAriaLabel() {
215
- return this.getAttribute("previous-aria-label");
216
- }
217
- set previousAriaLabel(t) {
218
- this.setAttribute("previous-aria-label", t);
219
- }
220
- }
221
- o = new WeakSet(), d = function(t) {
222
- var s, i, a, l, h, u, p, v;
223
- t === "" ? ((s = this.$prefixButton) == null || s.setAttribute("inverted", ""), (i = this.$suffixButton) == null || i.setAttribute("inverted", ""), (a = this.$activePanel) == null || a.setAttribute("inverted", ""), (l = this.$activeTab) == null || l.setAttribute("inverted", ""), [...this.$tabs].forEach((c) => {
224
- c.setAttribute("inverted", "");
225
- })) : ((h = this.$prefixButton) == null || h.removeAttribute("inverted"), (u = this.$suffixButton) == null || u.removeAttribute("inverted"), (p = this.$activePanel) == null || p.removeAttribute("inverted"), (v = this.$activeTab) == null || v.removeAttribute("inverted"), [...this.$tabs].forEach((c) => {
226
- c.removeAttribute("inverted");
227
- }));
228
- }, $ = function(t) {
229
- t === "" ? (this.$prefixButton.remove(), this.$suffixButton.remove()) : (this.$suffixButton.setAttribute(
230
- "aria-label",
231
- this.nextAriaLabel || "Next tab"
232
- ), this.$prefixButton.setAttribute(
233
- "aria-label",
234
- this.previousAriaLabel || "Previous tab"
235
- ));
236
- };
237
- const w = ":host [role=tabpanel]{overflow-x:auto}", y = new CSSStyleSheet();
238
- y.replaceSync(w);
239
- class B extends HTMLElement {
240
- constructor() {
241
- super(), this.template = () => `
2
+ import { booleanPropertyToAttributeSetter as e, propertyToAttributeSetter as t } from "@proximus/lavender-common";
3
+ //#region src/tab.css?inline
4
+ var n = "*{font-family:var(--px-font-family)}:host{background-color:var(--px-color-background-container-default-default)}:host(:first-child),:host(:first-child) .tab-btn{border-radius:var(--px-radius-main) var(--px-radius-none) var(--px-radius-none) var(--px-radius-main)}:host(:last-of-type),:host(:last-of-type) .tab-btn{border-radius:var(--px-radius-none) var(--px-radius-main) var(--px-radius-main) var(--px-radius-none)}:host([selected]){background-color:var(--px-color-background-state-active-default);border-radius:var(--px-radius-main)!important}:host([selected])>.tab-btn{cursor:auto;padding-block:var(--px-padding-m-mobile);color:var(--px-color-text-neutral-inverted)}.tab-btn{padding:var(--px-padding-s-mobile);cursor:pointer;height:inherit;width:inherit;font-size:var(--px-text-size-label-l-mobile);font-weight:var(--px-font-weight-title);text-wrap:nowrap;color:var(--px-color-text-neutral-default);background:0 0;border:none;outline:none;margin:0}:host(:focus-visible){outline-offset:var(--px-focus-offset-mobile);outline:var(--px-focus-outline-mobile) solid var(--px-color-border-focus-outline-default)}:host(:not([selected])) .tab-btn:hover{background-color:var(--px-color-background-state-hover-default)}:host([inverted]){background-color:var(--px-color-background-container-default-inverted)}:host([inverted]) .tab-btn{color:var(--px-color-text-neutral-inverted)}:host([inverted]:not([selected])) .tab-btn:hover{background-color:var(--px-color-background-state-hover-inverted)}:host([inverted][selected]){background-color:var(--px-color-background-state-active-inverted)}:host([inverted][selected]) .tab-btn{color:var(--px-color-text-brand-default)}:host([inverted]:focus-visible){outline-color:var(--px-color-border-focus-outline-inverted)}@media screen and (width>=48rem){.tab-btn{padding:var(--px-padding-s-desktop);font-size:var(--px-text-size-label-l-desktop)}:host[selected]>.tab-btn{padding-block:var(--px-padding-m-desktop)}}@media screen and (width>=64.0625rem){.tab-btn{padding:var(--px-padding-s-desktop);font-size:var(--px-text-size-label-l-desktop);padding:var(--px-padding-s-desktop);font-size:var(--px-text-size-label-l-desktop)}:host[selected]>.tab-btn{padding-block:var(--px-padding-m-desktop)}}", r = new CSSStyleSheet();
5
+ r.replaceSync(n);
6
+ var i = "px.lavender.tab.selected", a = "px-tab-connected", o = class extends HTMLElement {
7
+ static get observedAttributes() {
8
+ return [
9
+ "selected",
10
+ "target",
11
+ "id",
12
+ "inverted"
13
+ ];
14
+ }
15
+ constructor() {
16
+ super(), this.template = () => "\n <div class=\"tab-btn\"><slot></slot></div>\n ", this.attachShadow({ mode: "open" }), this.shadowRoot.innerHTML = this.template(), this.shadowRoot.adoptedStyleSheets = [r], this.internals = this.attachInternals?.();
17
+ }
18
+ connectedCallback() {
19
+ this.role = "tab", this.internals && (this.internals.role = "tab"), this.ariaSelected = `${this.selected}`, this.slot = "tabs", this.dispatchEvent(new CustomEvent(a, {
20
+ bubbles: !0,
21
+ composed: !0
22
+ })), this.addEventListener("click", () => {
23
+ this.selected = !0;
24
+ });
25
+ }
26
+ attributeChangedCallback(e, t, n) {
27
+ e === "selected" ? this.handleSelected(n) : e === "id" ? this.$tabBtn.setAttribute("id", n) : e === "target" ? this.setAttribute("aria-controls", n) : e === "inverted" && (n === "" ? this.$tabBtn.setAttribute("inverted", "") : this.$tabBtn.removeAttribute("inverted"));
28
+ }
29
+ get $tabBtn() {
30
+ return this.shadowRoot.querySelector(".tab-btn");
31
+ }
32
+ get selected() {
33
+ return this.hasAttribute("selected");
34
+ }
35
+ set selected(t) {
36
+ e(this, "selected", t);
37
+ }
38
+ get inverted() {
39
+ return this.hasAttribute("inverted");
40
+ }
41
+ set target(e) {
42
+ t(this, "target", e);
43
+ }
44
+ get target() {
45
+ return this.getAttribute("target");
46
+ }
47
+ handleSelected(e) {
48
+ e === "" ? (setTimeout(() => {
49
+ this.target && this.dispatchEvent(new CustomEvent(i, {
50
+ bubbles: !0,
51
+ composed: !0,
52
+ detail: {
53
+ tabId: this.id,
54
+ targetId: this.target
55
+ }
56
+ }));
57
+ }), this.focus(), this.tabIndex = 0, this.internals && (this.internals.ariaSelected = "true"), this.ariaSelected = "true") : (this.tabIndex = -1, this.internals && (this.internals.ariaSelected = "false"), this.ariaSelected = "false");
58
+ }
59
+ }, s = "*{font-family:var(--px-font-family)}#container{align-items:flex-start;gap:var(--px-spacing-default-mobile);flex-direction:column;display:flex}#tab-container{width:100%;position:relative}#tab-container>#previous{position:absolute;top:12px;left:-24px}#tab-container>#next{position:absolute;top:12px;right:-24px}#panels{width:100%}#tablist{scrollbar-width:none;box-sizing:border-box;width:100%;margin:calc(calc(var(--px-focus-outline-mobile) + var(--px-focus-offset-mobile)) * -1);padding:calc(var(--px-focus-outline-mobile) + var(--px-focus-offset-mobile));align-items:center;display:flex;overflow:scroll}#tablist::-webkit-scrollbar{display:none}:host([inverted]) button[role=tab]{color:var(--px-color-text-neutral-inverted)}:host([inverted]) button[aria-selected=\"\"]{color:var(--px-color-text-brand-default)}@media screen and (width>=48rem){#container{gap:var(--px-spacing-default-desktop)}#tablist{margin:calc(calc(var(--px-focus-outline-tablet) + var(--px-focus-offset-tablet)) * -1);padding:calc(var(--px-focus-outline-tablet) + var(--px-focus-offset-tablet))}}@media screen and (width>=64.0625rem){#container{gap:var(--px-spacing-default-desktop)}#tablist{margin:calc(calc(var(--px-focus-outline-desktop) + var(--px-focus-offset-desktop)) * -1);padding:calc(var(--px-focus-outline-desktop) + var(--px-focus-offset-desktop))}}", c = new CSSStyleSheet();
60
+ c.replaceSync(s);
61
+ //#endregion
62
+ //#region src/Tabs.ts
63
+ var l = class extends HTMLElement {
64
+ static get observedAttributes() {
65
+ return [
66
+ "inverted",
67
+ "next-aria-label",
68
+ "previous-aria-label",
69
+ "hide-controls"
70
+ ];
71
+ }
72
+ constructor() {
73
+ super(), this.template = () => "\n <div id=\"container\">\n <div id=\"tab-container\">\n <px-button-icon id=\"previous\" hidden--mobile hidden--tablet>\n <px-icon name=\"chevron_left\" from=\"lavender\"></px-icon>\n </px-button-icon>\n <div id=\"tablist\">\n <slot name=\"tabs\"></slot>\n </div>\n <px-button-icon id=\"next\" hidden--mobile hidden--tablet>\n <px-icon name=\"chevron_right\" from=\"lavender\"></px-icon>\n </px-button-icon>\n </div>\n <div id=\"panels\">\n <slot name=\"tabpanels\"></slot>\n </div>\n </div>\n ", this.handleNextPreviousDisplay = () => {
74
+ this.$prefixButton && this.$suffixButton && (this.$prefixButton.style.display = this.shouldDisplayScrollLeftButton() ? "" : "none", this.$suffixButton.style.display = this.shouldDisplayScrollRightButton() ? "" : "none");
75
+ }, this.attachShadow({ mode: "open" }), this.shadowRoot.innerHTML = this.template(), this.shadowRoot.adoptedStyleSheets = [c], this.internals = this.attachInternals?.();
76
+ }
77
+ attributeChangedCallback(e, t, n) {
78
+ switch (e) {
79
+ case "next-aria-label":
80
+ this.hasAttribute("hide-controls") || this.$suffixButton.setAttribute("aria-label", n);
81
+ break;
82
+ case "previous-aria-label":
83
+ this.hasAttribute("hide-controls") || this.$prefixButton.setAttribute("aria-label", n);
84
+ break;
85
+ case "hide-controls":
86
+ this.#t(n);
87
+ break;
88
+ case "inverted": this.#e(n);
89
+ }
90
+ }
91
+ connectedCallback() {
92
+ this.$tabList.role = "tablist", this.addEventListener(i, (e) => {
93
+ [...this.$tabPanels].forEach((t) => {
94
+ t.getAttribute("panel-id") !== e.detail.targetId && t.hasAttribute("selected") && (t.removeAttribute("selected"), t.removeAttribute("aria-labelledby")), t.getAttribute("panel-id") === e.detail.targetId && (t.setAttribute("selected", ""), t.setAttribute("aria-labelledby", e.detail.tabId));
95
+ }), [...this.$tabs].forEach((t) => {
96
+ t.getAttribute("id") !== e.detail.tabId && t.hasAttribute("selected") && t.removeAttribute("selected");
97
+ });
98
+ }), this.addEventListener(a, () => {
99
+ this.handleNextPreviousDisplay(), this.inverted && this.#e(this.getAttribute("inverted"));
100
+ }), this.handleNextPreviousDisplay(), this.#e(this.getAttribute("inverted")), this.addEventListener("keydown", (e) => {
101
+ (e.key === "ArrowRight" || e.key === "ArrowLeft") && document.activeElement?.localName?.endsWith("-tab") && this.navigateToTab(e.key === "ArrowRight" ? "right" : "left");
102
+ }), this.$prefixButton?.addEventListener("click", (e) => {
103
+ e.stopPropagation(), this.$tabList.scrollTo({
104
+ left: this.$tabList.scrollLeft - 100,
105
+ behavior: "smooth"
106
+ });
107
+ }), this.$suffixButton?.addEventListener("click", (e) => {
108
+ e.stopPropagation(), this.$tabList.scrollTo({
109
+ left: this.$tabList.scrollLeft + 100,
110
+ behavior: "smooth"
111
+ });
112
+ }), window.addEventListener("resize", this.handleNextPreviousDisplay), this.$tabList.addEventListener("scroll", this.handleNextPreviousDisplay);
113
+ }
114
+ disconnectedCallback() {
115
+ window.addEventListener("resize", this.handleNextPreviousDisplay);
116
+ }
117
+ #e(e) {
118
+ e === "" ? (this.$prefixButton?.setAttribute("inverted", ""), this.$suffixButton?.setAttribute("inverted", ""), this.$activePanel?.setAttribute("inverted", ""), this.$activeTab?.setAttribute("inverted", ""), [...this.$tabs].forEach((e) => {
119
+ e.setAttribute("inverted", "");
120
+ })) : (this.$prefixButton?.removeAttribute("inverted"), this.$suffixButton?.removeAttribute("inverted"), this.$activePanel?.removeAttribute("inverted"), this.$activeTab?.removeAttribute("inverted"), [...this.$tabs].forEach((e) => {
121
+ e.removeAttribute("inverted");
122
+ }));
123
+ }
124
+ #t(e) {
125
+ e === "" ? (this.$prefixButton.remove(), this.$suffixButton.remove()) : (this.$suffixButton.setAttribute("aria-label", this.nextAriaLabel || "Next tab"), this.$prefixButton.setAttribute("aria-label", this.previousAriaLabel || "Previous tab"));
126
+ }
127
+ navigateToTab(e) {
128
+ let t = this.$nextTab, n = this.$previousTab;
129
+ this.$activePanel.selected = !1, this.$activeTab.selected = !1, e === "right" ? (t.selected = !0, t.focus()) : e === "left" && (n.selected = !0, n.focus()), this.$activePanel.selected = !0;
130
+ }
131
+ shouldDisplayScrollRightButton() {
132
+ return this.$tabList.scrollWidth > this.$tabList.clientWidth && this.$tabList.scrollWidth - this.$tabList.scrollLeft !== this.$tabList.clientWidth;
133
+ }
134
+ shouldDisplayScrollLeftButton() {
135
+ return this.$tabList.scrollLeft > 0;
136
+ }
137
+ get $activeTab() {
138
+ return this.querySelector("[selected=\"\"][slot=\"tabs\"]");
139
+ }
140
+ get $nextTab() {
141
+ let e = this.$activeTab.nextElementSibling;
142
+ return e?.slot === "tabs" ? e : this.querySelector("[slot=\"tabs\"]");
143
+ }
144
+ get $previousTab() {
145
+ return this.$activeTab.previousElementSibling || Array.from(this.querySelectorAll("[slot=\"tabs\"]")).pop();
146
+ }
147
+ get $activePanel() {
148
+ return this.querySelector(`[panel-id="${this.$activeTab?.target}"]`);
149
+ }
150
+ get $tabList() {
151
+ return this.shadowRoot.querySelector("#tablist");
152
+ }
153
+ get $tabs() {
154
+ return this.querySelectorAll("[slot=\"tabs\"]");
155
+ }
156
+ get $tabPanels() {
157
+ return this.querySelectorAll("[slot=\"tabpanels\"]");
158
+ }
159
+ get $prefixButton() {
160
+ return this.shadowRoot.querySelector("#previous");
161
+ }
162
+ get $suffixButton() {
163
+ return this.shadowRoot.querySelector("#next");
164
+ }
165
+ get hideControls() {
166
+ return this.hasAttribute("hide-controls");
167
+ }
168
+ set hideControls(e) {
169
+ e ? this.setAttribute("hide-controls", "") : this.removeAttribute("hide-controls");
170
+ }
171
+ get inverted() {
172
+ return this.hasAttribute("inverted");
173
+ }
174
+ set inverted(e) {
175
+ e ? this.setAttribute("inverted", "") : this.removeAttribute("inverted");
176
+ }
177
+ get nextAriaLabel() {
178
+ return this.getAttribute("next-aria-label");
179
+ }
180
+ set nextAriaLabel(e) {
181
+ t(this, "next-aria-label", e);
182
+ }
183
+ get previousAriaLabel() {
184
+ return this.getAttribute("previous-aria-label");
185
+ }
186
+ set previousAriaLabel(e) {
187
+ t(this, "previous-aria-label", e);
188
+ }
189
+ }, u = ":host [role=tabpanel]{overflow-x:auto}", d = new CSSStyleSheet();
190
+ d.replaceSync(u);
191
+ var f = class extends HTMLElement {
192
+ static get observedAttributes() {
193
+ return ["id", "selected"];
194
+ }
195
+ constructor() {
196
+ super(), this.template = () => `
242
197
  <div role="tabpanel" id="${this.panelId}" tabindex="0">
243
198
  <slot></slot>
244
199
  </div>
245
- `, this.attachShadow({ mode: "open" }), this.shadowRoot.innerHTML = this.template(), this.shadowRoot.adoptedStyleSheets = [b, y];
246
- }
247
- static get observedAttributes() {
248
- return ["id", "selected"];
249
- }
250
- attributeChangedCallback(e, t, s) {
251
- e === "panel-id" ? this.$panel.setAttribute("id", s) : e === "selected" && (s === "" ? this.$panel.style.display = "block" : this.$panel.style.display = "none");
252
- }
253
- connectedCallback() {
254
- this.slot = "tabpanels", this.$panel.style.display = "none";
255
- }
256
- get panelId() {
257
- return this.getAttribute("panel-id");
258
- }
259
- set panelId(e) {
260
- this.setAttribute("panel-id", e);
261
- }
262
- set selected(e) {
263
- e ? this.setAttribute("selected", "") : this.removeAttribute("selected");
264
- }
265
- get selected() {
266
- return this.hasAttribute("selected");
267
- }
268
- get $panel() {
269
- return this.shadowRoot.querySelector('[role="tabpanel"]');
270
- }
271
- }
272
- class C extends E {
273
- constructor() {
274
- super();
275
- }
276
- connectedCallback() {
277
- var e;
278
- (e = super.connectedCallback) == null || e.call(this), this.querySelectorAll("px-tab").forEach((t) => {
279
- t.setAttribute("slot", "tabs");
280
- });
281
- }
282
- }
283
- customElements.get("px-tabs") || customElements.define("px-tabs", C);
284
- class P extends L {
285
- constructor() {
286
- super();
287
- }
288
- }
289
- customElements.get("px-tab") || customElements.define("px-tab", P);
290
- class R extends B {
291
- constructor() {
292
- super();
293
- }
294
- }
295
- customElements.get("px-tab-panel") || customElements.define("px-tab-panel", R);
296
- export {
297
- P as PxTab,
298
- R as PxTabPanel,
299
- C as PxTabs
200
+ `, this.attachShadow({ mode: "open" }), this.shadowRoot.innerHTML = this.template(), this.shadowRoot.adoptedStyleSheets = [c, d];
201
+ }
202
+ attributeChangedCallback(e, t, n) {
203
+ e === "panel-id" ? this.$panel.setAttribute("id", n) : e === "selected" && (n === "" ? this.$panel.style.display = "block" : this.$panel.style.display = "none");
204
+ }
205
+ connectedCallback() {
206
+ this.slot = "tabpanels", this.$panel.style.display = "none";
207
+ }
208
+ get panelId() {
209
+ return this.getAttribute("panel-id");
210
+ }
211
+ set panelId(e) {
212
+ t(this, "panel-id", e);
213
+ }
214
+ set selected(t) {
215
+ e(this, "selected", t);
216
+ }
217
+ get selected() {
218
+ return this.hasAttribute("selected");
219
+ }
220
+ get $panel() {
221
+ return this.shadowRoot.querySelector("[role=\"tabpanel\"]");
222
+ }
223
+ }, p = class extends l {
224
+ constructor() {
225
+ super();
226
+ }
227
+ connectedCallback() {
228
+ super.connectedCallback?.(), this.querySelectorAll("px-tab").forEach((e) => {
229
+ e.setAttribute("slot", "tabs");
230
+ });
231
+ }
232
+ };
233
+ customElements.get("px-tabs") || customElements.define("px-tabs", p);
234
+ var m = class extends o {
235
+ constructor() {
236
+ super();
237
+ }
238
+ };
239
+ customElements.get("px-tab") || customElements.define("px-tab", m);
240
+ var h = class extends f {
241
+ constructor() {
242
+ super();
243
+ }
300
244
  };
245
+ customElements.get("px-tab-panel") || customElements.define("px-tab-panel", h);
246
+ //#endregion
247
+ export { m as PxTab, h as PxTabPanel, p as PxTabs };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proximus/lavender-tabs",
3
- "version": "2.0.0-alpha.165",
3
+ "version": "2.0.0-alpha.169",
4
4
  "description": "",
5
5
  "main": "dist/index.es.js",
6
6
  "types": "dist/index.d.ts",