@zhangt58/svelte-vtable 0.0.1 → 0.0.3
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
CHANGED
|
@@ -9,7 +9,7 @@ A Svelte 5 library providing virtualized data tables with sorting, selection, se
|
|
|
9
9
|
- 🔍 **Search** - Built-in search filtering
|
|
10
10
|
- 📄 **Pagination** - Configurable page controls with ellipsis navigation
|
|
11
11
|
- ✅ **Selection** - Row selection with callback support
|
|
12
|
-
- 🎨 **Styling** - Tailwind CSS based with dark mode support
|
|
12
|
+
- 🎨 **Styling** - Tailwind CSS based with light/dark mode support
|
|
13
13
|
- 📱 **Responsive** - Flexible column widths with stretch weights
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
@@ -129,22 +129,59 @@ Controls component for search and pagination.
|
|
|
129
129
|
| `pagechange` | `function` | `() => {}` | Callback for page changes: `({currentPage}) => void` |
|
|
130
130
|
| `searchchange` | `function` | `() => {}` | Callback for search changes: `({search}) => void` |
|
|
131
131
|
|
|
132
|
-
## Styling
|
|
132
|
+
## Styling (important)
|
|
133
133
|
|
|
134
|
-
|
|
135
|
-
- Light and dark mode
|
|
136
|
-
- Alternating row colors
|
|
137
|
-
- Hover states
|
|
138
|
-
- Selected row highlighting
|
|
139
|
-
- Sticky headers
|
|
134
|
+
This library ships with built-in CSS to provide sensible default visuals (light/dark mode, striping, hover, selection, sticky headers, and pagination control styling). There are two important details to understand so the styles work correctly for both local development and package consumers:
|
|
140
135
|
|
|
141
|
-
|
|
136
|
+
1) Source vs published CSS
|
|
137
|
+
- The human-editable source is `src/lib/styles.css`. It is written using Svelte-style `:global(...)` wrappers so the selectors are clear and scoped intentionally when compiled inside Svelte components.
|
|
138
|
+
- Bundlers and consumer projects do not process Svelte `:global(...)` tokens when they load plain `.css` files. For that reason the package publishes a compiled plain-CSS file at `src/lib/dist/styles.css`. This compiled file has the `:global(...)` wrappers removed so the selectors are normal CSS selectors and will match in any bundler.
|
|
139
|
+
|
|
140
|
+
2) How you should import the styles as a consumer
|
|
141
|
+
- Recommended (installed from npm):
|
|
142
142
|
|
|
143
143
|
```js
|
|
144
144
|
import '@zhangt58/svelte-vtable/styles.css';
|
|
145
145
|
```
|
|
146
146
|
|
|
147
|
-
|
|
147
|
+
This import resolves to the precompiled `src/lib/dist/styles.css` via the package `exports` entry in `package.json`.
|
|
148
|
+
|
|
149
|
+
- Working inside the repo or during local development (components import the file relatively):
|
|
150
|
+
|
|
151
|
+
Components inside this package import the compiled CSS via:
|
|
152
|
+
|
|
153
|
+
```css
|
|
154
|
+
@import '../lib/dist/styles.css';
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Do not import the raw `src/lib/styles.css` from components or consumers — the `:global(...)` wrappers will remain and selectors won't behave as intended outside the Svelte compiler.
|
|
158
|
+
|
|
159
|
+
3) How :global works here and why we compile it
|
|
160
|
+
- `:global(.selector)` is a Svelte compiler token used when writing styles in Svelte components. It tells the Svelte compiler to treat the selector as global instead of scoping it to the component.
|
|
161
|
+
- When shipping plain `.css` files to consumers, those tokens must be converted into regular selectors. The repository contains a tiny build script (`scripts/build-styles.cjs`) that strips `:global(...)` wrappers and emits a compiled `src/lib/dist/styles.css`. This is what gets published and what consumers should import.
|
|
162
|
+
|
|
163
|
+
4) Build scripts and publishing
|
|
164
|
+
- The project has a `build:styles` script that generates `src/lib/dist/styles.css` from `src/lib/styles.css`:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
npm run build:styles
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
- `package.json` already runs `npm run build:styles` as part of `prepublishOnly` to ensure the compiled CSS is present before publishing.
|
|
171
|
+
|
|
172
|
+
Optional recommendation: add `prepare` to `package.json` so that `npm install` in development or certain CI flows will also generate the compiled CSS automatically:
|
|
173
|
+
|
|
174
|
+
```json
|
|
175
|
+
"scripts": {
|
|
176
|
+
"build:styles": "node ./scripts/build-styles.cjs",
|
|
177
|
+
"prepare": "npm run build:styles",
|
|
178
|
+
"prepublishOnly": "npm run build:styles && npm run check"
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
This is optional — the current `prepublishOnly` is sufficient for publishing.
|
|
183
|
+
|
|
184
|
+
## CSS Custom Properties
|
|
148
185
|
|
|
149
186
|
Override these CSS variables to customize appearance:
|
|
150
187
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhangt58/svelte-vtable",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "A Svelte 5 library for virtualized data tables with sorting, selection, and pagination controls.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"svelte": "./src/lib/index.js",
|
|
@@ -12,11 +12,13 @@
|
|
|
12
12
|
"import": "./src/lib/index.js",
|
|
13
13
|
"default": "./src/lib/index.js"
|
|
14
14
|
},
|
|
15
|
-
"./styles.css": "./src/lib/styles.css"
|
|
15
|
+
"./styles.css": "./src/lib/dist/styles.css"
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
18
|
"check": "svelte-check --tsconfig ./jsconfig.json",
|
|
19
|
-
"
|
|
19
|
+
"build:styles": "node ./scripts/build-styles.cjs",
|
|
20
|
+
"prepare": "npm run build:styles",
|
|
21
|
+
"prepublishOnly": "npm run build:styles && npm run check"
|
|
20
22
|
},
|
|
21
23
|
"keywords": [
|
|
22
24
|
"svelte",
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
.virtual-data-table {
|
|
2
|
+
display: block;
|
|
3
|
+
min-width: 0;
|
|
4
|
+
height: 100%;
|
|
5
|
+
overflow: auto;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.datatable-table {
|
|
9
|
+
display: table;
|
|
10
|
+
width: 100%;
|
|
11
|
+
min-width: 0;
|
|
12
|
+
border-collapse: collapse;
|
|
13
|
+
box-sizing: border-box;
|
|
14
|
+
font-size: 0.875rem; /* 14px - smaller, more compact */
|
|
15
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
|
|
16
|
+
line-height: 1.4;
|
|
17
|
+
border: none;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/* Sticky header support */
|
|
21
|
+
.datatable-table thead.sticky-header {
|
|
22
|
+
position: sticky;
|
|
23
|
+
top: 0;
|
|
24
|
+
z-index: 20;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* Header visual styles - only bottom border */
|
|
28
|
+
.datatable-table thead th {
|
|
29
|
+
background-color: var(--tbl-head-bg, #f8f9fa);
|
|
30
|
+
font-size: 0.8125rem; /* 13px */
|
|
31
|
+
font-weight: 600;
|
|
32
|
+
text-transform: uppercase;
|
|
33
|
+
letter-spacing: 0.025em;
|
|
34
|
+
border-top: none;
|
|
35
|
+
border-left: none;
|
|
36
|
+
border-right: none;
|
|
37
|
+
border-bottom: 2px solid #dee2e6;
|
|
38
|
+
padding: 0.5rem 0.75rem;
|
|
39
|
+
text-align: left;
|
|
40
|
+
white-space: normal; /* Allow header text to wrap */
|
|
41
|
+
overflow: visible;
|
|
42
|
+
box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1); /* Keep border visible on scroll */
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* Row striping - alternating colors */
|
|
46
|
+
/* VirtualList may wrap rows, so we target tr directly */
|
|
47
|
+
.datatable-table tbody tr:nth-of-type(even) {
|
|
48
|
+
background-color: #ffffff;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.datatable-table tbody tr:nth-of-type(odd) {
|
|
52
|
+
background-color: #f8f9fa;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* Also ensure tr elements themselves have background */
|
|
56
|
+
.datatable-table tbody tr {
|
|
57
|
+
background-color: inherit;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* Hover effect */
|
|
61
|
+
.datatable-table tbody tr:hover {
|
|
62
|
+
background-color: #e7f1ff !important;
|
|
63
|
+
transition: background-color 0.15s ease-in-out;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* Selesky-500 row overrides striping and hover */
|
|
67
|
+
.datatable-table tbody tr.selected-row {
|
|
68
|
+
background-color: #e0f2fe !important; /* light sky background */
|
|
69
|
+
box-shadow: inset 4px 0 0 0 #0369a1; /* left accent */
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.dark .datatable-table tbody tr.selected-row {
|
|
73
|
+
/* brighter, higher-contrast selection in dark mode */
|
|
74
|
+
background-color: rgba(14,165,233,0.22) !important; /* stronger visible blue */
|
|
75
|
+
box-shadow: inset 6px 0 0 0 rgba(56,189,248,0.85); /* stronger left accent */
|
|
76
|
+
transition: background-color 0.12s ease-in-out, box-shadow 0.12s ease-in-out;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* Also apply to cells to defeat any cell-level background from striping and ensure readable text */
|
|
80
|
+
.datatable-table tbody tr.selected-row td {
|
|
81
|
+
background-color: #e0f2fe !important;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.dark .datatable-table tbody tr.selected-row td {
|
|
85
|
+
background-color: rgba(14,165,233,0.22) !important;
|
|
86
|
+
color: #f0fbff !important; /* ensure high-contrast, very light text */
|
|
87
|
+
border-bottom-color: rgba(255,255,255,0.06);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* Body cell defaults - only bottom border */
|
|
91
|
+
.datatable-table tbody td {
|
|
92
|
+
padding: 0.5rem 0.75rem;
|
|
93
|
+
border-top: none;
|
|
94
|
+
border-left: none;
|
|
95
|
+
border-right: none;
|
|
96
|
+
border-bottom: 1px solid #e9ecef;
|
|
97
|
+
vertical-align: middle;
|
|
98
|
+
text-align: left;
|
|
99
|
+
font-size: 0.875rem; /* 14px */
|
|
100
|
+
overflow: hidden;
|
|
101
|
+
white-space: normal; /* Allow wrapping by default */
|
|
102
|
+
word-wrap: break-word;
|
|
103
|
+
box-sizing: border-box;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/* No-wrap variant for cells that should truncate */
|
|
107
|
+
.datatable-table tbody td.nowrap {
|
|
108
|
+
white-space: nowrap;
|
|
109
|
+
text-overflow: ellipsis;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/* Compact variant */
|
|
113
|
+
.datatable-table.compact tbody td {
|
|
114
|
+
padding: 0.1rem 0.3rem;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/* Header content alignment helper */
|
|
118
|
+
.datatable-table thead th > div {
|
|
119
|
+
display: inline-flex;
|
|
120
|
+
align-items: center;
|
|
121
|
+
gap: 0.25rem;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/* Allow certain long cells to wrap fully if explicitly requested */
|
|
125
|
+
.datatable-table td.wrap {
|
|
126
|
+
white-space: normal;
|
|
127
|
+
word-break: break-word;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/* Dark mode variants for the datatable */
|
|
131
|
+
.dark .datatable-table thead th {
|
|
132
|
+
background-color: #1f2937;
|
|
133
|
+
border-bottom-color: #374151;
|
|
134
|
+
color: #f9fafb;
|
|
135
|
+
box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.3); /* Darker shadow for dark mode */
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.dark .datatable-table tbody tr:nth-of-type(even) {
|
|
139
|
+
background-color: #111827;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.dark .datatable-table tbody tr:nth-of-type(odd) {
|
|
143
|
+
background-color: #1f2937;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.dark .datatable-table tbody tr:hover {
|
|
147
|
+
background-color: #374151 !important;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.dark .datatable-table tbody td {
|
|
151
|
+
border-bottom-color: #374151;
|
|
152
|
+
color: #e5e7eb;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/* Shared control styles (inputs, pagination, column filters) used by page components */
|
|
156
|
+
.datatable-input {
|
|
157
|
+
padding: 0.375rem 0.75rem;
|
|
158
|
+
font-size: 0.95rem;
|
|
159
|
+
border: 1px solid #ced4da;
|
|
160
|
+
border-radius: 0.25rem;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.datatable-input:focus {
|
|
164
|
+
border-color: #86b7fe;
|
|
165
|
+
outline: 0;
|
|
166
|
+
box-shadow: 0 0 0.1rem 0.2rem rgba(13, 110, 253, 0.25);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.search-filtering-row {
|
|
170
|
+
background-color: #f8f9fa;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.search-filtering-row th {
|
|
174
|
+
padding: 0.1rem 0.1rem;
|
|
175
|
+
border-bottom: 1px solid #dee2e6;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.column-filter {
|
|
179
|
+
width: 95%;
|
|
180
|
+
padding: 0.2rem 0.25rem;
|
|
181
|
+
font-size: 0.8rem;
|
|
182
|
+
border: 1px solid #ced4da;
|
|
183
|
+
border-radius: 0.25rem;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.column-filter::placeholder {
|
|
187
|
+
color: #adb5bd;
|
|
188
|
+
font-size: 0.75rem;
|
|
189
|
+
font-style: italic;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.datatable-pagination {
|
|
193
|
+
display: flex;
|
|
194
|
+
gap: 0.1rem;
|
|
195
|
+
margin-top: 0.6rem;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.datatable-pagination li a,
|
|
199
|
+
.datatable-pagination li button {
|
|
200
|
+
padding: 0.3rem 0.7rem;
|
|
201
|
+
border: 1px solid #dee2e6;
|
|
202
|
+
border-radius: 0;
|
|
203
|
+
background-color: #fff;
|
|
204
|
+
color: #0d6efd;
|
|
205
|
+
text-decoration: none;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.datatable-pagination li a:hover,
|
|
209
|
+
.datatable-pagination li button:hover {
|
|
210
|
+
background-color: #e9ecef;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.datatable-pagination .datatable-active a,
|
|
214
|
+
.datatable-pagination .datatable-active button {
|
|
215
|
+
background-color: #0d6efd;
|
|
216
|
+
border-color: #0d6efd;
|
|
217
|
+
color: #fff;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/* Force the active/current page to use the green tokens (override flowbite's primary/orange).
|
|
221
|
+
Intentionally specific to reliably win over third-party rules. */
|
|
222
|
+
[data-pagination-id] ul li [aria-current="page"] {
|
|
223
|
+
background-color: #dcfce7 !important; /* bg-green-100 */
|
|
224
|
+
color: #16a34a !important; /* text-green-600 */
|
|
225
|
+
border-color: transparent !important;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/* Ensure Prev/Next controls visually match the numeric buttons' border and rhythm
|
|
229
|
+
(keeps border, radius and min-width consistent). This is minimal and won't
|
|
230
|
+
override hover/text colors managed by Tailwind classes applied at runtime. */
|
|
231
|
+
[data-pagination-id] ul li:first-child > button,
|
|
232
|
+
[data-pagination-id] ul li:first-child > a,
|
|
233
|
+
[data-pagination-id] ul li:last-child > button,
|
|
234
|
+
[data-pagination-id] ul li:last-child > a {
|
|
235
|
+
border: 1px solid #d1d5db; /* border-gray-300 */
|
|
236
|
+
min-width: 2rem; /* align with numeric buttons' min width */
|
|
237
|
+
background: transparent;
|
|
238
|
+
padding: 0.25rem 0.5rem; /* keep comfortable hit area */
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/* Light mode: hover/focus for Prev/Next match numeric button hover */
|
|
242
|
+
[data-pagination-id] ul li:first-child > button:hover,
|
|
243
|
+
[data-pagination-id] ul li:first-child > a:hover,
|
|
244
|
+
[data-pagination-id] ul li:last-child > button:hover,
|
|
245
|
+
[data-pagination-id] ul li:last-child > a:hover,
|
|
246
|
+
[data-pagination-id] ul li:first-child > button:focus,
|
|
247
|
+
[data-pagination-id] ul li:first-child > a:focus,
|
|
248
|
+
[data-pagination-id] ul li:last-child > button:focus,
|
|
249
|
+
[data-pagination-id] ul li:last-child > a:focus {
|
|
250
|
+
background-color: #f3f4f6; /* tailwind gray-100 */
|
|
251
|
+
outline: none;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/* Ellipsis styling: make clickable and visually lighter (JS sets data-ellipsis/data-jump) */
|
|
255
|
+
[data-pagination-id] ul li [data-ellipsis="true"] {
|
|
256
|
+
cursor: pointer;
|
|
257
|
+
background: transparent !important;
|
|
258
|
+
color: inherit;
|
|
259
|
+
opacity: 0.9;
|
|
260
|
+
font-size: 0.875rem;
|
|
261
|
+
padding: 0.25rem 0.5rem;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/* Chevron sizing for Prev/Next so icons sit comfortably in the buttons */
|
|
265
|
+
[data-pagination-id] ul li:first-child svg,
|
|
266
|
+
[data-pagination-id] ul li:last-child svg {
|
|
267
|
+
height: 1.25rem;
|
|
268
|
+
width: 1.25rem;
|
|
269
|
+
display: block;
|
|
270
|
+
}
|