@sondor-technology/sondor-components 1.0.0 → 1.0.1-develop.2
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/README.md +8 -0
- package/dist/components/alert/alert.d.ts +13 -0
- package/dist/components/alert/alert.d.ts.map +1 -0
- package/dist/components/alert/alert.js +105 -0
- package/dist/components/badge/badge.d.ts +13 -0
- package/dist/components/badge/badge.d.ts.map +1 -0
- package/dist/components/badge/badge.js +101 -0
- package/dist/components/breadcrumb/breadcrumb.d.ts +19 -0
- package/dist/components/breadcrumb/breadcrumb.d.ts.map +1 -0
- package/dist/components/breadcrumb/breadcrumb.js +99 -0
- package/dist/components/button/button.d.ts +23 -0
- package/dist/components/button/button.d.ts.map +1 -0
- package/dist/components/button/button.js +304 -0
- package/dist/components/button-group/button-group.d.ts +6 -0
- package/dist/components/button-group/button-group.d.ts.map +1 -0
- package/dist/components/button-group/button-group.js +74 -0
- package/dist/components/card/card.d.ts +11 -0
- package/dist/components/card/card.d.ts.map +1 -0
- package/dist/components/card/card.js +54 -0
- package/dist/components/checkbox/checkbox.d.ts +28 -0
- package/dist/components/checkbox/checkbox.d.ts.map +1 -0
- package/dist/components/checkbox/checkbox.js +247 -0
- package/dist/components/code-block/code-block.d.ts +20 -0
- package/dist/components/code-block/code-block.d.ts.map +1 -0
- package/dist/components/code-block/code-block.js +260 -0
- package/dist/components/content-card/content-card.d.ts +13 -0
- package/dist/components/content-card/content-card.d.ts.map +1 -0
- package/dist/components/content-card/content-card.js +140 -0
- package/dist/components/divider/divider.d.ts +16 -0
- package/dist/components/divider/divider.d.ts.map +1 -0
- package/dist/components/divider/divider.js +82 -0
- package/dist/components/drawer/drawer.d.ts +22 -0
- package/dist/components/drawer/drawer.d.ts.map +1 -0
- package/dist/components/drawer/drawer.js +226 -0
- package/dist/components/field/field.d.ts +11 -0
- package/dist/components/field/field.d.ts.map +1 -0
- package/dist/components/field/field.js +32 -0
- package/dist/components/footer/footer.d.ts +6 -0
- package/dist/components/footer/footer.d.ts.map +1 -0
- package/dist/components/footer/footer.js +65 -0
- package/dist/components/form/form-step.d.ts +13 -0
- package/dist/components/form/form-step.d.ts.map +1 -0
- package/dist/components/form/form-step.js +41 -0
- package/dist/components/form/form.d.ts +25 -0
- package/dist/components/form/form.d.ts.map +1 -0
- package/dist/components/form/form.js +358 -0
- package/dist/components/grid/grid-row.d.ts +17 -0
- package/dist/components/grid/grid-row.d.ts.map +1 -0
- package/dist/components/grid/grid-row.js +92 -0
- package/dist/components/grid/grid.d.ts +13 -0
- package/dist/components/grid/grid.d.ts.map +1 -0
- package/dist/components/grid/grid.js +42 -0
- package/dist/components/icon/icon-paths.d.ts +116 -0
- package/dist/components/icon/icon-paths.d.ts.map +1 -0
- package/dist/components/icon/icon-paths.js +121 -0
- package/dist/components/icon/icon.d.ts +16 -0
- package/dist/components/icon/icon.d.ts.map +1 -0
- package/dist/components/icon/icon.js +95 -0
- package/dist/components/input/input.d.ts +31 -0
- package/dist/components/input/input.d.ts.map +1 -0
- package/dist/components/input/input.js +268 -0
- package/dist/components/link/link.d.ts +16 -0
- package/dist/components/link/link.d.ts.map +1 -0
- package/dist/components/link/link.js +116 -0
- package/dist/components/metadata/metadata.d.ts +18 -0
- package/dist/components/metadata/metadata.d.ts.map +1 -0
- package/dist/components/metadata/metadata.js +71 -0
- package/dist/components/modal/modal.d.ts +24 -0
- package/dist/components/modal/modal.d.ts.map +1 -0
- package/dist/components/modal/modal.js +163 -0
- package/dist/components/page-layout/page-layout.d.ts +46 -0
- package/dist/components/page-layout/page-layout.d.ts.map +1 -0
- package/dist/components/page-layout/page-layout.js +697 -0
- package/dist/components/radio/radio.d.ts +16 -0
- package/dist/components/radio/radio.d.ts.map +1 -0
- package/dist/components/radio/radio.js +152 -0
- package/dist/components/radio-group/radio-group.d.ts +27 -0
- package/dist/components/radio-group/radio-group.d.ts.map +1 -0
- package/dist/components/radio-group/radio-group.js +161 -0
- package/dist/components/router/router.d.ts +7 -0
- package/dist/components/router/router.d.ts.map +1 -0
- package/dist/components/router/router.js +37 -0
- package/dist/components/select/select.d.ts +16 -0
- package/dist/components/select/select.d.ts.map +1 -0
- package/dist/components/select/select.js +172 -0
- package/dist/components/skeleton/skeleton.d.ts +17 -0
- package/dist/components/skeleton/skeleton.d.ts.map +1 -0
- package/dist/components/skeleton/skeleton.js +78 -0
- package/dist/components/switch/switch.d.ts +25 -0
- package/dist/components/switch/switch.d.ts.map +1 -0
- package/dist/components/switch/switch.js +185 -0
- package/dist/components/table/data-table.d.ts +72 -0
- package/dist/components/table/data-table.d.ts.map +1 -0
- package/dist/components/table/data-table.js +551 -0
- package/dist/components/table/table.d.ts +22 -0
- package/dist/components/table/table.d.ts.map +1 -0
- package/dist/components/table/table.js +167 -0
- package/dist/components/tabs/tab-panel.d.ts +8 -0
- package/dist/components/tabs/tab-panel.d.ts.map +1 -0
- package/dist/components/tabs/tab-panel.js +46 -0
- package/dist/components/tabs/tab.d.ts +9 -0
- package/dist/components/tabs/tab.d.ts.map +1 -0
- package/dist/components/tabs/tab.js +91 -0
- package/dist/components/tabs/tabs.d.ts +14 -0
- package/dist/components/tabs/tabs.d.ts.map +1 -0
- package/dist/components/tabs/tabs.js +85 -0
- package/dist/components/textarea/textarea.d.ts +36 -0
- package/dist/components/textarea/textarea.d.ts.map +1 -0
- package/dist/components/textarea/textarea.js +231 -0
- package/dist/components/theme-toggle/theme-toggle.d.ts +15 -0
- package/dist/components/theme-toggle/theme-toggle.d.ts.map +1 -0
- package/dist/components/theme-toggle/theme-toggle.js +130 -0
- package/dist/components/vertical-nav/vertical-nav-group.d.ts +9 -0
- package/dist/components/vertical-nav/vertical-nav-group.d.ts.map +1 -0
- package/dist/components/vertical-nav/vertical-nav-group.js +111 -0
- package/dist/components/vertical-nav/vertical-nav-item.d.ts +8 -0
- package/dist/components/vertical-nav/vertical-nav-item.d.ts.map +1 -0
- package/dist/components/vertical-nav/vertical-nav-item.js +65 -0
- package/dist/styles/index.css +171 -0
- package/dist/styles/reset.d.ts +2 -0
- package/dist/styles/reset.d.ts.map +1 -0
- package/dist/styles/reset.js +50 -0
- package/package.json +3 -2
- package/src/components/alert/alert.ts +100 -100
- package/src/components/badge/badge.ts +96 -96
- package/src/components/breadcrumb/breadcrumb.ts +98 -98
- package/src/components/button/button.ts +281 -281
- package/src/components/button-group/button-group.ts +67 -67
- package/src/components/card/card.ts +52 -52
- package/src/components/checkbox/checkbox.ts +238 -238
- package/src/components/code-block/code-block.ts +256 -256
- package/src/components/content-card/content-card.ts +133 -133
- package/src/components/divider/divider.ts +68 -68
- package/src/components/drawer/drawer.ts +217 -217
- package/src/components/field/field.ts +30 -30
- package/src/components/footer/footer.ts +58 -58
- package/src/components/form/form-step.ts +32 -32
- package/src/components/form/form.ts +376 -376
- package/src/components/grid/grid-row.ts +75 -75
- package/src/components/grid/grid.ts +36 -36
- package/src/components/icon/icon-paths.ts +124 -124
- package/src/components/icon/icon.ts +82 -82
- package/src/components/input/input.ts +248 -248
- package/src/components/link/link.ts +97 -97
- package/src/components/metadata/metadata.ts +66 -66
- package/src/components/modal/modal.ts +158 -158
- package/src/components/page-layout/page-layout.ts +704 -704
- package/src/components/radio/radio.ts +142 -142
- package/src/components/radio-group/radio-group.ts +157 -157
- package/src/components/router/router.ts +46 -46
- package/src/components/select/select.ts +161 -161
- package/src/components/skeleton/skeleton.ts +67 -67
- package/src/components/switch/switch.ts +181 -181
- package/src/components/table/data-table.ts +556 -556
- package/src/components/table/table.ts +153 -153
- package/src/components/tabs/tab-panel.ts +30 -30
- package/src/components/tabs/tab.ts +76 -76
- package/src/components/tabs/tabs.ts +88 -88
- package/src/components/textarea/textarea.ts +215 -215
- package/src/components/theme-toggle/theme-toggle.ts +131 -131
- package/src/components/vertical-nav/vertical-nav-group.ts +96 -96
- package/src/components/vertical-nav/vertical-nav-item.ts +49 -49
- package/src/styles/globals.css +58 -58
- package/src/styles/index.css +80 -80
- package/src/styles/reset.ts +50 -50
- package/src/styles/theme.css +58 -58
- package/src/styles/typography.css +25 -25
- package/tsconfig.json +15 -15
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { LitElement, html, css } from 'lit';
|
|
8
|
+
import { customElement, property, state } from 'lit/decorators.js';
|
|
9
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
10
|
+
import { resetStyles } from '../../styles/reset.js';
|
|
11
|
+
let StDataTable = class StDataTable extends LitElement {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
/**
|
|
15
|
+
* Array defining table headers, keys, and sortability.
|
|
16
|
+
*/
|
|
17
|
+
this.columns = [];
|
|
18
|
+
/**
|
|
19
|
+
* Array of row data objects rendered in the table.
|
|
20
|
+
*/
|
|
21
|
+
this.data = [];
|
|
22
|
+
/**
|
|
23
|
+
* Total number of rows available on the server (used for pagination).
|
|
24
|
+
*/
|
|
25
|
+
this.totalRows = 0;
|
|
26
|
+
/**
|
|
27
|
+
* Current page number (1-indexed).
|
|
28
|
+
*/
|
|
29
|
+
this.page = 1;
|
|
30
|
+
/**
|
|
31
|
+
* Number of rows per page.
|
|
32
|
+
*/
|
|
33
|
+
this.pageSize = 10;
|
|
34
|
+
/**
|
|
35
|
+
* Enables holding 'Shift' to sort by multiple columns sequentially.
|
|
36
|
+
*/
|
|
37
|
+
this.multiSort = false;
|
|
38
|
+
/**
|
|
39
|
+
* Displays loading skeleton rows and locks controls.
|
|
40
|
+
*/
|
|
41
|
+
this.loading = false;
|
|
42
|
+
// --- Internal State ---
|
|
43
|
+
this.internalColumns = [];
|
|
44
|
+
this.sortState = [];
|
|
45
|
+
this.searchQuery = '';
|
|
46
|
+
this.showColumnMenu = false;
|
|
47
|
+
this.draggedColumnKey = null;
|
|
48
|
+
this.handleOutsideClick = (e) => {
|
|
49
|
+
const target = e.target;
|
|
50
|
+
if (!target.closest('.columns-toggle-wrapper')) {
|
|
51
|
+
this.showColumnMenu = false;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
willUpdate(changedProperties) {
|
|
56
|
+
if (changedProperties.has('columns') && this.columns.length > 0) {
|
|
57
|
+
if (this.internalColumns.length === 0) {
|
|
58
|
+
this.internalColumns = [...this.columns];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
firstUpdated() {
|
|
63
|
+
if (this.internalColumns.length === 0 && this.columns.length > 0) {
|
|
64
|
+
this.internalColumns = [...this.columns];
|
|
65
|
+
}
|
|
66
|
+
this.emitChange();
|
|
67
|
+
}
|
|
68
|
+
connectedCallback() {
|
|
69
|
+
super.connectedCallback();
|
|
70
|
+
document.addEventListener('click', this.handleOutsideClick);
|
|
71
|
+
}
|
|
72
|
+
disconnectedCallback() {
|
|
73
|
+
document.removeEventListener('click', this.handleOutsideClick);
|
|
74
|
+
super.disconnectedCallback();
|
|
75
|
+
}
|
|
76
|
+
emitChange() {
|
|
77
|
+
this.dispatchEvent(new CustomEvent('st-data-change', {
|
|
78
|
+
detail: {
|
|
79
|
+
page: this.page,
|
|
80
|
+
pageSize: this.pageSize,
|
|
81
|
+
search: this.searchQuery,
|
|
82
|
+
sort: this.sortState
|
|
83
|
+
},
|
|
84
|
+
bubbles: true,
|
|
85
|
+
composed: true
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
handleSearchInput(e) {
|
|
89
|
+
if (this.loading)
|
|
90
|
+
return;
|
|
91
|
+
const val = e.target.value;
|
|
92
|
+
window.clearTimeout(this.searchTimeout);
|
|
93
|
+
this.searchTimeout = window.setTimeout(() => {
|
|
94
|
+
this.searchQuery = val;
|
|
95
|
+
this.page = 1;
|
|
96
|
+
this.emitChange();
|
|
97
|
+
}, 350);
|
|
98
|
+
}
|
|
99
|
+
handleSort(key, e) {
|
|
100
|
+
if (this.loading)
|
|
101
|
+
return;
|
|
102
|
+
const isShift = e.shiftKey && this.multiSort;
|
|
103
|
+
const existingIndex = this.sortState.findIndex(s => s.key === key);
|
|
104
|
+
let newDirection = 'asc';
|
|
105
|
+
if (existingIndex !== -1) {
|
|
106
|
+
newDirection = this.sortState[existingIndex].direction === 'asc' ? 'desc' : null;
|
|
107
|
+
}
|
|
108
|
+
let newSortState = [...this.sortState];
|
|
109
|
+
if (isShift) {
|
|
110
|
+
if (newDirection) {
|
|
111
|
+
if (existingIndex !== -1) {
|
|
112
|
+
newSortState[existingIndex].direction = newDirection;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
newSortState.push({ key, direction: newDirection });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
newSortState.splice(existingIndex, 1);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
if (newDirection) {
|
|
124
|
+
newSortState = [{ key, direction: newDirection }];
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
newSortState = [];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
this.sortState = newSortState;
|
|
131
|
+
this.page = 1;
|
|
132
|
+
this.emitChange();
|
|
133
|
+
}
|
|
134
|
+
get totalPages() {
|
|
135
|
+
return Math.max(1, Math.ceil(this.totalRows / this.pageSize));
|
|
136
|
+
}
|
|
137
|
+
prevPage() {
|
|
138
|
+
if (!this.loading && this.page > 1) {
|
|
139
|
+
this.page--;
|
|
140
|
+
this.emitChange();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
nextPage() {
|
|
144
|
+
if (!this.loading && this.page < this.totalPages) {
|
|
145
|
+
this.page++;
|
|
146
|
+
this.emitChange();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
toggleColumnVisibility(key) {
|
|
150
|
+
this.internalColumns = this.internalColumns.map(col => col.key === key ? { ...col, hidden: !col.hidden } : col);
|
|
151
|
+
}
|
|
152
|
+
handleDragStart(e, key) {
|
|
153
|
+
this.draggedColumnKey = key;
|
|
154
|
+
if (e.dataTransfer) {
|
|
155
|
+
e.dataTransfer.effectAllowed = 'move';
|
|
156
|
+
e.dataTransfer.setData('text/plain', key);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
handleDragOver(e) {
|
|
160
|
+
e.preventDefault();
|
|
161
|
+
if (e.dataTransfer)
|
|
162
|
+
e.dataTransfer.dropEffect = 'move';
|
|
163
|
+
const target = e.target.closest('th');
|
|
164
|
+
if (target)
|
|
165
|
+
target.classList.add('drag-over');
|
|
166
|
+
}
|
|
167
|
+
handleDragLeave(e) {
|
|
168
|
+
const target = e.target.closest('th');
|
|
169
|
+
if (target)
|
|
170
|
+
target.classList.remove('drag-over');
|
|
171
|
+
}
|
|
172
|
+
handleDrop(e, targetKey) {
|
|
173
|
+
e.preventDefault();
|
|
174
|
+
const targetEl = e.target.closest('th');
|
|
175
|
+
if (targetEl)
|
|
176
|
+
targetEl.classList.remove('drag-over');
|
|
177
|
+
if (!this.draggedColumnKey || this.draggedColumnKey === targetKey)
|
|
178
|
+
return;
|
|
179
|
+
const newCols = [...this.internalColumns];
|
|
180
|
+
const fromIndex = newCols.findIndex(c => c.key === this.draggedColumnKey);
|
|
181
|
+
const toIndex = newCols.findIndex(c => c.key === targetKey);
|
|
182
|
+
const [movedCol] = newCols.splice(fromIndex, 1);
|
|
183
|
+
newCols.splice(toIndex, 0, movedCol);
|
|
184
|
+
this.internalColumns = newCols;
|
|
185
|
+
this.draggedColumnKey = null;
|
|
186
|
+
}
|
|
187
|
+
renderSortIcon(key) {
|
|
188
|
+
const sortIndex = this.sortState.findIndex(s => s.key === key);
|
|
189
|
+
if (sortIndex === -1) {
|
|
190
|
+
return html `<svg class="sort-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m7 15 5 5 5-5"/><path d="m7 9 5-5 5 5"/></svg>`;
|
|
191
|
+
}
|
|
192
|
+
const sortConfig = this.sortState[sortIndex];
|
|
193
|
+
const icon = sortConfig.direction === 'asc'
|
|
194
|
+
? html `<svg class="sort-icon active" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m18 15-6-6-6 6"/></svg>`
|
|
195
|
+
: html `<svg class="sort-icon active" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>`;
|
|
196
|
+
const priority = this.sortState.length > 1 && this.multiSort
|
|
197
|
+
? html `<span class="sort-priority">${sortIndex + 1}</span>`
|
|
198
|
+
: '';
|
|
199
|
+
return html `${icon}${priority}`;
|
|
200
|
+
}
|
|
201
|
+
render() {
|
|
202
|
+
const visibleColumns = this.internalColumns.filter(c => !c.hidden);
|
|
203
|
+
const skeletonRowsCount = Math.min(this.pageSize, 5);
|
|
204
|
+
return html `
|
|
205
|
+
<!-- Toolbar -->
|
|
206
|
+
<div class="toolbar">
|
|
207
|
+
<div class="search-wrapper">
|
|
208
|
+
<svg class="search-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>
|
|
209
|
+
<input
|
|
210
|
+
type="text"
|
|
211
|
+
class="search-input"
|
|
212
|
+
placeholder="Search..."
|
|
213
|
+
?disabled=${this.loading}
|
|
214
|
+
@input=${this.handleSearchInput}
|
|
215
|
+
>
|
|
216
|
+
</div>
|
|
217
|
+
|
|
218
|
+
<div class="columns-toggle-wrapper">
|
|
219
|
+
<st-button
|
|
220
|
+
variant="secondary"
|
|
221
|
+
size="sm"
|
|
222
|
+
@click=${() => this.showColumnMenu = !this.showColumnMenu}
|
|
223
|
+
>
|
|
224
|
+
Columns
|
|
225
|
+
</st-button>
|
|
226
|
+
|
|
227
|
+
${this.showColumnMenu ? html `
|
|
228
|
+
<div class="columns-menu">
|
|
229
|
+
${this.internalColumns.map(col => html `
|
|
230
|
+
<label class="column-option">
|
|
231
|
+
<input
|
|
232
|
+
type="checkbox"
|
|
233
|
+
.checked=${!col.hidden}
|
|
234
|
+
@change=${() => this.toggleColumnVisibility(col.key)}
|
|
235
|
+
>
|
|
236
|
+
${col.header}
|
|
237
|
+
</label>
|
|
238
|
+
`)}
|
|
239
|
+
</div>
|
|
240
|
+
` : ''}
|
|
241
|
+
</div>
|
|
242
|
+
</div>
|
|
243
|
+
|
|
244
|
+
<!-- Table -->
|
|
245
|
+
<div class="table-wrapper">
|
|
246
|
+
<table>
|
|
247
|
+
<thead>
|
|
248
|
+
<tr>
|
|
249
|
+
${visibleColumns.map(col => html `
|
|
250
|
+
<th
|
|
251
|
+
draggable="true"
|
|
252
|
+
@dragstart=${(e) => this.handleDragStart(e, col.key)}
|
|
253
|
+
@dragover=${this.handleDragOver}
|
|
254
|
+
@dragleave=${this.handleDragLeave}
|
|
255
|
+
@drop=${(e) => this.handleDrop(e, col.key)}
|
|
256
|
+
>
|
|
257
|
+
<div class="th-content">
|
|
258
|
+
<svg class="drag-handle" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="9" cy="12" r="1"/><circle cx="9" cy="5" r="1"/><circle cx="9" cy="19" r="1"/><circle cx="15" cy="12" r="1"/><circle cx="15" cy="5" r="1"/><circle cx="15" cy="19" r="1"/></svg>
|
|
259
|
+
|
|
260
|
+
<div
|
|
261
|
+
class=${classMap({ 'sortable-header': !!col.sortable })}
|
|
262
|
+
@click=${(e) => col.sortable && this.handleSort(col.key, e)}
|
|
263
|
+
>
|
|
264
|
+
${col.header}
|
|
265
|
+
${col.sortable ? this.renderSortIcon(col.key) : ''}
|
|
266
|
+
</div>
|
|
267
|
+
</div>
|
|
268
|
+
</th>
|
|
269
|
+
`)}
|
|
270
|
+
</tr>
|
|
271
|
+
</thead>
|
|
272
|
+
<tbody>
|
|
273
|
+
${this.loading ? html `
|
|
274
|
+
${Array.from({ length: skeletonRowsCount }).map(() => html `
|
|
275
|
+
<tr>
|
|
276
|
+
${visibleColumns.map(() => html `
|
|
277
|
+
<td><st-skeleton variant="text" width="75%"></st-skeleton></td>
|
|
278
|
+
`)}
|
|
279
|
+
</tr>
|
|
280
|
+
`)}
|
|
281
|
+
` : this.data.length === 0 ? html `
|
|
282
|
+
<tr>
|
|
283
|
+
<td colspan=${visibleColumns.length} style="text-align: center; padding: 2rem;">No results found.</td>
|
|
284
|
+
</tr>
|
|
285
|
+
` : this.data.map(row => html `
|
|
286
|
+
<tr>
|
|
287
|
+
${visibleColumns.map(col => html `
|
|
288
|
+
<td>${row[col.key]}</td>
|
|
289
|
+
`)}
|
|
290
|
+
</tr>
|
|
291
|
+
`)}
|
|
292
|
+
</tbody>
|
|
293
|
+
</table>
|
|
294
|
+
</div>
|
|
295
|
+
|
|
296
|
+
<!-- Pagination -->
|
|
297
|
+
<div class="pagination">
|
|
298
|
+
<div class="pagination-info">
|
|
299
|
+
Page ${this.page} of ${this.totalPages} (${this.totalRows} total items)
|
|
300
|
+
</div>
|
|
301
|
+
<div class="pagination-controls">
|
|
302
|
+
<st-button
|
|
303
|
+
variant="secondary"
|
|
304
|
+
size="sm"
|
|
305
|
+
?disabled=${this.loading || this.page === 1}
|
|
306
|
+
@click=${this.prevPage}
|
|
307
|
+
>
|
|
308
|
+
Prev
|
|
309
|
+
</st-button>
|
|
310
|
+
<st-button
|
|
311
|
+
variant="secondary"
|
|
312
|
+
size="sm"
|
|
313
|
+
?disabled=${this.loading || this.page === this.totalPages}
|
|
314
|
+
@click=${this.nextPage}
|
|
315
|
+
>
|
|
316
|
+
Next
|
|
317
|
+
</st-button>
|
|
318
|
+
</div>
|
|
319
|
+
</div>
|
|
320
|
+
`;
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
StDataTable.styles = [
|
|
324
|
+
resetStyles,
|
|
325
|
+
css `
|
|
326
|
+
:host {
|
|
327
|
+
display: block;
|
|
328
|
+
width: 100%;
|
|
329
|
+
font-family: var(--st-font-family, inherit);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
.toolbar {
|
|
333
|
+
display: flex;
|
|
334
|
+
justify-content: space-between;
|
|
335
|
+
align-items: center;
|
|
336
|
+
gap: var(--st-spacing-md);
|
|
337
|
+
margin-bottom: var(--st-spacing-md);
|
|
338
|
+
flex-wrap: wrap;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
.search-wrapper {
|
|
342
|
+
flex: 1;
|
|
343
|
+
min-width: 250px;
|
|
344
|
+
position: relative;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
.search-input {
|
|
348
|
+
width: 100%;
|
|
349
|
+
padding: 0.5rem 0.75rem 0.5rem 2.25rem;
|
|
350
|
+
border: 1px solid var(--st-color-border);
|
|
351
|
+
border-radius: var(--st-radius-md);
|
|
352
|
+
background-color: var(--st-color-surface);
|
|
353
|
+
color: var(--st-color-text);
|
|
354
|
+
font-size: var(--st-font-size-sm);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
.search-input:disabled {
|
|
358
|
+
opacity: 0.6;
|
|
359
|
+
cursor: not-allowed;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
.search-icon {
|
|
363
|
+
position: absolute;
|
|
364
|
+
left: 0.75rem;
|
|
365
|
+
top: 50%;
|
|
366
|
+
transform: translateY(-50%);
|
|
367
|
+
width: 1rem;
|
|
368
|
+
height: 1rem;
|
|
369
|
+
color: var(--st-color-text-muted);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
.columns-toggle-wrapper {
|
|
373
|
+
position: relative;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
.columns-menu {
|
|
377
|
+
position: absolute;
|
|
378
|
+
top: calc(100% + 0.5rem);
|
|
379
|
+
right: 0;
|
|
380
|
+
background: var(--st-color-surface);
|
|
381
|
+
border: 1px solid var(--st-color-border);
|
|
382
|
+
border-radius: var(--st-radius-md);
|
|
383
|
+
padding: var(--st-spacing-sm);
|
|
384
|
+
min-width: 200px;
|
|
385
|
+
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
|
|
386
|
+
z-index: 10;
|
|
387
|
+
display: flex;
|
|
388
|
+
flex-direction: column;
|
|
389
|
+
gap: 0.25rem;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
.column-option {
|
|
393
|
+
display: flex;
|
|
394
|
+
align-items: center;
|
|
395
|
+
gap: 0.5rem;
|
|
396
|
+
font-size: var(--st-font-size-sm);
|
|
397
|
+
cursor: pointer;
|
|
398
|
+
padding: 0.25rem;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
.table-wrapper {
|
|
402
|
+
width: 100%;
|
|
403
|
+
overflow-x: auto;
|
|
404
|
+
border: 1px solid var(--st-color-border);
|
|
405
|
+
border-radius: var(--st-radius-md);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
table {
|
|
409
|
+
width: 100%;
|
|
410
|
+
border-collapse: collapse;
|
|
411
|
+
text-align: left;
|
|
412
|
+
font-size: var(--st-font-size-sm);
|
|
413
|
+
background-color: var(--st-color-surface);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
th {
|
|
417
|
+
font-weight: 600;
|
|
418
|
+
padding: var(--st-spacing-sm) var(--st-spacing-md);
|
|
419
|
+
border-bottom: 2px solid var(--st-color-border);
|
|
420
|
+
color: var(--st-color-text-muted);
|
|
421
|
+
white-space: nowrap;
|
|
422
|
+
background-color: var(--st-color-surface-muted, #f8fafc);
|
|
423
|
+
user-select: none;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
th[draggable="true"] {
|
|
427
|
+
cursor: grab;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
th[draggable="true"]:active {
|
|
431
|
+
cursor: grabbing;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
th.drag-over {
|
|
435
|
+
border-left: 2px solid var(--st-color-primary);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
.th-content {
|
|
439
|
+
display: flex;
|
|
440
|
+
align-items: center;
|
|
441
|
+
gap: 0.5rem;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
.sortable-header {
|
|
445
|
+
cursor: pointer;
|
|
446
|
+
display: flex;
|
|
447
|
+
align-items: center;
|
|
448
|
+
gap: 0.25rem;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
.sortable-header:hover {
|
|
452
|
+
color: var(--st-color-text);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
.sort-icon {
|
|
456
|
+
width: 1rem;
|
|
457
|
+
height: 1rem;
|
|
458
|
+
color: var(--st-color-text-muted);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
.sort-icon.active {
|
|
462
|
+
color: var(--st-color-primary);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
.sort-priority {
|
|
466
|
+
font-size: 0.7rem;
|
|
467
|
+
background: var(--st-color-border);
|
|
468
|
+
color: var(--st-color-text);
|
|
469
|
+
border-radius: 50%;
|
|
470
|
+
width: 1.1rem;
|
|
471
|
+
height: 1.1rem;
|
|
472
|
+
display: inline-flex;
|
|
473
|
+
align-items: center;
|
|
474
|
+
justify-content: center;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
td {
|
|
478
|
+
padding: var(--st-spacing-sm) var(--st-spacing-md);
|
|
479
|
+
border-bottom: 1px solid var(--st-color-border);
|
|
480
|
+
color: var(--st-color-text);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
tbody tr:last-child td {
|
|
484
|
+
border-bottom: none;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
tbody tr:hover {
|
|
488
|
+
background-color: var(--st-color-surface-hover, #f1f5f9);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
.pagination {
|
|
492
|
+
display: flex;
|
|
493
|
+
justify-content: space-between;
|
|
494
|
+
align-items: center;
|
|
495
|
+
padding: var(--st-spacing-md) 0;
|
|
496
|
+
font-size: var(--st-font-size-sm);
|
|
497
|
+
color: var(--st-color-text-muted);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
.pagination-controls {
|
|
501
|
+
display: flex;
|
|
502
|
+
gap: var(--st-spacing-sm);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
.drag-handle {
|
|
506
|
+
opacity: 0.3;
|
|
507
|
+
cursor: grab;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
.drag-handle:hover {
|
|
511
|
+
opacity: 0.7;
|
|
512
|
+
}
|
|
513
|
+
`
|
|
514
|
+
];
|
|
515
|
+
__decorate([
|
|
516
|
+
property({ type: Array })
|
|
517
|
+
], StDataTable.prototype, "columns", void 0);
|
|
518
|
+
__decorate([
|
|
519
|
+
property({ type: Array })
|
|
520
|
+
], StDataTable.prototype, "data", void 0);
|
|
521
|
+
__decorate([
|
|
522
|
+
property({ type: Number, attribute: 'total-rows' })
|
|
523
|
+
], StDataTable.prototype, "totalRows", void 0);
|
|
524
|
+
__decorate([
|
|
525
|
+
property({ type: Number })
|
|
526
|
+
], StDataTable.prototype, "page", void 0);
|
|
527
|
+
__decorate([
|
|
528
|
+
property({ type: Number, attribute: 'page-size' })
|
|
529
|
+
], StDataTable.prototype, "pageSize", void 0);
|
|
530
|
+
__decorate([
|
|
531
|
+
property({ type: Boolean, attribute: 'multi-sort' })
|
|
532
|
+
], StDataTable.prototype, "multiSort", void 0);
|
|
533
|
+
__decorate([
|
|
534
|
+
property({ type: Boolean, reflect: true })
|
|
535
|
+
], StDataTable.prototype, "loading", void 0);
|
|
536
|
+
__decorate([
|
|
537
|
+
state()
|
|
538
|
+
], StDataTable.prototype, "internalColumns", void 0);
|
|
539
|
+
__decorate([
|
|
540
|
+
state()
|
|
541
|
+
], StDataTable.prototype, "sortState", void 0);
|
|
542
|
+
__decorate([
|
|
543
|
+
state()
|
|
544
|
+
], StDataTable.prototype, "searchQuery", void 0);
|
|
545
|
+
__decorate([
|
|
546
|
+
state()
|
|
547
|
+
], StDataTable.prototype, "showColumnMenu", void 0);
|
|
548
|
+
StDataTable = __decorate([
|
|
549
|
+
customElement('st-data-table')
|
|
550
|
+
], StDataTable);
|
|
551
|
+
export { StDataTable };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
export type TableMode = 'horizontal' | 'vertical';
|
|
3
|
+
export interface TableColumn {
|
|
4
|
+
header: string;
|
|
5
|
+
key: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class StTable extends LitElement {
|
|
8
|
+
columns: TableColumn[];
|
|
9
|
+
data: Record<string, any>[];
|
|
10
|
+
mode: TableMode;
|
|
11
|
+
striped: boolean;
|
|
12
|
+
hoverable: boolean;
|
|
13
|
+
dense: boolean;
|
|
14
|
+
static styles: import("lit").CSSResult[];
|
|
15
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
16
|
+
}
|
|
17
|
+
declare global {
|
|
18
|
+
interface HTMLElementTagNameMap {
|
|
19
|
+
'st-table': StTable;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../src/components/table/table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAI5C,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG,UAAU,CAAC;AAElD,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACb;AAED,qBACa,OAAQ,SAAQ,UAAU;IACV,OAAO,EAAE,WAAW,EAAE,CAAM;IAC5B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAM;IAEjB,IAAI,EAAE,SAAS,CAAgB;IAC9B,OAAO,UAAS;IAChB,SAAS,UAAS;IAClB,KAAK,UAAS;IAE1D,MAAM,CAAC,MAAM,4BAsGX;IAEF,MAAM,yCAqBL;CACF;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,UAAU,EAAE,OAAO,CAAC;KACrB;CACF"}
|