@proximus/lavender-tabs 1.0.0-alpha.16
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/index.js +175 -0
- package/package.json +40 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { isFalsy as r } from "@proximus/lavender-common";
|
|
2
|
+
const o = '*{font-family:var(--px-font-family)}#container{display:flex;flex-direction:column;align-items:flex-start;gap:var(--px-spacing-component-default-vertical)}#panels{width:100%}div[role=tablist]{display:flex;align-items:center;scrollbar-width:none;overflow:scroll;width:80vw;box-sizing:border-box}div[role=tablist] ::slotted(px-tab){background-color:var(--px-color-bg-container-weak-default)}div[role=tablist] ::slotted(px-tab[inverted=""]){background-color:var(--px-color-bg-container-weak-inverted)}div[role=tablist] ::slotted(px-tab[selected=""]){background-color:var(--px-color-bg-action-active-default);padding-block:var(--px-padding-m);border-radius:var(--px-radius-main)!important}div[role=tablist] ::slotted(px-tab[selected=""][inverted=""]){background-color:var(--px-color-bg-action-active-inverted)}div[role=tablist] ::slotted(px-tab:first-child){border-radius:var(--px-radius-main) var(--px-radius-none) var(--px-radius-none) var(--px-radius-main)}div[role=tablist] ::slotted(px-tab:last-of-type){border-radius:var(--px-radius-none) var(--px-radius-main) var(--px-radius-main) var(--px-radius-none)}div[role=tablist]::-webkit-scrollbar{display:none}button[role=tab]{background:none;border:none;padding:0;margin:0;cursor:pointer;height:inherit;width:inherit;padding:var(--px-padding-s);font-size:var(--px-text-size-base-mobile);font-weight:700;text-wrap:nowrap;color:var(--px-color-txt-body-default);outline:none}button[role=tab][inverted=""]{color:var(--px-color-txt-body-inverted)}@media screen and (min-width: 768px){button[role=tab]{font-size:var(--px-text-size-base-tablet)}}@media screen and (min-width: 1025px){button[role=tab]{font-size:var(--px-text-size-base-laptop)}}@media screen and (min-width: 1441px){button[role=tab]{font-size:var(--px-text-size-base-desktop)}}button[aria-selected=""]{padding-block:0;cursor:auto;color:var(--px-color-txt-primary-inverted)}button[aria-selected=""][inverted=""]{color:var(--px-color-txt-primary-default)}', i = new CSSStyleSheet();
|
|
3
|
+
i.replaceSync(o);
|
|
4
|
+
class l extends HTMLElement {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(), this._label = `tabs-${Math.random().toString(36).substring(2, 15)}`, this.template = () => `
|
|
7
|
+
<div id="container">
|
|
8
|
+
<div role="tablist" aria-labelledby="${this._label}">
|
|
9
|
+
<slot name="tabs"></slot>
|
|
10
|
+
</div>
|
|
11
|
+
<div id="panels">
|
|
12
|
+
<slot name="tabpanels"></slot>
|
|
13
|
+
</div>
|
|
14
|
+
</div>
|
|
15
|
+
`, this.attachShadow({ mode: "open" }), this.getAttribute("label") && (this._label = this.getAttribute("label")), this.shadowRoot.innerHTML = this.template(), this.shadowRoot.adoptedStyleSheets = [i];
|
|
16
|
+
}
|
|
17
|
+
static get observedAttributes() {
|
|
18
|
+
return ["label", "inverted"];
|
|
19
|
+
}
|
|
20
|
+
attributeChangedCallback(t, a, e) {
|
|
21
|
+
t === "label" && (this.label = e);
|
|
22
|
+
}
|
|
23
|
+
connectedCallback() {
|
|
24
|
+
this.addEventListener("click", (t) => {
|
|
25
|
+
var a;
|
|
26
|
+
if ((a = t.target.localName) != null && a.endsWith("-tab")) {
|
|
27
|
+
this.$activePanel.selected = !1, this.$activeTab.selected = "false";
|
|
28
|
+
const e = t.target;
|
|
29
|
+
e && (e.selected = ""), this.$activePanel ? this.$activePanel.selected = !0 : console.error("No panel found for this tab");
|
|
30
|
+
}
|
|
31
|
+
}), this.addEventListener("keydown", (t) => {
|
|
32
|
+
if (t.key === "ArrowRight" || t.key === "ArrowLeft") {
|
|
33
|
+
const a = this.$nextTab, e = this.$previousTab;
|
|
34
|
+
this.$activePanel.selected = !1, this.$activeTab.selected = "false", t.key === "ArrowRight" ? a.selected = "" : t.key === "ArrowLeft" && (e.selected = ""), this.$activePanel.selected = !0;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
get $activeTab() {
|
|
39
|
+
return this.querySelector('[selected=""][slot="tabs"]');
|
|
40
|
+
}
|
|
41
|
+
get $nextTab() {
|
|
42
|
+
const t = this.$activeTab.nextElementSibling;
|
|
43
|
+
return t.slot !== "tabs" ? this.querySelector('[slot="tabs"]') : t;
|
|
44
|
+
}
|
|
45
|
+
get $previousTab() {
|
|
46
|
+
const t = this.$activeTab.previousElementSibling;
|
|
47
|
+
return t || Array.from(this.querySelectorAll('[slot="tabs"]')).pop();
|
|
48
|
+
}
|
|
49
|
+
get $activePanel() {
|
|
50
|
+
return this.querySelector(`[name="${this.$activeTab.for}"]`);
|
|
51
|
+
}
|
|
52
|
+
get $tabList() {
|
|
53
|
+
return this.shadowRoot.querySelector('[role="tablist"]');
|
|
54
|
+
}
|
|
55
|
+
get label() {
|
|
56
|
+
return this.$tabList.getAttribute("aria-labelledby");
|
|
57
|
+
}
|
|
58
|
+
set label(t) {
|
|
59
|
+
this.$tabList.setAttribute("aria-labelledby", t);
|
|
60
|
+
}
|
|
61
|
+
get inverted() {
|
|
62
|
+
return this.hasAttribute("inverted");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
class n extends HTMLElement {
|
|
66
|
+
constructor() {
|
|
67
|
+
super(), this.template = () => `
|
|
68
|
+
<button role="tab" aria-selected="false" type="button" tabindex="-1">
|
|
69
|
+
<span><slot></slot></span>
|
|
70
|
+
</button>
|
|
71
|
+
`, this.attachShadow({ mode: "open" }), this.shadowRoot.innerHTML = this.template(), this.shadowRoot.adoptedStyleSheets = [i];
|
|
72
|
+
}
|
|
73
|
+
static get observedAttributes() {
|
|
74
|
+
return ["selected", "for", "name"];
|
|
75
|
+
}
|
|
76
|
+
connectedCallback() {
|
|
77
|
+
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", ""));
|
|
78
|
+
}
|
|
79
|
+
attributeChangedCallback(t, a, e) {
|
|
80
|
+
t === "selected" ? this.handleSelected(e) : t === "name" ? this.$button.setAttribute("id", e) : t === "for" && this.$button.setAttribute("aria-controls", e);
|
|
81
|
+
}
|
|
82
|
+
get $button() {
|
|
83
|
+
return this.shadowRoot.querySelector("button");
|
|
84
|
+
}
|
|
85
|
+
get selected() {
|
|
86
|
+
return this.$button.getAttribute("aria-selected");
|
|
87
|
+
}
|
|
88
|
+
get inverted() {
|
|
89
|
+
return this.hasAttribute("inverted");
|
|
90
|
+
}
|
|
91
|
+
set name(t) {
|
|
92
|
+
this.setAttribute("name", t);
|
|
93
|
+
}
|
|
94
|
+
get name() {
|
|
95
|
+
return this.getAttribute("name");
|
|
96
|
+
}
|
|
97
|
+
set for(t) {
|
|
98
|
+
this.setAttribute("for", t);
|
|
99
|
+
}
|
|
100
|
+
get for() {
|
|
101
|
+
return this.getAttribute("for");
|
|
102
|
+
}
|
|
103
|
+
handleSelected(t) {
|
|
104
|
+
r(t) ? (this.$button.removeAttribute("aria-selected"), this.$button.tabIndex = -1) : (this.$button.setAttribute("aria-selected", t), this.$button.removeAttribute("tabindex"), this.$button.focus());
|
|
105
|
+
}
|
|
106
|
+
set selected(t) {
|
|
107
|
+
this.setAttribute("selected", t);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
class d extends HTMLElement {
|
|
111
|
+
constructor() {
|
|
112
|
+
super(), this.template = () => `
|
|
113
|
+
<div role="tabpanel" aria-labelledby="${this.name}" tabindex="0">
|
|
114
|
+
<slot></slot>
|
|
115
|
+
</div>
|
|
116
|
+
`, this.attachShadow({ mode: "open" }), this.shadowRoot.innerHTML = this.template(), this.shadowRoot.adoptedStyleSheets = [i];
|
|
117
|
+
}
|
|
118
|
+
static get observedAttributes() {
|
|
119
|
+
return ["name"];
|
|
120
|
+
}
|
|
121
|
+
attributeChangedCallback(t, a, e) {
|
|
122
|
+
t === "name" && this.$panel.setAttribute("aria-labelledby", e);
|
|
123
|
+
}
|
|
124
|
+
connectedCallback() {
|
|
125
|
+
this.name || console.error("TabPanel needs a name attribute"), this.slot = "tabpanels";
|
|
126
|
+
const t = this.parentElement.querySelector(
|
|
127
|
+
`[for="${this.getAttribute("name")}"]`
|
|
128
|
+
);
|
|
129
|
+
t ? this.$panel.setAttribute(
|
|
130
|
+
"aria-labelledby",
|
|
131
|
+
t.getAttribute("name")
|
|
132
|
+
) : console.error("No tab found for this panel");
|
|
133
|
+
const a = this.parentElement.querySelector(
|
|
134
|
+
`[for="${this.name}"]`
|
|
135
|
+
);
|
|
136
|
+
r(a.selected) ? this.selected = !1 : this.selected = !0;
|
|
137
|
+
}
|
|
138
|
+
get name() {
|
|
139
|
+
return this.getAttribute("name");
|
|
140
|
+
}
|
|
141
|
+
set name(t) {
|
|
142
|
+
this.setAttribute("name", t);
|
|
143
|
+
}
|
|
144
|
+
set selected(t) {
|
|
145
|
+
t ? this.$panel.style.display = "block" : this.$panel.style.display = "none";
|
|
146
|
+
}
|
|
147
|
+
get $panel() {
|
|
148
|
+
return this.shadowRoot.querySelector('[role="tabpanel"]');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
class b extends l {
|
|
152
|
+
constructor() {
|
|
153
|
+
super(), this.querySelectorAll("px-tab").forEach((t) => {
|
|
154
|
+
t.setAttribute("slot", "tabs");
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
customElements.get("px-tabs") || customElements.define("px-tabs", b);
|
|
159
|
+
class c extends n {
|
|
160
|
+
constructor() {
|
|
161
|
+
super();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
customElements.get("px-tab") || customElements.define("px-tab", c);
|
|
165
|
+
class u extends d {
|
|
166
|
+
constructor() {
|
|
167
|
+
super();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
customElements.get("px-tab-panel") || customElements.define("px-tab-panel", u);
|
|
171
|
+
export {
|
|
172
|
+
c as PxTab,
|
|
173
|
+
u as PxTabPanel,
|
|
174
|
+
b as PxTabs
|
|
175
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@proximus/lavender-tabs",
|
|
3
|
+
"version": "1.0.0-alpha.16",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./src/index.ts",
|
|
9
|
+
"development": "./src/index.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./src/*.css": {
|
|
13
|
+
"development": "src/*.css"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "rm -rf dist;tsc; vite build",
|
|
22
|
+
"test": "vitest run --coverage"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"gitHead": "15a231df98020f83813279639a9a7712a5a5e759",
|
|
28
|
+
"lerna": {
|
|
29
|
+
"command": {
|
|
30
|
+
"publish": {
|
|
31
|
+
"assets": [
|
|
32
|
+
"CHANGELOG.md",
|
|
33
|
+
"package.json",
|
|
34
|
+
"dist/*.js",
|
|
35
|
+
"dist/css/**/*.css"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|