dt-vue 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +266 -2
- package/dist/index.js +1253 -0
- package/dist/style.css +1 -0
- package/package.json +73 -4
- package/types/index.d.ts +302 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 John Benedict Palo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,267 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dt-vue
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A declarative Vue 3 data table built on [TanStack Table](https://tanstack.com/table) and styled with Tailwind
|
|
4
|
+
utilities. Columns are written as components, not config objects:
|
|
5
|
+
|
|
6
|
+
```vue
|
|
7
|
+
<DtTable :data="facilities" title="Facilities" exportable totals>
|
|
8
|
+
<DtColumn field="name" header="Facility" type="category" sortable width="w-1/3" />
|
|
9
|
+
<DtColumn field="region" header="Region" type="category" sortable />
|
|
10
|
+
<DtColumn field="cases" header="Cases" type="number" sortable />
|
|
11
|
+
</DtTable>
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Sorting, debounced global search, pagination, grouping with aggregates, a totals row, nested rows,
|
|
15
|
+
shift/drag range selection and Excel export are built in.
|
|
16
|
+
|
|
17
|
+
> **Status: 0.x, pre-release.** The API is still moving. See [Roadmap](#roadmap).
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm i dt-vue @tanstack/vue-table @heroicons/vue
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`xlsx` is an **optional** peer — install it only if you want Excel export. It is loaded with a dynamic
|
|
26
|
+
import, so apps that never export do not pay for it in their bundle.
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm i xlsx # only for export
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Setup
|
|
33
|
+
|
|
34
|
+
**1. Import the tokens stylesheet once** (app entry point):
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
import 'dt-vue/styles.css'
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**2. Add the package to your Tailwind content paths**, otherwise the component's utility classes are purged
|
|
41
|
+
and the table renders unstyled:
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
// tailwind.config.js (Tailwind v3)
|
|
45
|
+
export default {
|
|
46
|
+
content: ['./src/**/*.{vue,js}', './node_modules/dt-vue/dist/**/*.js'],
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```css
|
|
51
|
+
/* Tailwind v4 */
|
|
52
|
+
@source "../node_modules/dt-vue/dist";
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**3. Import the components** where you need them, or register globally:
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
import DtVue from 'dt-vue'
|
|
59
|
+
|
|
60
|
+
app.use(DtVue)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Theming
|
|
64
|
+
|
|
65
|
+
Only brand colours are tokenised; neutrals use stock Tailwind greys. Override any token on `:root`, or on an
|
|
66
|
+
ancestor element to scope a theme to part of the page:
|
|
67
|
+
|
|
68
|
+
```css
|
|
69
|
+
:root {
|
|
70
|
+
--dt-accent: #7c3aed;
|
|
71
|
+
--dt-accent-strong: #5b21b6;
|
|
72
|
+
--dt-accent-fg: #ffffff;
|
|
73
|
+
--dt-accent-wash: rgb(124 58 237 / 0.1);
|
|
74
|
+
--dt-focus-border: #c4b5fd;
|
|
75
|
+
--dt-focus-ring: rgb(196 181 253 / 0.4);
|
|
76
|
+
--dt-action: #4f46e5;
|
|
77
|
+
--dt-action-fg: #ffffff;
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Column types
|
|
82
|
+
|
|
83
|
+
`type` drives alignment, formatting, sorting, group aggregation and what gets written to the export.
|
|
84
|
+
|
|
85
|
+
| Type | Alignment | Renders as | Aggregates to | Totals row | Exports as |
|
|
86
|
+
| ---------- | --------- | ------------- | ------------- | ---------- | ---------- |
|
|
87
|
+
| `string` | center | raw value | — | — | text |
|
|
88
|
+
| `category` | left | raw value | shared value | — | text |
|
|
89
|
+
| `number` | center | `1,234` | sum | sum | number |
|
|
90
|
+
| `percent` | center | `92.40%` | mean | — | number |
|
|
91
|
+
| `date` | center | `Jan 5, 2026` | — | — | date |
|
|
92
|
+
| `minDate` | center | `Jan 5, 2026` | earliest | earliest | date |
|
|
93
|
+
| `maxDate` | center | `Jan 5, 2026` | latest | latest | date |
|
|
94
|
+
|
|
95
|
+
All formatting goes through `Intl`; there is no date library. Control it with `locale`, `dateFormat` and
|
|
96
|
+
`numberFormat` on the table, and `decimals` on a `percent` column.
|
|
97
|
+
|
|
98
|
+
### Column props
|
|
99
|
+
|
|
100
|
+
| Prop | Type | Default | Description |
|
|
101
|
+
| ------------ | ---------- | --------- | ---------------------------------------------------- |
|
|
102
|
+
| `field` | `String` | required | Key on the row object. |
|
|
103
|
+
| `header` | `String` | `field` | Column heading. |
|
|
104
|
+
| `type` | `String` | `string` | See the table above. |
|
|
105
|
+
| `sortable` | `Boolean` | `false` | Allow sorting by clicking the header. |
|
|
106
|
+
| `align` | `String` | by type | `left` \| `center` \| `right`. |
|
|
107
|
+
| `fit` | `Boolean` | `false` | Shrink the column to its content. |
|
|
108
|
+
| `width` | `String` | `null` | Tailwind width class, e.g. `w-1/3`, `w-[180px]`. |
|
|
109
|
+
| `decimals` | `Number` | `2` | Fraction digits for `percent`. |
|
|
110
|
+
| `cellStyle` | `Function` | `null` | `(value, rowData) => styleObject`. |
|
|
111
|
+
| `exportable` | `Boolean` | `true` | Include this column in the export. |
|
|
112
|
+
|
|
113
|
+
### Custom cells
|
|
114
|
+
|
|
115
|
+
```vue
|
|
116
|
+
<DtColumn field="status" header="Status">
|
|
117
|
+
<template #body="{ data, value, row, column, table }">
|
|
118
|
+
<StatusBadge :status="value" />
|
|
119
|
+
</template>
|
|
120
|
+
</DtColumn>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Clicks on interactive content inside a cell (`a`, `button`, `input`, …) do not toggle row selection. Add
|
|
124
|
+
`data-dt-no-select` to opt a custom element out too.
|
|
125
|
+
|
|
126
|
+
### Conditional cell shading
|
|
127
|
+
|
|
128
|
+
```vue
|
|
129
|
+
<script setup>
|
|
130
|
+
import { heatmap } from 'dt-vue'
|
|
131
|
+
|
|
132
|
+
const rate = heatmap({ min: 0, max: 100 })
|
|
133
|
+
</script>
|
|
134
|
+
|
|
135
|
+
<template>
|
|
136
|
+
<DtColumn field="rate" header="Accomplishment" type="percent" :cell-style="rate" />
|
|
137
|
+
</template>
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`heatmap({ colors, min, max, property })` returns a `cellStyle` function. The default ten-step scale runs red
|
|
141
|
+
through amber to green; pass your own `colors` array for anything else.
|
|
142
|
+
|
|
143
|
+
## Table props
|
|
144
|
+
|
|
145
|
+
| Prop | Type | Default | Description |
|
|
146
|
+
| ---------------- | -------------------- | ----------------------- | ---------------------------------------------------------------- |
|
|
147
|
+
| `data` | `Array` | `[]` | Row objects. |
|
|
148
|
+
| `title` | `String` | `''` | Heading, and the default export filename. |
|
|
149
|
+
| `locale` | `String` | runtime locale | Applied to every number and date. |
|
|
150
|
+
| `dateFormat` | `Object\|Function` | medium date | `Intl.DateTimeFormatOptions`, or `(date) => string`. |
|
|
151
|
+
| `numberFormat` | `Object` | `{}` | `Intl.NumberFormatOptions` for `number` columns. |
|
|
152
|
+
| `labels` | `Object` | English | Override any UI string. |
|
|
153
|
+
| `totals` | `Boolean` | `false` | Totals row for numeric and min/max date columns. |
|
|
154
|
+
| `bordered` | `Boolean` | `false` | Thin border under every row. |
|
|
155
|
+
| `mono` | `Boolean` | `false` | Monospace table text. |
|
|
156
|
+
| `loading` | `Boolean` | `false` | Loading placeholder row. |
|
|
157
|
+
| `rows` | `Number` | `10` | Page size. Reactive. |
|
|
158
|
+
| `pageSizes` | `Array` | `[10,25,50,75,100]` | Page-size options. |
|
|
159
|
+
| `searchable` | `Boolean` | `true` | Show the global search box. |
|
|
160
|
+
| `searchDebounce` | `Number` | `200` | Milliseconds before filtering. |
|
|
161
|
+
| `sortField` | `String` | `null` | Externally controlled sort column. |
|
|
162
|
+
| `sortOrder` | `Number` | `1` | `1` ascending, `-1` descending. |
|
|
163
|
+
| `groupBy` | `Object` | `null` | `{ Label: ['col'] }` — renders a "Group by Label" button. |
|
|
164
|
+
| `groupRowsBy` | `String` | `null` | Visual-only heading row whenever this field changes. |
|
|
165
|
+
| `subRows` | `String\|Function` | `'children'` | Where nested rows live. |
|
|
166
|
+
| `expandable` | `Boolean` | `true` | Expander column when the data nests. Set `false` to hide it. |
|
|
167
|
+
| `rowId` | `String` | `null` | Row identity; also what `v-model` holds. |
|
|
168
|
+
| `selectable` | `Boolean` | `false` | Checkbox column, click, shift-click and drag selection. |
|
|
169
|
+
| `exportable` | `Boolean` | `false` | Show the built-in Export button. |
|
|
170
|
+
| `exportFilename` | `String` | `title` | Export filename, without extension. |
|
|
171
|
+
| `sheetName` | `String` | `'Data'` | Worksheet name. |
|
|
172
|
+
|
|
173
|
+
### Selection
|
|
174
|
+
|
|
175
|
+
`v-model` is two-way. It holds `row[rowId]` values when `rowId` is set, otherwise whole row objects, and a
|
|
176
|
+
selection assigned from outside is applied back to the table — so rows can be pre-selected.
|
|
177
|
+
|
|
178
|
+
```vue
|
|
179
|
+
<DtTable v-model="selected" :data="rows" row-id="id" selectable>
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Only top-level rows are selectable; nested rows are not.
|
|
183
|
+
|
|
184
|
+
### Slots
|
|
185
|
+
|
|
186
|
+
| Slot | Props | Purpose |
|
|
187
|
+
| --------- | ------------------------------------------------------------ | ---------------------------- |
|
|
188
|
+
| `title` | — | Replace the heading. |
|
|
189
|
+
| `toolbar` | `table`, `exportXlsx`, `grouping`, `setGrouping`, `clearGrouping` | Buttons in the header bar. |
|
|
190
|
+
| `empty` | — | Empty state. |
|
|
191
|
+
| `loading` | — | Loading state. |
|
|
192
|
+
|
|
193
|
+
### Events
|
|
194
|
+
|
|
195
|
+
| Event | Payload | When |
|
|
196
|
+
| -------------- | ------- | ------------------------------------ |
|
|
197
|
+
| `export-error` | `Error` | Export failed, e.g. `xlsx` missing. |
|
|
198
|
+
|
|
199
|
+
### Exposed methods
|
|
200
|
+
|
|
201
|
+
```js
|
|
202
|
+
tableRef.value.table // the underlying TanStack table instance
|
|
203
|
+
await tableRef.value.exportXlsx()
|
|
204
|
+
tableRef.value.resetSelection()
|
|
205
|
+
tableRef.value.getSelectedRows()
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Export contents
|
|
209
|
+
|
|
210
|
+
The export reflects what the user is looking at: the active search, sort order, grouping order and column
|
|
211
|
+
visibility all apply, and columns marked `:exportable="false"` are left out. Pagination and expand/collapse
|
|
212
|
+
state do not apply, so the file always holds the full result set including nested rows. Numbers and dates are
|
|
213
|
+
written as real numbers and dates so Excel can total and reformat them.
|
|
214
|
+
|
|
215
|
+
## TypeScript
|
|
216
|
+
|
|
217
|
+
Declarations ship with the package — no `@types` install needed. Both components are generic over the row
|
|
218
|
+
type, so `#body` slot props and `cellStyle` are inferred:
|
|
219
|
+
|
|
220
|
+
```vue
|
|
221
|
+
<script setup lang="ts">
|
|
222
|
+
import { DtColumn, DtTable } from 'dt-vue'
|
|
223
|
+
import type { DtTableExposed } from 'dt-vue'
|
|
224
|
+
|
|
225
|
+
interface Facility { id: number; name: string; cases: number }
|
|
226
|
+
|
|
227
|
+
const rows = ref<Facility[]>([])
|
|
228
|
+
const table = ref<DtTableExposed<Facility>>()
|
|
229
|
+
</script>
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Installing the plugin also registers `DtTable` and `DtColumn` in Vue's `GlobalComponents`, so they resolve in
|
|
233
|
+
templates without an import.
|
|
234
|
+
|
|
235
|
+
## Behaviour notes
|
|
236
|
+
|
|
237
|
+
- **Sort direction on first click** follows TanStack: numeric columns sort descending first, text columns
|
|
238
|
+
ascending first.
|
|
239
|
+
- **Pagination resets to page 1** when the search text, the `data` prop or the grouping changes — and only
|
|
240
|
+
then. (TanStack's `autoResetPageIndex` is switched off deliberately: under the Vue adapter its queued reset
|
|
241
|
+
is flushed by the next `setOptions`, which lands straight after an ordinary page change and snaps the user
|
|
242
|
+
back to page 1.)
|
|
243
|
+
|
|
244
|
+
## Known limitations
|
|
245
|
+
|
|
246
|
+
- A `v-model` array mutated in place (`selected.value.push(x)`) is not picked up; assign a new array.
|
|
247
|
+
- Columns must be direct children of `<DtTable>`; they are read from the slot's vnodes, so columns wrapped
|
|
248
|
+
inside another component are not discovered.
|
|
249
|
+
- No column virtualization — use pagination for large datasets.
|
|
250
|
+
|
|
251
|
+
## Development
|
|
252
|
+
|
|
253
|
+
```bash
|
|
254
|
+
npm install
|
|
255
|
+
npm run dev # playground at /dev
|
|
256
|
+
npm run test:types # vue-tsc against the published declarations
|
|
257
|
+
npm run test:coverage
|
|
258
|
+
npm run check # tests + types + build
|
|
259
|
+
npm run build
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
`npm audit` reports advisories against `xlsx`, which is a dev dependency here for the playground and is
|
|
263
|
+
optional for consumers.
|
|
264
|
+
|
|
265
|
+
## License
|
|
266
|
+
|
|
267
|
+
MIT
|