@waggylabs/yumekit 0.2.0
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/components/y-appbar.d.ts +28 -0
- package/dist/components/y-appbar.js +1707 -0
- package/dist/components/y-avatar.d.ts +5 -0
- package/dist/components/y-avatar.js +108 -0
- package/dist/components/y-badge.d.ts +15 -0
- package/dist/components/y-badge.js +149 -0
- package/dist/components/y-button.d.ts +19 -0
- package/dist/components/y-button.js +557 -0
- package/dist/components/y-card.d.ts +8 -0
- package/dist/components/y-card.js +157 -0
- package/dist/components/y-checkbox.d.ts +20 -0
- package/dist/components/y-checkbox.js +256 -0
- package/dist/components/y-dialog.d.ts +18 -0
- package/dist/components/y-dialog.js +232 -0
- package/dist/components/y-drawer.d.ts +1 -0
- package/dist/components/y-drawer.js +459 -0
- package/dist/components/y-icon.d.ts +19 -0
- package/dist/components/y-icon.js +270 -0
- package/dist/components/y-input.d.ts +15 -0
- package/dist/components/y-input.js +233 -0
- package/dist/components/y-menu.d.ts +26 -0
- package/dist/components/y-menu.js +322 -0
- package/dist/components/y-panel.d.ts +23 -0
- package/dist/components/y-panel.js +366 -0
- package/dist/components/y-panelbar.d.ts +3 -0
- package/dist/components/y-panelbar.js +27 -0
- package/dist/components/y-progress.d.ts +38 -0
- package/dist/components/y-progress.js +328 -0
- package/dist/components/y-radio.d.ts +16 -0
- package/dist/components/y-radio.js +202 -0
- package/dist/components/y-select.d.ts +33 -0
- package/dist/components/y-select.js +524 -0
- package/dist/components/y-slider.d.ts +34 -0
- package/dist/components/y-slider.js +387 -0
- package/dist/components/y-switch.d.ts +24 -0
- package/dist/components/y-switch.js +373 -0
- package/dist/components/y-table.d.ts +25 -0
- package/dist/components/y-table.js +327 -0
- package/dist/components/y-tabs.d.ts +21 -0
- package/dist/components/y-tabs.js +286 -0
- package/dist/components/y-tag.d.ts +7 -0
- package/dist/components/y-tag.js +218 -0
- package/dist/components/y-theme.d.ts +10 -0
- package/dist/components/y-theme.js +115 -0
- package/dist/components/y-toast.d.ts +33 -0
- package/dist/components/y-toast.js +248 -0
- package/dist/components/y-tooltip.d.ts +25 -0
- package/dist/components/y-tooltip.js +228 -0
- package/dist/icons/all.d.ts +1 -0
- package/dist/icons/all.js +208 -0
- package/dist/icons/index.d.ts +19 -0
- package/dist/icons/registry.d.ts +3 -0
- package/dist/icons/registry.js +30 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.iife.d.ts +1 -0
- package/dist/index.js +7137 -0
- package/dist/modules/helpers.d.ts +44 -0
- package/dist/modules/helpers.js +124 -0
- package/dist/react.d.ts +214 -0
- package/dist/styles/blue-dark.css +138 -0
- package/dist/styles/blue-light.css +138 -0
- package/dist/styles/orange-dark.css +138 -0
- package/dist/styles/orange-light.css +138 -0
- package/dist/styles/style.css +8 -0
- package/dist/styles/variables.css +594 -0
- package/dist/yumekit.min.js +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/* ================================================================== */
|
|
2
|
+
/* Centralized SVG icon strings for the YumeKit component library. */
|
|
3
|
+
/* */
|
|
4
|
+
/* Each static icon also lives in its own .svg file in this directory */
|
|
5
|
+
/* so it can be used standalone (e.g. <img src="…">, CSS background, */
|
|
6
|
+
/* design tools, etc.). The strings below mirror those files — keep */
|
|
7
|
+
/* them in sync when editing an icon. */
|
|
8
|
+
/* ================================================================== */
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Dual-arrow sort indicator for table headers.
|
|
13
|
+
* @param {string} topColor – fill for the up-arrow triangle.
|
|
14
|
+
* @param {string} bottomColor – fill for the down-arrow triangle.
|
|
15
|
+
*/
|
|
16
|
+
function sortArrows(topColor, bottomColor) {
|
|
17
|
+
return `<svg class="sort-icon" xmlns="http://www.w3.org/2000/svg" width="12" height="16" viewBox="0 0 12 16" aria-hidden="true">
|
|
18
|
+
<path d="M6 1 L11 7 L1 7 Z" fill="${topColor}"/>
|
|
19
|
+
<path d="M6 15 L11 9 L1 9 Z" fill="${bottomColor}"/>
|
|
20
|
+
</svg>`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
class YumeTable extends HTMLElement {
|
|
24
|
+
static get observedAttributes() {
|
|
25
|
+
return ["columns", "data", "striped", "size"];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
constructor() {
|
|
29
|
+
super();
|
|
30
|
+
this.attachShadow({ mode: "open" });
|
|
31
|
+
this._sortField = null;
|
|
32
|
+
this._sortDir = "none"; // "none" | "asc" | "desc"
|
|
33
|
+
this._parsedData = [];
|
|
34
|
+
this._parsedColumns = [];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
connectedCallback() {
|
|
38
|
+
this._parseAttributes();
|
|
39
|
+
this.render();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
attributeChangedCallback(name, oldVal, newVal) {
|
|
43
|
+
if (oldVal === newVal) return;
|
|
44
|
+
this._parseAttributes();
|
|
45
|
+
this.render();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get columns() {
|
|
49
|
+
return this.getAttribute("columns");
|
|
50
|
+
}
|
|
51
|
+
set columns(val) {
|
|
52
|
+
this.setAttribute(
|
|
53
|
+
"columns",
|
|
54
|
+
typeof val === "string" ? val : JSON.stringify(val),
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get data() {
|
|
59
|
+
return this.getAttribute("data");
|
|
60
|
+
}
|
|
61
|
+
set data(val) {
|
|
62
|
+
this.setAttribute(
|
|
63
|
+
"data",
|
|
64
|
+
typeof val === "string" ? val : JSON.stringify(val),
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get striped() {
|
|
69
|
+
return this.hasAttribute("striped");
|
|
70
|
+
}
|
|
71
|
+
set striped(val) {
|
|
72
|
+
if (val) this.setAttribute("striped", "");
|
|
73
|
+
else this.removeAttribute("striped");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Cell padding size: "small" | "medium" | "large" (default "medium").
|
|
78
|
+
*/
|
|
79
|
+
get size() {
|
|
80
|
+
return this.getAttribute("size") || "medium";
|
|
81
|
+
}
|
|
82
|
+
set size(val) {
|
|
83
|
+
this.setAttribute("size", val);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
_parseAttributes() {
|
|
87
|
+
try {
|
|
88
|
+
this._parsedColumns = JSON.parse(this.columns || "[]");
|
|
89
|
+
} catch {
|
|
90
|
+
this._parsedColumns = [];
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
this._parsedData = JSON.parse(this.data || "[]");
|
|
94
|
+
} catch {
|
|
95
|
+
this._parsedData = [];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
_onHeaderClick(field) {
|
|
100
|
+
if (this._sortField === field) {
|
|
101
|
+
this._sortDir =
|
|
102
|
+
this._sortDir === "asc"
|
|
103
|
+
? "desc"
|
|
104
|
+
: this._sortDir === "desc"
|
|
105
|
+
? "none"
|
|
106
|
+
: "asc";
|
|
107
|
+
if (this._sortDir === "none") this._sortField = null;
|
|
108
|
+
} else {
|
|
109
|
+
this._sortField = field;
|
|
110
|
+
this._sortDir = "asc";
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
this.dispatchEvent(
|
|
114
|
+
new CustomEvent("sort", {
|
|
115
|
+
detail: { field: this._sortField, direction: this._sortDir },
|
|
116
|
+
bubbles: true,
|
|
117
|
+
composed: true,
|
|
118
|
+
}),
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
this.render();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
_getSortedData() {
|
|
125
|
+
const data = [...this._parsedData];
|
|
126
|
+
if (!this._sortField || this._sortDir === "none") return data;
|
|
127
|
+
|
|
128
|
+
const dir = this._sortDir === "asc" ? 1 : -1;
|
|
129
|
+
const field = this._sortField;
|
|
130
|
+
|
|
131
|
+
return data.sort((a, b) => {
|
|
132
|
+
const aVal = a[field];
|
|
133
|
+
const bVal = b[field];
|
|
134
|
+
|
|
135
|
+
if (aVal == null && bVal == null) return 0;
|
|
136
|
+
if (aVal == null) return 1;
|
|
137
|
+
if (bVal == null) return -1;
|
|
138
|
+
|
|
139
|
+
if (typeof aVal === "number" && typeof bVal === "number") {
|
|
140
|
+
return (aVal - bVal) * dir;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return String(aVal).localeCompare(String(bVal)) * dir;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
_sortIcon(field) {
|
|
148
|
+
const active = this._sortField === field;
|
|
149
|
+
const dir = active ? this._sortDir : "none";
|
|
150
|
+
|
|
151
|
+
const topColor =
|
|
152
|
+
dir === "asc"
|
|
153
|
+
? "var(--component-table-color, #f7f7fa)"
|
|
154
|
+
: "var(--component-table-color-light, #acaeb2)";
|
|
155
|
+
const bottomColor =
|
|
156
|
+
dir === "desc"
|
|
157
|
+
? "var(--component-table-color, #f7f7fa)"
|
|
158
|
+
: "var(--component-table-color-light, #acaeb2)";
|
|
159
|
+
|
|
160
|
+
return sortArrows(topColor, bottomColor);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
render() {
|
|
164
|
+
const columns = this._parsedColumns;
|
|
165
|
+
const rows = this._getSortedData();
|
|
166
|
+
const size = this.size;
|
|
167
|
+
const striped = this.striped;
|
|
168
|
+
|
|
169
|
+
const paddingVar = `var(--component-table-padding-${size}, 8px)`;
|
|
170
|
+
|
|
171
|
+
this.shadowRoot.innerHTML = "";
|
|
172
|
+
|
|
173
|
+
const style = document.createElement("style");
|
|
174
|
+
style.textContent = `
|
|
175
|
+
:host {
|
|
176
|
+
display: block;
|
|
177
|
+
font-family: var(--font-family-body, sans-serif);
|
|
178
|
+
color: var(--component-table-color, #f7f7fa);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.table-wrapper {
|
|
182
|
+
overflow-x: auto;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
table {
|
|
186
|
+
width: 100%;
|
|
187
|
+
border-collapse: collapse;
|
|
188
|
+
table-layout: auto;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
thead th {
|
|
192
|
+
position: relative;
|
|
193
|
+
padding: ${paddingVar};
|
|
194
|
+
text-align: left;
|
|
195
|
+
font-weight: 500;
|
|
196
|
+
font-size: var(--font-size-paragraph, 1em);
|
|
197
|
+
white-space: nowrap;
|
|
198
|
+
background: transparent;
|
|
199
|
+
border-bottom: var(--component-table-border-width-header, 2px) solid var(--component-table-border-color, #37383a);
|
|
200
|
+
user-select: none;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
thead th.sortable {
|
|
204
|
+
cursor: pointer;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
thead th.sortable:hover {
|
|
208
|
+
background: var(--component-table-hover-background, #292a2b);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.th-content {
|
|
212
|
+
display: inline-flex;
|
|
213
|
+
align-items: center;
|
|
214
|
+
gap: 6px;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.sort-icon {
|
|
218
|
+
flex-shrink: 0;
|
|
219
|
+
vertical-align: middle;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
tbody td {
|
|
223
|
+
padding: ${paddingVar};
|
|
224
|
+
font-size: var(--font-size-paragraph, 1em);
|
|
225
|
+
border-bottom: var(--component-table-border-width, 2px) solid var(--component-table-border-color, #37383a);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
tbody tr:last-child td {
|
|
229
|
+
border-bottom: none;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
tbody td.row-header {
|
|
233
|
+
font-weight: 500;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
${
|
|
237
|
+
striped
|
|
238
|
+
? `tbody tr:nth-child(even) {
|
|
239
|
+
background: var(--component-table-hover-background, #292a2b);
|
|
240
|
+
}`
|
|
241
|
+
: ""
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
tbody tr:hover {
|
|
245
|
+
background: var(--component-table-active-background, #46474a);
|
|
246
|
+
}
|
|
247
|
+
`;
|
|
248
|
+
this.shadowRoot.appendChild(style);
|
|
249
|
+
|
|
250
|
+
const wrapper = document.createElement("div");
|
|
251
|
+
wrapper.className = "table-wrapper";
|
|
252
|
+
|
|
253
|
+
const table = document.createElement("table");
|
|
254
|
+
table.setAttribute("role", "grid");
|
|
255
|
+
table.setAttribute("part", "table");
|
|
256
|
+
|
|
257
|
+
const thead = document.createElement("thead");
|
|
258
|
+
thead.setAttribute("part", "header");
|
|
259
|
+
const headerRow = document.createElement("tr");
|
|
260
|
+
|
|
261
|
+
columns.forEach((col) => {
|
|
262
|
+
const th = document.createElement("th");
|
|
263
|
+
th.setAttribute("scope", "col");
|
|
264
|
+
|
|
265
|
+
const sortable = col.sortable !== false;
|
|
266
|
+
if (sortable) {
|
|
267
|
+
th.classList.add("sortable");
|
|
268
|
+
th.setAttribute(
|
|
269
|
+
"aria-sort",
|
|
270
|
+
this._sortField === col.field
|
|
271
|
+
? this._sortDir === "asc"
|
|
272
|
+
? "ascending"
|
|
273
|
+
: this._sortDir === "desc"
|
|
274
|
+
? "descending"
|
|
275
|
+
: "none"
|
|
276
|
+
: "none",
|
|
277
|
+
);
|
|
278
|
+
th.addEventListener("click", () =>
|
|
279
|
+
this._onHeaderClick(col.field),
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const inner = document.createElement("span");
|
|
284
|
+
inner.className = "th-content";
|
|
285
|
+
inner.textContent = col.header || col.field;
|
|
286
|
+
|
|
287
|
+
if (sortable) {
|
|
288
|
+
const iconSpan = document.createElement("span");
|
|
289
|
+
iconSpan.innerHTML = this._sortIcon(col.field);
|
|
290
|
+
inner.appendChild(iconSpan);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
th.appendChild(inner);
|
|
294
|
+
headerRow.appendChild(th);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
thead.appendChild(headerRow);
|
|
298
|
+
table.appendChild(thead);
|
|
299
|
+
|
|
300
|
+
const tbody = document.createElement("tbody");
|
|
301
|
+
|
|
302
|
+
rows.forEach((row) => {
|
|
303
|
+
const tr = document.createElement("tr");
|
|
304
|
+
tr.setAttribute("part", "row");
|
|
305
|
+
columns.forEach((col, colIdx) => {
|
|
306
|
+
const td = document.createElement("td");
|
|
307
|
+
td.setAttribute("part", "cell");
|
|
308
|
+
if (col.rowHeader || colIdx === 0) {
|
|
309
|
+
td.classList.add("row-header");
|
|
310
|
+
}
|
|
311
|
+
td.textContent = row[col.field] ?? "";
|
|
312
|
+
tr.appendChild(td);
|
|
313
|
+
});
|
|
314
|
+
tbody.appendChild(tr);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
table.appendChild(tbody);
|
|
318
|
+
wrapper.appendChild(table);
|
|
319
|
+
this.shadowRoot.appendChild(wrapper);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (!customElements.get("y-table")) {
|
|
324
|
+
customElements.define("y-table", YumeTable);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export { YumeTable };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export class YumeTabs extends HTMLElement {
|
|
2
|
+
static get observedAttributes(): string[];
|
|
3
|
+
_activeTab: string;
|
|
4
|
+
connectedCallback(): void;
|
|
5
|
+
attributeChangedCallback(name: any, oldVal: any, newVal: any): void;
|
|
6
|
+
set options(val: any);
|
|
7
|
+
get options(): any;
|
|
8
|
+
set size(val: string);
|
|
9
|
+
get size(): string;
|
|
10
|
+
set position(val: string);
|
|
11
|
+
get position(): string;
|
|
12
|
+
activateTab(id: any): void;
|
|
13
|
+
_setupEvents(): void;
|
|
14
|
+
_handleTabKeydown(e: any, buttons: any): void;
|
|
15
|
+
_findSiblingButton(buttons: any, fromIndex: any, direction: any): any;
|
|
16
|
+
_resolveActiveTab(tabs: any): void;
|
|
17
|
+
_getStyles(): string;
|
|
18
|
+
_createTabButton(tab: any): HTMLButtonElement;
|
|
19
|
+
_createPanel(slotName: any): HTMLDivElement;
|
|
20
|
+
render(): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
class YumeTabs extends HTMLElement {
|
|
2
|
+
static get observedAttributes() {
|
|
3
|
+
return ["options", "size", "position"];
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
this.attachShadow({ mode: "open" });
|
|
9
|
+
this._activeTab = "";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
connectedCallback() {
|
|
13
|
+
if (!this.hasAttribute("size")) this.setAttribute("size", "medium");
|
|
14
|
+
if (!this.hasAttribute("position"))
|
|
15
|
+
this.setAttribute("position", "top");
|
|
16
|
+
this.render();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
attributeChangedCallback(name, oldVal, newVal) {
|
|
20
|
+
if (
|
|
21
|
+
(name === "options" || name === "size" || name === "position") &&
|
|
22
|
+
oldVal !== newVal
|
|
23
|
+
) {
|
|
24
|
+
this.render();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get options() {
|
|
29
|
+
try {
|
|
30
|
+
return JSON.parse(this.getAttribute("options") || "[]");
|
|
31
|
+
} catch {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
set options(val) {
|
|
37
|
+
this.setAttribute("options", JSON.stringify(val));
|
|
38
|
+
this.render();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get size() {
|
|
42
|
+
const sz = this.getAttribute("size");
|
|
43
|
+
return ["small", "medium", "large"].includes(sz) ? sz : "medium";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
set size(val) {
|
|
47
|
+
if (["small", "medium", "large"].includes(val))
|
|
48
|
+
this.setAttribute("size", val);
|
|
49
|
+
else this.setAttribute("size", "medium");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
get position() {
|
|
53
|
+
const pos = this.getAttribute("position");
|
|
54
|
+
return ["top", "bottom", "left", "right"].includes(pos) ? pos : "top";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
set position(val) {
|
|
58
|
+
if (["top", "bottom", "left", "right"].includes(val))
|
|
59
|
+
this.setAttribute("position", val);
|
|
60
|
+
else this.setAttribute("position", "top");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
activateTab(id) {
|
|
64
|
+
const tab = this.options.find((t) => t.id === id);
|
|
65
|
+
if (!tab || tab.disabled) return;
|
|
66
|
+
if (this._activeTab === id) return;
|
|
67
|
+
this._activeTab = id;
|
|
68
|
+
this.render();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
_setupEvents() {
|
|
72
|
+
const buttons = Array.from(this.shadowRoot.querySelectorAll("button"));
|
|
73
|
+
buttons.forEach((button) => {
|
|
74
|
+
if (button.disabled) return;
|
|
75
|
+
button.addEventListener("click", () =>
|
|
76
|
+
this.activateTab(button.dataset.id),
|
|
77
|
+
);
|
|
78
|
+
button.addEventListener("keydown", (e) => {
|
|
79
|
+
this._handleTabKeydown(e, buttons);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
_handleTabKeydown(e, buttons) {
|
|
85
|
+
const idx = buttons.indexOf(e.currentTarget);
|
|
86
|
+
if (e.key === "ArrowRight") {
|
|
87
|
+
e.preventDefault();
|
|
88
|
+
this._findSiblingButton(buttons, idx, 1)?.focus();
|
|
89
|
+
} else if (e.key === "ArrowLeft") {
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
this._findSiblingButton(buttons, idx, -1)?.focus();
|
|
92
|
+
} else if (e.key === "Enter" || e.key === " ") {
|
|
93
|
+
e.preventDefault();
|
|
94
|
+
this.activateTab(e.currentTarget.dataset.id);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
_findSiblingButton(buttons, fromIndex, direction) {
|
|
99
|
+
for (let i = 1; i <= buttons.length; i++) {
|
|
100
|
+
const b =
|
|
101
|
+
buttons[
|
|
102
|
+
(fromIndex + i * direction + buttons.length) %
|
|
103
|
+
buttons.length
|
|
104
|
+
];
|
|
105
|
+
if (!b.disabled) return b;
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
_resolveActiveTab(tabs) {
|
|
111
|
+
const currentInvalid =
|
|
112
|
+
!this._activeTab ||
|
|
113
|
+
tabs.find((t) => t.id === this._activeTab)?.disabled;
|
|
114
|
+
if (tabs.length && currentInvalid) {
|
|
115
|
+
this._activeTab = tabs.find((t) => !t.disabled)?.id || "";
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
_getStyles() {
|
|
120
|
+
const paddingVar = `var(--component-tab-padding-${this.size})`;
|
|
121
|
+
const gapVar = `var(--component-tab-gap-${this.size})`;
|
|
122
|
+
return `
|
|
123
|
+
:host {
|
|
124
|
+
display: flex;
|
|
125
|
+
font-family: var(--component-tabs-font-family, var(--font-family-body));
|
|
126
|
+
}
|
|
127
|
+
:host([position="top"]) { flex-direction: column; }
|
|
128
|
+
:host([position="bottom"]) { flex-direction: column-reverse; }
|
|
129
|
+
:host([position="left"]) { flex-direction: row; }
|
|
130
|
+
:host([position="right"]) { flex-direction: row-reverse; }
|
|
131
|
+
|
|
132
|
+
.tablist {
|
|
133
|
+
display: flex;
|
|
134
|
+
gap: 0;
|
|
135
|
+
position: relative;
|
|
136
|
+
z-index: 1;
|
|
137
|
+
}
|
|
138
|
+
:host([position="top"]) .tablist { margin-bottom: -1px; margin-top: 0; }
|
|
139
|
+
:host([position="bottom"]) .tablist { margin-top: -1px; margin-bottom: 0; }
|
|
140
|
+
:host([position="left"]) .tablist { flex-direction: column; margin-right: -1px; margin-left: 0; }
|
|
141
|
+
:host([position="right"]) .tablist { flex-direction: column; margin-left: -1px; margin-right: 0; }
|
|
142
|
+
|
|
143
|
+
:host([position="top"]) .tablist button { border-bottom: none; }
|
|
144
|
+
:host([position="bottom"]) .tablist button { border-top: none; }
|
|
145
|
+
:host([position="left"]) .tablist button { border-right: none; }
|
|
146
|
+
:host([position="right"]) .tablist button { border-left: none; }
|
|
147
|
+
|
|
148
|
+
button {
|
|
149
|
+
background: var(--component-tabs-border-color);
|
|
150
|
+
color: var(--component-tabs-color);
|
|
151
|
+
border: var(--component-tab-border-width) solid var(--component-tabs-border-color);
|
|
152
|
+
margin: 0;
|
|
153
|
+
padding: ${paddingVar};
|
|
154
|
+
cursor: pointer;
|
|
155
|
+
font-size: var(--font-size-label);
|
|
156
|
+
display: inline-flex;
|
|
157
|
+
align-items: center;
|
|
158
|
+
gap: ${gapVar};
|
|
159
|
+
transition: background 0.2s ease;
|
|
160
|
+
outline: none;
|
|
161
|
+
font-family: inherit;
|
|
162
|
+
}
|
|
163
|
+
:host([position="top"]) .tablist button:first-child { border-top-left-radius: var(--component-tab-border-radius-outer); }
|
|
164
|
+
:host([position="top"]) .tablist button:last-child { border-top-right-radius: var(--component-tab-border-radius-outer); }
|
|
165
|
+
:host([position="bottom"]) .tablist button:first-child { border-bottom-left-radius: var(--component-tab-border-radius-outer); }
|
|
166
|
+
:host([position="bottom"]) .tablist button:last-child { border-bottom-right-radius: var(--component-tab-border-radius-outer); }
|
|
167
|
+
:host([position="left"]) .tablist button:first-child { border-top-left-radius: var(--component-tab-border-radius-outer); }
|
|
168
|
+
:host([position="left"]) .tablist button:last-child { border-bottom-left-radius: var(--component-tab-border-radius-outer); }
|
|
169
|
+
:host([position="right"]) .tablist button:first-child { border-top-right-radius: var(--component-tab-border-radius-outer); }
|
|
170
|
+
:host([position="right"]) .tablist button:last-child { border-bottom-right-radius: var(--component-tab-border-radius-outer); }
|
|
171
|
+
|
|
172
|
+
button[aria-selected="true"] {
|
|
173
|
+
background: var(--component-tabs-background);
|
|
174
|
+
}
|
|
175
|
+
button:focus-visible {
|
|
176
|
+
outline: 2px solid var(--component-tabs-accent);
|
|
177
|
+
outline-offset: -1px;
|
|
178
|
+
}
|
|
179
|
+
button[disabled] {
|
|
180
|
+
opacity: 0.5;
|
|
181
|
+
cursor: not-allowed;
|
|
182
|
+
}
|
|
183
|
+
.icon-slot {
|
|
184
|
+
display: inline-flex;
|
|
185
|
+
align-items: center;
|
|
186
|
+
margin: 0 4px;
|
|
187
|
+
}
|
|
188
|
+
.tabpanel {
|
|
189
|
+
position: relative;
|
|
190
|
+
z-index: 0;
|
|
191
|
+
border: var(--component-tab-border-width) solid var(--component-tabs-border-color);
|
|
192
|
+
border-radius: var(--component-tab-border-radius-outer);
|
|
193
|
+
padding: var(--component-tab-content-padding);
|
|
194
|
+
background: var(--component-tabs-background);
|
|
195
|
+
}
|
|
196
|
+
:host([position="top"]) .tabpanel { border-top-left-radius: 0; }
|
|
197
|
+
:host([position="bottom"]) .tabpanel { border-bottom-left-radius: 0; }
|
|
198
|
+
:host([position="left"]) .tabpanel { border-top-left-radius: 0; }
|
|
199
|
+
:host([position="right"]) .tabpanel { border-top-right-radius: 0; }
|
|
200
|
+
:host([position="top"]) .tabpanel { margin-top: -1px; }
|
|
201
|
+
:host([position="bottom"]) .tabpanel { margin-bottom: -1px; }
|
|
202
|
+
:host([position="left"]) .tabpanel { margin-left: -1px; }
|
|
203
|
+
:host([position="right"]) .tabpanel { margin-right: -1px; }
|
|
204
|
+
`;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
_createTabButton(tab) {
|
|
208
|
+
const isActive = tab.id === this._activeTab;
|
|
209
|
+
const isDisabled = !!tab.disabled;
|
|
210
|
+
const btn = document.createElement("button");
|
|
211
|
+
btn.id = `tab-${tab.id}`;
|
|
212
|
+
btn.setAttribute("role", "tab");
|
|
213
|
+
btn.setAttribute("part", "tab");
|
|
214
|
+
btn.setAttribute("aria-selected", isActive);
|
|
215
|
+
btn.setAttribute("aria-controls", `panel-${tab.id}`);
|
|
216
|
+
btn.setAttribute("aria-disabled", isDisabled);
|
|
217
|
+
|
|
218
|
+
if (isDisabled) btn.disabled = true;
|
|
219
|
+
btn.tabIndex = isActive && !isDisabled ? 0 : -1;
|
|
220
|
+
btn.dataset.id = tab.id;
|
|
221
|
+
|
|
222
|
+
if (this.querySelector(`[slot="left-icon-${tab.id}"]`)) {
|
|
223
|
+
const leftSlot = document.createElement("slot");
|
|
224
|
+
leftSlot.name = `left-icon-${tab.id}`;
|
|
225
|
+
leftSlot.className = "icon-slot";
|
|
226
|
+
btn.appendChild(leftSlot);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const labelSpan = document.createElement("span");
|
|
230
|
+
labelSpan.textContent = tab.label;
|
|
231
|
+
btn.appendChild(labelSpan);
|
|
232
|
+
|
|
233
|
+
if (this.querySelector(`[slot="right-icon-${tab.id}"]`)) {
|
|
234
|
+
const rightSlot = document.createElement("slot");
|
|
235
|
+
rightSlot.name = `right-icon-${tab.id}`;
|
|
236
|
+
rightSlot.className = "icon-slot";
|
|
237
|
+
btn.appendChild(rightSlot);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return btn;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
_createPanel(slotName) {
|
|
244
|
+
const panel = document.createElement("div");
|
|
245
|
+
panel.className = "tabpanel";
|
|
246
|
+
panel.id = `panel-${this._activeTab}`;
|
|
247
|
+
panel.setAttribute("role", "tabpanel");
|
|
248
|
+
panel.setAttribute("part", "content");
|
|
249
|
+
panel.setAttribute("aria-labelledby", `tab-${this._activeTab}`);
|
|
250
|
+
|
|
251
|
+
const contentSlot = document.createElement("slot");
|
|
252
|
+
contentSlot.name = slotName;
|
|
253
|
+
panel.appendChild(contentSlot);
|
|
254
|
+
return panel;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
render() {
|
|
258
|
+
const tabs = this.options;
|
|
259
|
+
this._resolveActiveTab(tabs);
|
|
260
|
+
|
|
261
|
+
const activeDef = tabs.find((t) => t.id === this._activeTab);
|
|
262
|
+
|
|
263
|
+
this.shadowRoot.innerHTML = "";
|
|
264
|
+
|
|
265
|
+
const style = document.createElement("style");
|
|
266
|
+
style.textContent = this._getStyles();
|
|
267
|
+
this.shadowRoot.appendChild(style);
|
|
268
|
+
|
|
269
|
+
const tablist = document.createElement("div");
|
|
270
|
+
tablist.className = "tablist";
|
|
271
|
+
tablist.setAttribute("role", "tablist");
|
|
272
|
+
tablist.setAttribute("part", "tablist");
|
|
273
|
+
tabs.forEach((tab) => tablist.appendChild(this._createTabButton(tab)));
|
|
274
|
+
this.shadowRoot.appendChild(tablist);
|
|
275
|
+
|
|
276
|
+
this.shadowRoot.appendChild(this._createPanel(activeDef?.slot || ""));
|
|
277
|
+
|
|
278
|
+
this._setupEvents();
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (!customElements.get("y-tabs")) {
|
|
283
|
+
customElements.define("y-tabs", YumeTabs);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export { YumeTabs };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export class YumeTag extends HTMLElement {
|
|
2
|
+
static get observedAttributes(): string[];
|
|
3
|
+
connectedCallback(): void;
|
|
4
|
+
attributeChangedCallback(name: any, oldValue: any, newValue: any): void;
|
|
5
|
+
render(): void;
|
|
6
|
+
getStyle(color: any, styleType: any, shape: any, size: any): string;
|
|
7
|
+
}
|