@proximus/lavender-tabs 2.0.0-alpha.2 → 2.0.0-alpha.200

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