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