@proximus/lavender-tabs 2.0.0-alpha.17 → 2.0.0-alpha.170

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/PxTabs.d.ts CHANGED
@@ -3,6 +3,7 @@ import { Tab } from './Tab.ts';
3
3
  import { TabPanel } from './TabPanel.ts';
4
4
  export declare class PxTabs extends Tabs {
5
5
  constructor();
6
+ connectedCallback(): void;
6
7
  }
7
8
  export declare class PxTab extends Tab {
8
9
  constructor();
package/dist/Tab.d.ts CHANGED
@@ -1,3 +1,9 @@
1
+ export declare const TAB_SELECTED_EVENT = "px.lavender.tab.selected";
2
+ export declare const TAB_CONNECTED_EVENT = "px-tab-connected";
3
+ export type TabSelectedDetail = {
4
+ tabId: string;
5
+ targetId: string;
6
+ };
1
7
  export declare class Tab extends HTMLElement {
2
8
  internals: ElementInternals;
3
9
  template: () => string;
@@ -9,9 +15,7 @@ export declare class Tab extends HTMLElement {
9
15
  get selected(): boolean;
10
16
  set selected(value: boolean);
11
17
  get inverted(): boolean;
12
- set id(value: string);
13
- get id(): string;
14
- set target(value: string);
15
- get target(): string;
18
+ set target(value: string | null);
19
+ get target(): string | null;
16
20
  handleSelected(value: string): void;
17
21
  }
@@ -4,8 +4,9 @@ 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
+ get selected(): boolean;
10
11
  get $panel(): HTMLElement;
11
12
  }
package/dist/Tabs.d.ts CHANGED
@@ -1,18 +1,20 @@
1
1
  import '@proximus/lavender-button-icon';
2
- import { Tab } from './Tab.ts';
3
- import { TabPanel } from './TabPanel.ts';
2
+ import { type Tab } from './Tab.ts';
3
+ import { type TabPanel } from './TabPanel.ts';
4
+ import type { TabsEventMap } from './events.ts';
4
5
  export declare class Tabs extends HTMLElement {
6
+ #private;
5
7
  internals: ElementInternals;
6
- tabsConnected: number;
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();
10
13
  attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
11
14
  connectedCallback(): void;
12
- checkNextPreviousButtonsVisibility(): void;
15
+ disconnectedCallback(): void;
13
16
  navigateToTab(direction: 'left' | 'right'): void;
14
- handleNextPreviousDisplay(): void;
15
- allTabsConnected(): boolean;
17
+ handleNextPreviousDisplay: () => void;
16
18
  shouldDisplayScrollRightButton(): boolean;
17
19
  shouldDisplayScrollLeftButton(): boolean;
18
20
  get $activeTab(): Tab;
@@ -20,16 +22,16 @@ export declare class Tabs extends HTMLElement {
20
22
  get $previousTab(): Tab;
21
23
  get $activePanel(): TabPanel;
22
24
  get $tabList(): HTMLElement;
25
+ get $tabs(): NodeListOf<Tab>;
26
+ get $tabPanels(): NodeListOf<TabPanel>;
23
27
  get $prefixButton(): HTMLButtonElement;
24
- get $prefixButtonIcon(): HTMLElement;
25
28
  get $suffixButton(): HTMLButtonElement;
26
- get $suffixButtonIcon(): HTMLElement;
27
- get tablistAriaLabelledby(): string;
28
- set tablistAriaLabelledby(value: string);
29
+ get hideControls(): boolean;
30
+ set hideControls(value: boolean);
29
31
  get inverted(): boolean;
30
32
  set inverted(value: boolean);
31
- get nextAriaLabel(): string;
32
- set nextAriaLabel(value: string);
33
- get previousAriaLabel(): string;
34
- 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);
35
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,275 +1,247 @@
1
1
  import "@proximus/lavender-button-icon";
2
- import { isFalsy as c } from "@proximus/lavender-common";
3
- const b = '*{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:.75em;left:-1.5em}#tab-container>#next{position:absolute;top:.75em;right:-1.5em}#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 only screen and (min-width: 768px){#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 only screen and (min-width: 1025px){#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))}}', l = new CSSStyleSheet();
4
- l.replaceSync(b);
5
- class u extends HTMLElement {
6
- constructor() {
7
- var t;
8
- super(), this.tabsConnected = 0, this.template = () => `
9
- <div id="container">
10
- <div id="tab-container">
11
- <px-button-icon id="previous">
12
- <px-icon name="chevron_left" from="lavender"></px-icon>
13
- </px-button-icon>
14
- <div id="tablist">
15
- <slot name="tabs"></slot>
16
- </div>
17
- <px-button-icon id="next" >
18
- <px-icon name="chevron_right" from="lavender"></px-icon>
19
- </px-button-icon>
20
- </div>
21
- <div id="panels">
22
- <slot name="tabpanels"></slot>
23
- </div>
24
- </div>
25
- `, this.attachShadow({ mode: "open" }), this.shadowRoot.innerHTML = this.template(), this.getAttribute("tablist-aria-labelledby") && this.$tabList.setAttribute(
26
- "aria-labelledby",
27
- this.getAttribute("tablist-aria-labelledby")
28
- ), this.shadowRoot.innerHTML = this.template(), this.shadowRoot.adoptedStyleSheets = [l], this.internals = (t = this.attachInternals) == null ? void 0 : t.call(this), this.$tabList.role = "tablist", this.addEventListener("px-tab-connected", () => {
29
- this.tabsConnected++, this.handleNextPreviousDisplay();
30
- }), window.addEventListener("resize", () => {
31
- this.handleNextPreviousDisplay();
32
- }), this.$tabList.addEventListener("scroll", () => {
33
- this.handleNextPreviousDisplay();
34
- });
35
- }
36
- static get observedAttributes() {
37
- return [
38
- "tablist-aria-labelledby",
39
- "inverted",
40
- "next-aria-label",
41
- "previous-aria-label"
42
- ];
43
- }
44
- attributeChangedCallback(t, i, e) {
45
- switch (t) {
46
- case "tablist-aria-labelledby":
47
- this.$tabList.setAttribute("aria-labelledby", e);
48
- break;
49
- case "next-aria-label":
50
- this.hasAttribute("hide-controls") || this.$suffixButtonIcon.setAttribute("aria-label", e);
51
- break;
52
- case "previous-aria-label":
53
- this.hasAttribute("hide-controls") || this.$prefixButtonIcon.setAttribute("aria-label", e);
54
- break;
55
- }
56
- }
57
- connectedCallback() {
58
- var t, i, e, n;
59
- this.checkNextPreviousButtonsVisibility(), this.addEventListener("click", (s) => {
60
- var r;
61
- if ((r = s.target.localName) != null && r.endsWith("-tab")) {
62
- this.$activePanel.selected = !1, this.$activeTab.selected = !1;
63
- const o = s.target;
64
- o && (o.selected = !0), this.$activePanel && (this.$activePanel.selected = !0);
65
- }
66
- }), this.addEventListener("keydown", (s) => {
67
- var r, o;
68
- (s.key === "ArrowRight" || s.key === "ArrowLeft") && ((o = (r = document.activeElement) == null ? void 0 : r.localName) != null && o.endsWith("-tab")) && this.navigateToTab(s.key === "ArrowRight" ? "right" : "left");
69
- }), (t = this.$prefixButton) == null || t.addEventListener("click", (s) => {
70
- s.stopPropagation(), this.$tabList.scrollTo({
71
- left: this.$tabList.scrollLeft - 100,
72
- behavior: "smooth"
73
- });
74
- }), (i = this.$suffixButton) == null || i.addEventListener("click", (s) => {
75
- s.stopPropagation(), this.$tabList.scrollTo({
76
- left: this.$tabList.scrollLeft + 100,
77
- behavior: "smooth"
78
- });
79
- }), this.inverted && ((e = this.$prefixButton) == null || e.setAttribute("inverted", ""), (n = this.$suffixButton) == null || n.setAttribute("inverted", "")), this.hasAttribute("hide-controls") || (this.$suffixButtonIcon.setAttribute(
80
- "aria-label",
81
- this.nextAriaLabel || "Next tab"
82
- ), this.$prefixButtonIcon.setAttribute(
83
- "aria-label",
84
- this.previousAriaLabel || "Previous tab"
85
- ));
86
- }
87
- checkNextPreviousButtonsVisibility() {
88
- (this.getAttribute("hide-controls") === "" || this.getAttribute("hide-controls") === "true") && (this.$prefixButton.remove(), this.$suffixButton.remove());
89
- }
90
- navigateToTab(t) {
91
- const i = this.$nextTab, e = this.$previousTab;
92
- this.$activePanel.selected = !1, this.$activeTab.selected = !1, t === "right" ? (i.selected = !0, i.focus()) : t === "left" && (e.selected = !0, e.focus()), this.$activePanel.selected = !0;
93
- }
94
- handleNextPreviousDisplay() {
95
- this.allTabsConnected() && this.$prefixButton && this.$suffixButton && (this.$prefixButton.style.display = this.shouldDisplayScrollLeftButton() ? "" : "none", this.$suffixButton.style.display = this.shouldDisplayScrollRightButton() ? "" : "none");
96
- }
97
- allTabsConnected() {
98
- return this.tabsConnected === this.querySelectorAll('[slot="tabs"]').length;
99
- }
100
- shouldDisplayScrollRightButton() {
101
- return this.allTabsConnected() && this.$tabList.scrollWidth > this.$tabList.clientWidth && this.$tabList.scrollWidth - this.$tabList.scrollLeft !== this.$tabList.clientWidth;
102
- }
103
- shouldDisplayScrollLeftButton() {
104
- return this.$tabList.scrollLeft > 0;
105
- }
106
- get $activeTab() {
107
- return this.querySelector('[selected=""][slot="tabs"]');
108
- }
109
- get $nextTab() {
110
- const t = this.$activeTab.nextElementSibling;
111
- return t.slot !== "tabs" ? this.querySelector('[slot="tabs"]') : t;
112
- }
113
- get $previousTab() {
114
- const t = this.$activeTab.previousElementSibling;
115
- return t || Array.from(this.querySelectorAll('[slot="tabs"]')).pop();
116
- }
117
- get $activePanel() {
118
- return this.querySelector(
119
- `[panel-id="${this.$activeTab.target}"]`
120
- );
121
- }
122
- get $tabList() {
123
- return this.shadowRoot.querySelector("#tablist");
124
- }
125
- get $prefixButton() {
126
- return this.shadowRoot.querySelector("#previous");
127
- }
128
- get $prefixButtonIcon() {
129
- return this.shadowRoot.querySelector("#previous px-icon");
130
- }
131
- get $suffixButton() {
132
- return this.shadowRoot.querySelector("#next");
133
- }
134
- get $suffixButtonIcon() {
135
- return this.shadowRoot.querySelector("#next px-icon");
136
- }
137
- get tablistAriaLabelledby() {
138
- return this.$tabList.getAttribute("aria-labelledby");
139
- }
140
- set tablistAriaLabelledby(t) {
141
- this.$tabList.setAttribute("aria-labelledby", t);
142
- }
143
- get inverted() {
144
- return this.hasAttribute("inverted");
145
- }
146
- set inverted(t) {
147
- t ? this.setAttribute("inverted", "") : this.removeAttribute("inverted");
148
- }
149
- get nextAriaLabel() {
150
- return this.getAttribute("next-aria-label");
151
- }
152
- set nextAriaLabel(t) {
153
- this.setAttribute("next-aria-label", t);
154
- }
155
- get previousAriaLabel() {
156
- return this.getAttribute("previous-aria-label");
157
- }
158
- set previousAriaLabel(t) {
159
- this.setAttribute("previous-aria-label", t);
160
- }
161
- }
162
- const h = "*{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 only screen and (min-width: 768px){.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 only screen and (min-width: 1025px){.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)}}", d = new CSSStyleSheet();
163
- d.replaceSync(h);
164
- class p extends HTMLElement {
165
- constructor() {
166
- var t;
167
- super(), this.template = () => `
168
- <div class="tab-btn"><slot></slot></div>
169
- `, this.attachShadow({ mode: "open" }), this.shadowRoot.innerHTML = this.template(), this.shadowRoot.adoptedStyleSheets = [d], this.internals = (t = this.attachInternals) == null ? void 0 : t.call(this), this.role = "tab", this.internals && (this.internals.role = "tab"), this.ariaSelected = `${this.selected}`;
170
- }
171
- static get observedAttributes() {
172
- return ["selected", "target", "id"];
173
- }
174
- connectedCallback() {
175
- this.slot = "tabs", this.parentElement.inverted && (this.setAttribute("inverted", ""), this.$tabBtn.setAttribute("inverted", "")), this.dispatchEvent(
176
- new CustomEvent("px-tab-connected", { bubbles: !0, composed: !0 })
177
- );
178
- }
179
- attributeChangedCallback(t, i, e) {
180
- t === "selected" ? this.handleSelected(e) : t === "target" && this.setAttribute("aria-controls", e);
181
- }
182
- get $tabBtn() {
183
- return this.shadowRoot.querySelector(".tab-btn");
184
- }
185
- get selected() {
186
- return !!this.hasAttribute("selected");
187
- }
188
- set selected(t) {
189
- t ? this.setAttribute("selected", "") : this.removeAttribute("selected");
190
- }
191
- get inverted() {
192
- return this.hasAttribute("inverted");
193
- }
194
- set id(t) {
195
- this.setAttribute("id", t);
196
- }
197
- get id() {
198
- return this.getAttribute("id");
199
- }
200
- set target(t) {
201
- this.setAttribute("target", t);
202
- }
203
- get target() {
204
- return this.getAttribute("target");
205
- }
206
- handleSelected(t) {
207
- t === null ? (this.tabIndex = -1, this.internals && (this.internals.ariaSelected = "false"), this.ariaSelected = "false") : (this.focus(), this.tabIndex = 0, this.internals && (this.internals.ariaSelected = "true"), this.ariaSelected = "true");
208
- }
209
- }
210
- class v extends HTMLElement {
211
- constructor() {
212
- 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 = () => `
213
197
  <div role="tabpanel" id="${this.panelId}" tabindex="0">
214
198
  <slot></slot>
215
199
  </div>
216
- `, this.attachShadow({ mode: "open" }), this.shadowRoot.innerHTML = this.template(), this.shadowRoot.adoptedStyleSheets = [l];
217
- }
218
- static get observedAttributes() {
219
- return ["id"];
220
- }
221
- attributeChangedCallback(t, i, e) {
222
- t === "panel-id" && this.$panel.setAttribute("id", e);
223
- }
224
- connectedCallback() {
225
- this.slot = "tabpanels";
226
- const t = this.parentElement.querySelector(
227
- `[target="${this.panelId}"]`
228
- );
229
- t && this.$panel.setAttribute(
230
- "aria-labelledby",
231
- t.getAttribute("id")
232
- );
233
- const i = this.parentElement.querySelector(
234
- `[target="${this.panelId}"]`
235
- );
236
- c(i.selected) ? this.selected = !1 : this.selected = !0;
237
- }
238
- get panelId() {
239
- return this.getAttribute("panel-id");
240
- }
241
- set panelId(t) {
242
- this.setAttribute("panel-id", t);
243
- }
244
- set selected(t) {
245
- t ? this.$panel.style.display = "block" : this.$panel.style.display = "none";
246
- }
247
- get $panel() {
248
- return this.shadowRoot.querySelector('[role="tabpanel"]');
249
- }
250
- }
251
- class f extends u {
252
- constructor() {
253
- super(), this.querySelectorAll("px-tab").forEach((t) => {
254
- t.setAttribute("slot", "tabs");
255
- });
256
- }
257
- }
258
- customElements.get("px-tabs") || customElements.define("px-tabs", f);
259
- class x extends p {
260
- constructor() {
261
- super();
262
- }
263
- }
264
- customElements.get("px-tab") || customElements.define("px-tab", x);
265
- class g extends v {
266
- constructor() {
267
- super();
268
- }
269
- }
270
- customElements.get("px-tab-panel") || customElements.define("px-tab-panel", g);
271
- export {
272
- x as PxTab,
273
- g as PxTabPanel,
274
- f 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
+ }
275
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.17",
3
+ "version": "2.0.0-alpha.170",
4
4
  "description": "",
5
5
  "main": "dist/index.es.js",
6
6
  "types": "dist/index.d.ts",