@casinogate/ui 0.0.4 → 1.0.1
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 +886 -90
- package/dist/app.d.ts +1 -1
- package/dist/app.html +9 -9
- package/dist/assets/css/root.css +585 -0
- package/dist/assets/css/theme.css +2 -0
- package/dist/components/button/button.stories.svelte +2 -2
- package/dist/components/checkbox/checkbox.stories.svelte +2 -2
- package/dist/components/checkbox/components/checkbox.root.svelte +2 -2
- package/dist/components/checkbox/index.js +1 -1
- package/dist/components/collapsible/collapsible.stories.svelte +2 -2
- package/dist/components/collapsible/components/collapsaible.svelte.js +1 -1
- package/dist/components/collapsible/components/collapsaible.trigger.svelte +2 -2
- package/dist/components/data-table/README.md +1285 -0
- package/dist/components/data-table/components/data-table.body.svelte +33 -0
- package/dist/components/data-table/components/data-table.body.svelte.d.ts +8 -0
- package/dist/components/data-table/components/data-table.cell.svelte +48 -0
- package/dist/components/data-table/components/data-table.cell.svelte.d.ts +10 -0
- package/dist/components/data-table/components/data-table.head.svelte +48 -0
- package/dist/components/data-table/components/data-table.head.svelte.d.ts +10 -0
- package/dist/components/data-table/components/data-table.header.svelte +41 -0
- package/dist/components/data-table/components/data-table.header.svelte.d.ts +7 -0
- package/dist/components/data-table/components/data-table.resize-handler.svelte +31 -0
- package/dist/components/data-table/components/data-table.resize-handler.svelte.d.ts +7 -0
- package/dist/components/data-table/components/data-table.root.svelte +55 -0
- package/dist/components/data-table/components/data-table.root.svelte.d.ts +34 -0
- package/dist/components/data-table/components/data-table.row.svelte +35 -0
- package/dist/components/data-table/components/data-table.row.svelte.d.ts +7 -0
- package/dist/components/data-table/components/data-table.sort-button.svelte +51 -0
- package/dist/components/data-table/components/data-table.sort-button.svelte.d.ts +7 -0
- package/dist/components/data-table/components/data-table.svelte.d.ts +139 -0
- package/dist/components/data-table/components/data-table.svelte.js +248 -0
- package/dist/components/data-table/components/data-table.table.svelte +33 -0
- package/dist/components/data-table/components/data-table.table.svelte.d.ts +8 -0
- package/dist/components/data-table/components/flex-render.svelte +32 -0
- package/dist/components/data-table/components/flex-render.svelte.d.ts +30 -0
- package/dist/components/data-table/data-table.stories.svelte +327 -0
- package/dist/components/data-table/data-table.stories.svelte.d.ts +4 -0
- package/dist/components/data-table/data-table.svelte +118 -0
- package/dist/components/data-table/data-table.svelte.d.ts +32 -0
- package/dist/components/data-table/index.js +27 -0
- package/dist/components/data-table/models/create-table.svelte.d.ts +19 -0
- package/dist/components/data-table/models/create-table.svelte.js +35 -0
- package/dist/components/data-table/models/index.d.ts +1 -0
- package/dist/components/data-table/models/index.js +1 -0
- package/dist/components/data-table/styles.d.ts +176 -0
- package/dist/components/data-table/styles.js +83 -0
- package/dist/components/data-table/types.d.ts +1 -0
- package/dist/components/data-table/types.js +1 -0
- package/dist/components/data-table/utils/index.d.ts +4 -0
- package/dist/components/data-table/utils/index.js +4 -0
- package/dist/components/data-table/utils/pagination-state.svelte.d.ts +10 -0
- package/dist/components/data-table/utils/pagination-state.svelte.js +26 -0
- package/dist/components/data-table/utils/render-helper.d.ts +90 -0
- package/dist/components/data-table/utils/render-helper.js +99 -0
- package/dist/components/data-table/utils/resize-state.svelte.d.ts +10 -0
- package/dist/components/data-table/utils/resize-state.svelte.js +23 -0
- package/dist/components/data-table/utils/row-models.d.ts +7 -0
- package/dist/components/data-table/utils/row-models.js +7 -0
- package/dist/components/data-table/utils/row-selection-state.svelte.d.ts +10 -0
- package/dist/components/data-table/utils/row-selection-state.svelte.js +23 -0
- package/dist/components/icons/caret-down.svelte +12 -0
- package/dist/components/icons/caret-down.svelte.d.ts +3 -0
- package/dist/components/icons/caret-up.svelte +12 -0
- package/dist/components/icons/caret-up.svelte.d.ts +3 -0
- package/dist/components/icons/check.svelte +12 -0
- package/dist/components/icons/check.svelte.d.ts +3 -0
- package/dist/components/icons/chevron-down.svelte +12 -0
- package/dist/components/icons/chevron-down.svelte.d.ts +3 -0
- package/dist/components/icons/chevron-left.svelte +12 -0
- package/dist/components/icons/chevron-left.svelte.d.ts +3 -0
- package/dist/components/icons/chevron-right.svelte +12 -0
- package/dist/components/icons/chevron-right.svelte.d.ts +3 -0
- package/dist/components/icons/chevron-small-down.svelte +14 -0
- package/dist/components/icons/chevron-small-down.svelte.d.ts +3 -0
- package/dist/components/icons/chevron-small-left.svelte +14 -0
- package/dist/components/icons/chevron-small-left.svelte.d.ts +3 -0
- package/dist/components/icons/chevron-small-right.svelte +14 -0
- package/dist/components/icons/chevron-small-right.svelte.d.ts +3 -0
- package/dist/components/icons/chevron-small-up.svelte +14 -0
- package/dist/components/icons/chevron-small-up.svelte.d.ts +3 -0
- package/dist/components/icons/chevron-up.svelte +12 -0
- package/dist/components/icons/chevron-up.svelte.d.ts +3 -0
- package/dist/components/icons/dots.svelte +20 -0
- package/dist/components/icons/dots.svelte.d.ts +3 -0
- package/dist/components/icons/error.svelte +12 -0
- package/dist/components/icons/error.svelte.d.ts +3 -0
- package/dist/components/icons/eye-crossed.svelte +14 -0
- package/dist/components/icons/eye-crossed.svelte.d.ts +3 -0
- package/dist/components/icons/eye.svelte +17 -0
- package/dist/components/icons/eye.svelte.d.ts +3 -0
- package/dist/components/icons/index.d.ts +22 -0
- package/dist/components/icons/index.js +21 -0
- package/dist/components/icons/info.svelte +12 -0
- package/dist/components/icons/info.svelte.d.ts +3 -0
- package/dist/components/icons/minus.svelte +12 -0
- package/dist/components/icons/minus.svelte.d.ts +3 -0
- package/dist/components/icons/sort.svelte +16 -0
- package/dist/components/icons/sort.svelte.d.ts +3 -0
- package/dist/components/icons/spinner.svelte +9 -0
- package/dist/components/icons/spinner.svelte.d.ts +3 -0
- package/dist/components/icons/success.svelte +12 -0
- package/dist/components/icons/success.svelte.d.ts +3 -0
- package/dist/components/icons/types.d.ts +2 -0
- package/dist/components/icons/types.js +1 -0
- package/dist/components/icons/warning.svelte +12 -0
- package/dist/components/icons/warning.svelte.d.ts +3 -0
- package/dist/components/input/index.d.ts +6 -0
- package/dist/components/input/index.js +5 -0
- package/dist/components/input/input.password.svelte +38 -0
- package/dist/components/input/input.password.svelte.d.ts +7 -0
- package/dist/components/input/input.stories.svelte +41 -0
- package/dist/components/input/input.stories.svelte.d.ts +19 -0
- package/dist/components/input/input.svelte +65 -0
- package/dist/components/input/input.svelte.d.ts +12 -0
- package/dist/components/input/styles.d.ts +141 -0
- package/dist/components/input/styles.js +64 -0
- package/dist/components/pagination/components/pagination.ellipsis.svelte +27 -0
- package/dist/components/pagination/components/pagination.ellipsis.svelte.d.ts +7 -0
- package/dist/components/pagination/components/pagination.item.svelte +16 -0
- package/dist/components/pagination/components/pagination.item.svelte.d.ts +5 -0
- package/dist/components/pagination/components/pagination.next-button.svelte +28 -0
- package/dist/components/pagination/components/pagination.next-button.svelte.d.ts +5 -0
- package/dist/components/pagination/components/pagination.prev-button.svelte +28 -0
- package/dist/components/pagination/components/pagination.prev-button.svelte.d.ts +5 -0
- package/dist/components/pagination/components/pagination.root.svelte +29 -0
- package/dist/components/pagination/components/pagination.root.svelte.d.ts +6 -0
- package/dist/components/pagination/index.d.ts +16 -0
- package/dist/components/pagination/index.js +16 -0
- package/dist/components/pagination/pagination.stories.svelte +69 -0
- package/dist/components/pagination/pagination.stories.svelte.d.ts +19 -0
- package/dist/components/pagination/presets/basic.svelte +31 -0
- package/dist/components/pagination/presets/basic.svelte.d.ts +5 -0
- package/dist/components/pagination/presets/index.d.ts +1 -0
- package/dist/components/pagination/presets/index.js +1 -0
- package/dist/components/pagination/styles.d.ts +98 -0
- package/dist/components/pagination/styles.js +51 -0
- package/dist/components/segment/components/segment.item.svelte +38 -0
- package/dist/components/segment/components/segment.item.svelte.d.ts +9 -0
- package/dist/components/segment/components/segment.root.svelte +66 -0
- package/dist/components/segment/components/segment.root.svelte.d.ts +13 -0
- package/dist/components/segment/components/segment.thumb.svelte +0 -0
- package/dist/components/segment/components/segment.thumb.svelte.d.ts +26 -0
- package/dist/components/segment/components/segmet.svelte.d.ts +43 -0
- package/dist/components/segment/components/segmet.svelte.js +74 -0
- package/dist/components/segment/index.d.ts +7 -0
- package/dist/components/segment/index.js +6 -0
- package/dist/components/segment/segment.stories.svelte +43 -0
- package/dist/components/segment/segment.stories.svelte.d.ts +18 -0
- package/dist/components/segment/styles.d.ts +107 -0
- package/dist/components/segment/styles.js +58 -0
- package/dist/components/select/components/select.content.svelte +0 -0
- package/dist/components/select/components/select.content.svelte.d.ts +26 -0
- package/dist/components/select/components/select.item.svelte +0 -0
- package/dist/components/select/components/select.item.svelte.d.ts +26 -0
- package/dist/components/select/components/select.root.svelte +27 -0
- package/dist/components/select/components/select.root.svelte.d.ts +6 -0
- package/dist/components/select/components/select.trigger.svelte +52 -0
- package/dist/components/select/components/select.trigger.svelte.d.ts +10 -0
- package/dist/components/select/components/select.viewport.svelte +0 -0
- package/dist/components/select/components/select.viewport.svelte.d.ts +26 -0
- package/dist/components/select/index.d.ts +7 -0
- package/dist/components/select/index.js +6 -0
- package/dist/components/select/select.stories.svelte +53 -0
- package/dist/components/select/select.stories.svelte.d.ts +18 -0
- package/dist/components/select/styles.d.ts +149 -0
- package/dist/components/select/styles.js +93 -0
- package/dist/components/skeleton/index.d.ts +1 -0
- package/dist/components/skeleton/index.js +1 -0
- package/dist/components/skeleton/skeleton.stories.svelte +121 -0
- package/dist/components/skeleton/skeleton.stories.svelte.d.ts +19 -0
- package/dist/components/skeleton/skeleton.svelte +25 -0
- package/dist/components/skeleton/skeleton.svelte.d.ts +8 -0
- package/dist/components/skeleton/styles.d.ts +78 -0
- package/dist/components/skeleton/styles.js +30 -0
- package/dist/components/spinner/index.d.ts +1 -0
- package/dist/components/spinner/index.js +1 -0
- package/dist/components/spinner/spinner.stories.svelte +29 -0
- package/dist/components/spinner/spinner.stories.svelte.d.ts +19 -0
- package/dist/components/spinner/spinner.svelte +24 -0
- package/dist/components/spinner/spinner.svelte.d.ts +9 -0
- package/dist/components/switch/index.d.ts +7 -2
- package/dist/components/switch/index.js +6 -3
- package/dist/components/switch/model/index.d.ts +1 -1
- package/dist/components/switch/model/index.js +1 -1
- package/dist/components/switch/model/switch-model.svelte.d.ts +1 -1
- package/dist/components/switch/model/switch-model.svelte.js +1 -1
- package/dist/components/switch/presets/basic.svelte +14 -0
- package/dist/components/switch/presets/basic.svelte.d.ts +5 -0
- package/dist/components/switch/switch.stories.svelte +16 -9
- package/dist/components/switch/switch.stories.svelte.d.ts +1 -0
- package/dist/components/toast/toast.component.svelte +2 -5
- package/dist/components/toast/toast.stories.svelte +2 -2
- package/dist/index.d.ts +10 -1
- package/dist/index.js +10 -1
- package/dist/internal/mocks/data-table.d.ts +9 -0
- package/dist/internal/mocks/data-table.js +146 -0
- package/dist/internal/types/common.d.ts +1 -0
- package/dist/internal/utils/attrs.d.ts +3 -0
- package/dist/internal/utils/attrs.js +9 -0
- package/dist/internal/utils/objects.d.ts +12 -0
- package/dist/internal/utils/objects.js +52 -0
- package/dist/internal/utils/tailwindcss.js +1 -0
- package/package.json +9 -2
- package/dist/assets/icons/check.svg +0 -4
- package/dist/assets/icons/chevron-down.svg +0 -4
- package/dist/assets/icons/chevron-left.svg +0 -4
- package/dist/assets/icons/chevron-right.svg +0 -4
- package/dist/assets/icons/chevron-small-down.svg +0 -4
- package/dist/assets/icons/chevron-small-left.svg +0 -4
- package/dist/assets/icons/chevron-small-right.svg +0 -4
- package/dist/assets/icons/chevron-small-up.svg +0 -4
- package/dist/assets/icons/chevron-up.svg +0 -4
- package/dist/assets/icons/error.svg +0 -4
- package/dist/assets/icons/info.svg +0 -4
- package/dist/assets/icons/minus.svg +0 -4
- package/dist/assets/icons/success.svg +0 -4
- package/dist/assets/icons/warning.svg +0 -3
- package/dist/internal/types/attrs.d.ts +0 -1
- package/dist/internal/types/attrs.js +0 -3
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { keyWithPrefix } from '../../../internal/utils/common.js';
|
|
2
|
+
import { Context, useMutationObserver, watch } from 'runed';
|
|
3
|
+
import { attachRef } from 'svelte-toolbelt';
|
|
4
|
+
const SLOT_ATTR_NAME = 'data-slot';
|
|
5
|
+
const SLOT_ATTR_VALUES = {
|
|
6
|
+
root: 'root',
|
|
7
|
+
header: 'header',
|
|
8
|
+
head: 'head',
|
|
9
|
+
body: 'body',
|
|
10
|
+
table: 'table',
|
|
11
|
+
footer: 'footer',
|
|
12
|
+
row: 'row',
|
|
13
|
+
cell: 'cell',
|
|
14
|
+
sortButton: 'sort-button',
|
|
15
|
+
resizeHandler: 'resize-handler',
|
|
16
|
+
};
|
|
17
|
+
const DataTableRootContext = new Context(keyWithPrefix('data-table-root'));
|
|
18
|
+
const DataTableHeadContext = new Context(keyWithPrefix('data-table-head'));
|
|
19
|
+
export class DataTableRootState {
|
|
20
|
+
static create(opts) {
|
|
21
|
+
return DataTableRootContext.set(new DataTableRootState(opts));
|
|
22
|
+
}
|
|
23
|
+
opts;
|
|
24
|
+
attachment;
|
|
25
|
+
observedRow = $state(null);
|
|
26
|
+
columnSizingVars = $derived.by(() => {
|
|
27
|
+
const headers = this.opts.table.current.getFlatHeaders();
|
|
28
|
+
const colSizes = {};
|
|
29
|
+
for (let i = 0; i < headers.length; i++) {
|
|
30
|
+
const header = headers[i];
|
|
31
|
+
colSizes[`--header-${header.id}-size`] = header.getSize();
|
|
32
|
+
colSizes[`--col-${header.column.id}-size`] = header.column.getSize();
|
|
33
|
+
}
|
|
34
|
+
return colSizes;
|
|
35
|
+
});
|
|
36
|
+
constructor(opts) {
|
|
37
|
+
this.opts = opts;
|
|
38
|
+
this.attachment = attachRef(opts.ref);
|
|
39
|
+
}
|
|
40
|
+
onLastRowReached = () => {
|
|
41
|
+
this.opts.table.current?.features?.onLastRowReached?.();
|
|
42
|
+
};
|
|
43
|
+
props = $derived.by(() => ({
|
|
44
|
+
id: this.opts.id.current,
|
|
45
|
+
[SLOT_ATTR_NAME]: SLOT_ATTR_VALUES.root,
|
|
46
|
+
style: {
|
|
47
|
+
...this.columnSizingVars,
|
|
48
|
+
},
|
|
49
|
+
...this.attachment,
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
export class DataTableTableState {
|
|
53
|
+
static create(opts) {
|
|
54
|
+
return new DataTableTableState(opts);
|
|
55
|
+
}
|
|
56
|
+
opts;
|
|
57
|
+
attachment;
|
|
58
|
+
constructor(opts) {
|
|
59
|
+
this.opts = opts;
|
|
60
|
+
this.attachment = attachRef(opts.ref);
|
|
61
|
+
}
|
|
62
|
+
props = $derived.by(() => ({
|
|
63
|
+
id: this.opts.id.current,
|
|
64
|
+
[SLOT_ATTR_NAME]: SLOT_ATTR_VALUES.table,
|
|
65
|
+
...this.attachment,
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
export class DataTableHeaderState {
|
|
69
|
+
static create(opts) {
|
|
70
|
+
return new DataTableHeaderState(opts);
|
|
71
|
+
}
|
|
72
|
+
opts;
|
|
73
|
+
attachment;
|
|
74
|
+
constructor(opts) {
|
|
75
|
+
this.opts = opts;
|
|
76
|
+
this.attachment = attachRef(opts.ref);
|
|
77
|
+
}
|
|
78
|
+
props = $derived.by(() => ({
|
|
79
|
+
id: this.opts.id.current,
|
|
80
|
+
[SLOT_ATTR_NAME]: SLOT_ATTR_VALUES.header,
|
|
81
|
+
...this.attachment,
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
export class DataTableRowState {
|
|
85
|
+
static create(opts) {
|
|
86
|
+
return new DataTableRowState(opts, DataTableRootContext.get());
|
|
87
|
+
}
|
|
88
|
+
opts;
|
|
89
|
+
attachment;
|
|
90
|
+
rootState;
|
|
91
|
+
constructor(opts, root) {
|
|
92
|
+
this.opts = opts;
|
|
93
|
+
this.rootState = root;
|
|
94
|
+
this.attachment = attachRef(opts.ref, (ref) => {
|
|
95
|
+
if (!ref)
|
|
96
|
+
return;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
props = $derived.by(() => ({
|
|
100
|
+
id: this.opts.id.current,
|
|
101
|
+
[SLOT_ATTR_NAME]: SLOT_ATTR_VALUES.row,
|
|
102
|
+
...this.attachment,
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
export class DataTableBodyState {
|
|
106
|
+
static create(opts) {
|
|
107
|
+
return new DataTableBodyState(opts, DataTableRootContext.get());
|
|
108
|
+
}
|
|
109
|
+
opts;
|
|
110
|
+
attachment;
|
|
111
|
+
rootState;
|
|
112
|
+
#lastRow = $state(null);
|
|
113
|
+
constructor(opts, root) {
|
|
114
|
+
this.opts = opts;
|
|
115
|
+
this.rootState = root;
|
|
116
|
+
this.attachment = attachRef(opts.ref);
|
|
117
|
+
const { stop } = useMutationObserver(() => opts.ref.current, (mutations) => {
|
|
118
|
+
const target = mutations[mutations.length - 1].target;
|
|
119
|
+
this.#lastRow = target.lastElementChild;
|
|
120
|
+
}, { childList: true, subtree: true });
|
|
121
|
+
let observer = null;
|
|
122
|
+
watch.pre(() => this.#lastRow, () => {
|
|
123
|
+
if (!this.#lastRow || this.rootState.opts.table.current.features?.isLoading)
|
|
124
|
+
return;
|
|
125
|
+
observer = this.#rowObserver();
|
|
126
|
+
});
|
|
127
|
+
$effect.pre(() => {
|
|
128
|
+
return () => {
|
|
129
|
+
stop();
|
|
130
|
+
observer?.disconnect();
|
|
131
|
+
observer = null;
|
|
132
|
+
this.#lastRow = null;
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
#rowObserver = () => {
|
|
137
|
+
const observer = new IntersectionObserver((entries) => {
|
|
138
|
+
const entry = entries[0];
|
|
139
|
+
if (entry.isIntersecting) {
|
|
140
|
+
this.rootState.opts.table.current?.features?.onLastRowReached?.();
|
|
141
|
+
if (this.#lastRow) {
|
|
142
|
+
observer.unobserve(this.#lastRow);
|
|
143
|
+
this.#lastRow = null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}, {
|
|
147
|
+
root: this.rootState.opts.ref.current,
|
|
148
|
+
threshold: 0.5,
|
|
149
|
+
});
|
|
150
|
+
if (this.#lastRow) {
|
|
151
|
+
observer.observe(this.#lastRow);
|
|
152
|
+
}
|
|
153
|
+
return observer;
|
|
154
|
+
};
|
|
155
|
+
props = $derived.by(() => ({
|
|
156
|
+
id: this.opts.id.current,
|
|
157
|
+
[SLOT_ATTR_NAME]: SLOT_ATTR_VALUES.body,
|
|
158
|
+
...this.attachment,
|
|
159
|
+
}));
|
|
160
|
+
}
|
|
161
|
+
export class DataTableHeadState {
|
|
162
|
+
static create(opts) {
|
|
163
|
+
return DataTableHeadContext.set(new DataTableHeadState(opts, DataTableRootContext.get()));
|
|
164
|
+
}
|
|
165
|
+
opts;
|
|
166
|
+
attachment;
|
|
167
|
+
rootState;
|
|
168
|
+
constructor(opts, root) {
|
|
169
|
+
this.opts = opts;
|
|
170
|
+
this.rootState = root;
|
|
171
|
+
this.attachment = attachRef(opts.ref);
|
|
172
|
+
}
|
|
173
|
+
#width = $derived.by(() => this.rootState.columnSizingVars[`--header-${this.opts.header.current.id}-size`]);
|
|
174
|
+
props = $derived.by(() => ({
|
|
175
|
+
id: this.opts.id.current,
|
|
176
|
+
[SLOT_ATTR_NAME]: SLOT_ATTR_VALUES.head,
|
|
177
|
+
'data-id': this.opts.header.current.id,
|
|
178
|
+
style: {
|
|
179
|
+
width: `calc(${this.#width} * 1px)`,
|
|
180
|
+
},
|
|
181
|
+
colspan: this.opts.header.current.colSpan,
|
|
182
|
+
...this.attachment,
|
|
183
|
+
}));
|
|
184
|
+
}
|
|
185
|
+
export class DataTableCellState {
|
|
186
|
+
static create(opts) {
|
|
187
|
+
return new DataTableCellState(opts, DataTableRootContext.get());
|
|
188
|
+
}
|
|
189
|
+
opts;
|
|
190
|
+
attachment;
|
|
191
|
+
rootState;
|
|
192
|
+
constructor(opts, root) {
|
|
193
|
+
this.opts = opts;
|
|
194
|
+
this.rootState = root;
|
|
195
|
+
this.attachment = attachRef(opts.ref);
|
|
196
|
+
}
|
|
197
|
+
#width = $derived.by(() => this.rootState.columnSizingVars[`--col-${this.opts.cell.current?.column.id}-size`]);
|
|
198
|
+
props = $derived.by(() => ({
|
|
199
|
+
id: this.opts.id.current,
|
|
200
|
+
[SLOT_ATTR_NAME]: SLOT_ATTR_VALUES.cell,
|
|
201
|
+
style: {
|
|
202
|
+
width: `calc(${this.#width} * 1px)`,
|
|
203
|
+
},
|
|
204
|
+
...this.attachment,
|
|
205
|
+
}));
|
|
206
|
+
}
|
|
207
|
+
export class DataTableSortButtonState {
|
|
208
|
+
static create(opts) {
|
|
209
|
+
return new DataTableSortButtonState(opts, DataTableHeadContext.get());
|
|
210
|
+
}
|
|
211
|
+
opts;
|
|
212
|
+
attachment;
|
|
213
|
+
headState;
|
|
214
|
+
constructor(opts, head) {
|
|
215
|
+
this.opts = opts;
|
|
216
|
+
this.headState = head;
|
|
217
|
+
this.attachment = attachRef(opts.ref);
|
|
218
|
+
}
|
|
219
|
+
props = $derived.by(() => ({
|
|
220
|
+
id: this.opts.id.current,
|
|
221
|
+
...this.attachment,
|
|
222
|
+
[SLOT_ATTR_NAME]: SLOT_ATTR_VALUES.sortButton,
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
export class DataTableResizeHandlerState {
|
|
226
|
+
static create(opts) {
|
|
227
|
+
return new DataTableResizeHandlerState(opts, DataTableHeadContext.get());
|
|
228
|
+
}
|
|
229
|
+
opts;
|
|
230
|
+
attachment;
|
|
231
|
+
headState;
|
|
232
|
+
constructor(opts, head) {
|
|
233
|
+
this.opts = opts;
|
|
234
|
+
this.headState = head;
|
|
235
|
+
this.attachment = attachRef(opts.ref);
|
|
236
|
+
}
|
|
237
|
+
#onDoubleClick = () => {
|
|
238
|
+
return this.headState.opts.header.current.column.resetSize();
|
|
239
|
+
};
|
|
240
|
+
props = $derived.by(() => ({
|
|
241
|
+
id: this.opts.id.current,
|
|
242
|
+
[SLOT_ATTR_NAME]: SLOT_ATTR_VALUES.resizeHandler,
|
|
243
|
+
ondblclick: this.#onDoubleClick,
|
|
244
|
+
onmousedown: this.headState.opts.header.current.getResizeHandler(),
|
|
245
|
+
ontouchstart: this.headState.opts.header.current.getResizeHandler(),
|
|
246
|
+
...this.attachment,
|
|
247
|
+
}));
|
|
248
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
type DataTableTablePropsWithoutHTML = WithElementRef<WithChildren<{}>>;
|
|
3
|
+
|
|
4
|
+
export type DataTableTableProps = DataTableTablePropsWithoutHTML &
|
|
5
|
+
Without<PrimitiveTableAttributes, DataTableTablePropsWithoutHTML>;
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import type { PrimitiveTableAttributes } from '../../../internal/types/html-attributes.js';
|
|
10
|
+
import { cn } from '../../../internal/utils/common.js';
|
|
11
|
+
import { useId, type Without } from 'bits-ui';
|
|
12
|
+
import { box, mergeProps, type WithChildren, type WithElementRef } from 'svelte-toolbelt';
|
|
13
|
+
import { DataTableStylesContext } from '../styles.js';
|
|
14
|
+
import { DataTableTableState } from './data-table.svelte.js';
|
|
15
|
+
|
|
16
|
+
let { ref = $bindable(null), id = useId(), children, class: className, ...restProps }: DataTableTableProps = $props();
|
|
17
|
+
|
|
18
|
+
const rootState = DataTableTableState.create({
|
|
19
|
+
id: box.with(() => id),
|
|
20
|
+
ref: box.with(
|
|
21
|
+
() => ref,
|
|
22
|
+
(v) => (ref = v)
|
|
23
|
+
),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const variants = DataTableStylesContext.get();
|
|
27
|
+
|
|
28
|
+
const mergedProps = $derived(mergeProps(restProps, rootState.props));
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<table class={cn(variants.current.table(), className)} {...mergedProps}>
|
|
32
|
+
{@render children?.()}
|
|
33
|
+
</table>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type DataTableTablePropsWithoutHTML = WithElementRef<WithChildren<{}>>;
|
|
2
|
+
export type DataTableTableProps = DataTableTablePropsWithoutHTML & Without<PrimitiveTableAttributes, DataTableTablePropsWithoutHTML>;
|
|
3
|
+
import type { PrimitiveTableAttributes } from '../../../internal/types/html-attributes.js';
|
|
4
|
+
import { type Without } from 'bits-ui';
|
|
5
|
+
import { type WithChildren, type WithElementRef } from 'svelte-toolbelt';
|
|
6
|
+
declare const DataTable: import("svelte").Component<DataTableTableProps, {}, "ref">;
|
|
7
|
+
type DataTable = ReturnType<typeof DataTable>;
|
|
8
|
+
export default DataTable;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<script lang="ts" generics="TData, TValue, TContext extends HeaderContext<TData, TValue> | CellContext<TData, TValue>">
|
|
2
|
+
import type { CellContext, ColumnDefTemplate, HeaderContext } from '@tanstack/table-core';
|
|
3
|
+
import { RenderComponentConfig, RenderSnippetConfig } from '../utils/render-helper.js';
|
|
4
|
+
type Props = {
|
|
5
|
+
/** The cell or header field of the current cell's column definition. */
|
|
6
|
+
content?: TContext extends HeaderContext<TData, TValue>
|
|
7
|
+
? ColumnDefTemplate<HeaderContext<TData, TValue>>
|
|
8
|
+
: TContext extends CellContext<TData, TValue>
|
|
9
|
+
? ColumnDefTemplate<CellContext<TData, TValue>>
|
|
10
|
+
: never;
|
|
11
|
+
/** The result of the `getContext()` function of the header or cell */
|
|
12
|
+
context: TContext;
|
|
13
|
+
};
|
|
14
|
+
let { content, context }: Props = $props();
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
{#if typeof content === 'string'}
|
|
18
|
+
{content}
|
|
19
|
+
{:else if content instanceof Function}
|
|
20
|
+
<!-- It's unlikely that a CellContext will be passed to a Header -->
|
|
21
|
+
<!-- eslint-disable-next-line @typescript-eslint/no-explicit-any -->
|
|
22
|
+
{@const result = content(context as any)}
|
|
23
|
+
{#if result instanceof RenderComponentConfig}
|
|
24
|
+
{@const { component: Component, props } = result}
|
|
25
|
+
<Component {...props} />
|
|
26
|
+
{:else if result instanceof RenderSnippetConfig}
|
|
27
|
+
{@const { snippet, params } = result}
|
|
28
|
+
{@render snippet(params)}
|
|
29
|
+
{:else}
|
|
30
|
+
{result}
|
|
31
|
+
{/if}
|
|
32
|
+
{/if}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { CellContext, ColumnDefTemplate, HeaderContext } from '@tanstack/table-core';
|
|
2
|
+
declare function $$render<TData, TValue, TContext extends HeaderContext<TData, TValue> | CellContext<TData, TValue>>(): {
|
|
3
|
+
props: {
|
|
4
|
+
/** The cell or header field of the current cell's column definition. */
|
|
5
|
+
content?: TContext extends HeaderContext<TData, TValue> ? ColumnDefTemplate<HeaderContext<TData, TValue>> : TContext extends CellContext<TData, TValue> ? ColumnDefTemplate<CellContext<TData, TValue>> : never;
|
|
6
|
+
/** The result of the `getContext()` function of the header or cell */
|
|
7
|
+
context: TContext;
|
|
8
|
+
};
|
|
9
|
+
exports: {};
|
|
10
|
+
bindings: "";
|
|
11
|
+
slots: {};
|
|
12
|
+
events: {};
|
|
13
|
+
};
|
|
14
|
+
declare class __sveltets_Render<TData, TValue, TContext extends HeaderContext<TData, TValue> | CellContext<TData, TValue>> {
|
|
15
|
+
props(): ReturnType<typeof $$render<TData, TValue, TContext>>['props'];
|
|
16
|
+
events(): ReturnType<typeof $$render<TData, TValue, TContext>>['events'];
|
|
17
|
+
slots(): ReturnType<typeof $$render<TData, TValue, TContext>>['slots'];
|
|
18
|
+
bindings(): "";
|
|
19
|
+
exports(): {};
|
|
20
|
+
}
|
|
21
|
+
interface $$IsomorphicComponent {
|
|
22
|
+
new <TData, TValue, TContext extends HeaderContext<TData, TValue> | CellContext<TData, TValue>>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TData, TValue, TContext>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TData, TValue, TContext>['props']>, ReturnType<__sveltets_Render<TData, TValue, TContext>['events']>, ReturnType<__sveltets_Render<TData, TValue, TContext>['slots']>> & {
|
|
23
|
+
$$bindings?: ReturnType<__sveltets_Render<TData, TValue, TContext>['bindings']>;
|
|
24
|
+
} & ReturnType<__sveltets_Render<TData, TValue, TContext>['exports']>;
|
|
25
|
+
<TData, TValue, TContext extends HeaderContext<TData, TValue> | CellContext<TData, TValue>>(internal: unknown, props: ReturnType<__sveltets_Render<TData, TValue, TContext>['props']> & {}): ReturnType<__sveltets_Render<TData, TValue, TContext>['exports']>;
|
|
26
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any, any, any>['bindings']>;
|
|
27
|
+
}
|
|
28
|
+
declare const FlexRender: $$IsomorphicComponent;
|
|
29
|
+
type FlexRender<TData, TValue, TContext extends HeaderContext<TData, TValue> | CellContext<TData, TValue>> = InstanceType<typeof FlexRender<TData, TValue, TContext>>;
|
|
30
|
+
export default FlexRender;
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { ColumnDef } from './types.js';
|
|
3
|
+
import { MOCK_DATA_TABLE } from '../../internal/mocks/data-table.js';
|
|
4
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
5
|
+
import type { Parameters } from '@storybook/sveltekit';
|
|
6
|
+
import { untrack, type ComponentProps } from 'svelte';
|
|
7
|
+
import { Pagination } from '../pagination/index.js';
|
|
8
|
+
import DataTableRoot from './components/data-table.root.svelte';
|
|
9
|
+
import { createTable, DataTable, DataTablePrimitive } from './index.js';
|
|
10
|
+
import { rowModels, usePaginationState, useResizeState } from './utils/index.js';
|
|
11
|
+
|
|
12
|
+
const parameters: Parameters = {
|
|
13
|
+
controls: {
|
|
14
|
+
include: ['table', 'resizable', 'rounded', 'align', 'stripped'],
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const { Story } = defineMeta({
|
|
19
|
+
title: 'UI Kit/DataTable',
|
|
20
|
+
component: DataTableRoot<(typeof MOCK_DATA_TABLE)[0]>,
|
|
21
|
+
tags: ['autodocs'],
|
|
22
|
+
parameters,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
type Args = ComponentProps<typeof DataTableRoot<(typeof MOCK_DATA_TABLE)[0]>>;
|
|
26
|
+
|
|
27
|
+
const args: Omit<Args, 'table'> = {
|
|
28
|
+
resizable: false,
|
|
29
|
+
rounded: 'md',
|
|
30
|
+
variant: 'primary',
|
|
31
|
+
align: 'start',
|
|
32
|
+
stripped: true,
|
|
33
|
+
};
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<script lang="ts">
|
|
37
|
+
const columns: ColumnDef<(typeof MOCK_DATA_TABLE)[0]>[] = [
|
|
38
|
+
{
|
|
39
|
+
accessorKey: 'id',
|
|
40
|
+
header: 'ID',
|
|
41
|
+
|
|
42
|
+
enableSorting: false,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
accessorKey: 'first_name',
|
|
46
|
+
header: 'First Name',
|
|
47
|
+
|
|
48
|
+
enableSorting: false,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
accessorKey: 'last_name',
|
|
52
|
+
header: 'Last Name',
|
|
53
|
+
|
|
54
|
+
enableSorting: false,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
accessorKey: 'email',
|
|
58
|
+
header: 'Email',
|
|
59
|
+
|
|
60
|
+
enableSorting: true,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
accessorKey: 'gender',
|
|
64
|
+
header: 'Gender',
|
|
65
|
+
|
|
66
|
+
enableSorting: true,
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
accessorKey: 'ip_address',
|
|
70
|
+
header: 'IP Address',
|
|
71
|
+
|
|
72
|
+
enableSorting: false,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
accessorKey: 'Bank',
|
|
76
|
+
header: 'Bank',
|
|
77
|
+
|
|
78
|
+
enableSorting: false,
|
|
79
|
+
},
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
const primitiveTable = createTable({
|
|
83
|
+
get data() {
|
|
84
|
+
return MOCK_DATA_TABLE;
|
|
85
|
+
},
|
|
86
|
+
columns,
|
|
87
|
+
|
|
88
|
+
getCoreRowModel: rowModels.coreRowModel(),
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const paginationState = usePaginationState();
|
|
92
|
+
|
|
93
|
+
const basicPresetTable = createTable({
|
|
94
|
+
get data() {
|
|
95
|
+
return MOCK_DATA_TABLE;
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
columns,
|
|
99
|
+
getCoreRowModel: rowModels.coreRowModel(),
|
|
100
|
+
getPaginationRowModel: rowModels.paginationRowModel(),
|
|
101
|
+
|
|
102
|
+
state: {
|
|
103
|
+
get pagination() {
|
|
104
|
+
return paginationState.value;
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
columnResizeMode: 'onChange',
|
|
109
|
+
|
|
110
|
+
onPaginationChange: paginationState.updater,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
type RemoteData = {
|
|
114
|
+
id: number;
|
|
115
|
+
title: string;
|
|
116
|
+
body: string;
|
|
117
|
+
userId: number;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
type CatData = {
|
|
121
|
+
id: string;
|
|
122
|
+
url: string;
|
|
123
|
+
width: number;
|
|
124
|
+
height: number;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const remoteColumns: ColumnDef<RemoteData>[] = [
|
|
128
|
+
{ accessorKey: 'id', header: 'ID' },
|
|
129
|
+
{ accessorKey: 'title', header: 'Title' },
|
|
130
|
+
// { accessorKey: 'body', header: 'Body' },
|
|
131
|
+
// { accessorKey: 'userId', header: 'User ID' },
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
let remoteData = $state<RemoteData[]>([]);
|
|
135
|
+
|
|
136
|
+
const remoteDataPagination = usePaginationState();
|
|
137
|
+
const remoteDataResize = useResizeState();
|
|
138
|
+
|
|
139
|
+
const remoteDataTable = createTable({
|
|
140
|
+
get data() {
|
|
141
|
+
return remoteData;
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
columns: remoteColumns,
|
|
145
|
+
|
|
146
|
+
getCoreRowModel: rowModels.coreRowModel(),
|
|
147
|
+
getPaginationRowModel: rowModels.paginationRowModel(),
|
|
148
|
+
|
|
149
|
+
columnResizeMode: 'onChange',
|
|
150
|
+
|
|
151
|
+
state: {
|
|
152
|
+
get pagination() {
|
|
153
|
+
return remoteDataPagination.value;
|
|
154
|
+
},
|
|
155
|
+
get columnSizing() {
|
|
156
|
+
return remoteDataResize.value;
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
onPaginationChange: remoteDataPagination.updater,
|
|
161
|
+
onColumnSizingChange: remoteDataResize.updater,
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
let catsIsLoaded = $state(false);
|
|
165
|
+
let catsIsLoading = $state(false);
|
|
166
|
+
let catsData = $state<CatData[]>([]);
|
|
167
|
+
let catsPage = $state(1);
|
|
168
|
+
let catsLimit = $state(20);
|
|
169
|
+
|
|
170
|
+
const infiniteColumns: ColumnDef<CatData>[] = [
|
|
171
|
+
{ accessorKey: 'id', header: 'ID' },
|
|
172
|
+
{ accessorKey: 'url', header: 'URL' },
|
|
173
|
+
{ accessorKey: 'width', header: 'Width' },
|
|
174
|
+
{ accessorKey: 'height', header: 'Height' },
|
|
175
|
+
];
|
|
176
|
+
|
|
177
|
+
async function fetchCatData(page = 1, limit = 20) {
|
|
178
|
+
catsIsLoading = true;
|
|
179
|
+
const res = await fetch(`https://api.thecatapi.com/v1/images/search?limit=${limit}&page=${page}`, {
|
|
180
|
+
headers: {
|
|
181
|
+
'Content-Type': 'application/json',
|
|
182
|
+
'x-api-key': 'live_V1XvjJ84eY5LPP29tbKPJXDiRFPg0WgkDjRtCsocndgnNrVtiUDP25W9rp3QuwbX',
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const data = (await res.json()) as CatData[];
|
|
187
|
+
|
|
188
|
+
const newData = new Map(catsData.map((item) => [item.id, item]));
|
|
189
|
+
|
|
190
|
+
data.forEach((item) => {
|
|
191
|
+
newData.set(item.id, item);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
catsData = Array.from(newData.values());
|
|
195
|
+
catsIsLoaded = true;
|
|
196
|
+
catsIsLoading = false;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const infiniteResize = useResizeState();
|
|
200
|
+
|
|
201
|
+
const infiniteTable = createTable({
|
|
202
|
+
get data() {
|
|
203
|
+
return catsData;
|
|
204
|
+
},
|
|
205
|
+
|
|
206
|
+
columns: infiniteColumns,
|
|
207
|
+
|
|
208
|
+
defaultColumn: {
|
|
209
|
+
minSize: 100,
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
state: {
|
|
213
|
+
get columnSizing() {
|
|
214
|
+
return infiniteResize.value;
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
|
|
218
|
+
getCoreRowModel: rowModels.coreRowModel(),
|
|
219
|
+
|
|
220
|
+
columnResizeMode: 'onChange',
|
|
221
|
+
|
|
222
|
+
onColumnSizingChange: infiniteResize.updater,
|
|
223
|
+
|
|
224
|
+
features: {
|
|
225
|
+
onLastRowReached: () => {
|
|
226
|
+
catsPage++;
|
|
227
|
+
fetchCatData(catsPage, catsLimit);
|
|
228
|
+
},
|
|
229
|
+
|
|
230
|
+
get isLoading() {
|
|
231
|
+
return catsIsLoading;
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
$effect(() => {
|
|
237
|
+
untrack(() => {
|
|
238
|
+
fetch('https://jsonplaceholder.typicode.com/posts')
|
|
239
|
+
.then((res) => res.json())
|
|
240
|
+
.then((data) => {
|
|
241
|
+
remoteData = data;
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
if (!catsIsLoaded) {
|
|
246
|
+
untrack(() => {
|
|
247
|
+
fetchCatData(catsPage, catsLimit);
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
</script>
|
|
252
|
+
|
|
253
|
+
<Story name="Primitive" {args}>
|
|
254
|
+
{#snippet template(args: Args)}
|
|
255
|
+
<div class="cgui:w-full">
|
|
256
|
+
<DataTablePrimitive.Root {...args} table={primitiveTable}>
|
|
257
|
+
<DataTablePrimitive.Table>
|
|
258
|
+
<DataTablePrimitive.Header>
|
|
259
|
+
{#each primitiveTable.getHeaderGroups() as headerGroup (headerGroup.id)}
|
|
260
|
+
<DataTablePrimitive.Row>
|
|
261
|
+
{#each headerGroup.headers as header (header.id)}
|
|
262
|
+
<DataTablePrimitive.Head {header}>
|
|
263
|
+
{#if !header.isPlaceholder}
|
|
264
|
+
<DataTablePrimitive.FlexRender
|
|
265
|
+
content={header.column.columnDef.header}
|
|
266
|
+
context={header.getContext()}
|
|
267
|
+
/>
|
|
268
|
+
|
|
269
|
+
{#if header.column.getCanSort()}
|
|
270
|
+
<DataTablePrimitive.SortButton />
|
|
271
|
+
{/if}
|
|
272
|
+
|
|
273
|
+
{#if args.resizable && header.column.getCanResize()}
|
|
274
|
+
<DataTablePrimitive.ResizeHandler />
|
|
275
|
+
{/if}
|
|
276
|
+
{/if}
|
|
277
|
+
</DataTablePrimitive.Head>
|
|
278
|
+
{/each}
|
|
279
|
+
</DataTablePrimitive.Row>
|
|
280
|
+
{/each}
|
|
281
|
+
</DataTablePrimitive.Header>
|
|
282
|
+
|
|
283
|
+
<DataTablePrimitive.Body>
|
|
284
|
+
{#each primitiveTable.getRowModel().rows as row}
|
|
285
|
+
<DataTablePrimitive.Row>
|
|
286
|
+
{#each row.getVisibleCells() as cell}
|
|
287
|
+
<DataTablePrimitive.Cell {cell}>
|
|
288
|
+
<DataTablePrimitive.FlexRender content={cell.column.columnDef.cell} context={cell.getContext()} />
|
|
289
|
+
</DataTablePrimitive.Cell>
|
|
290
|
+
{/each}
|
|
291
|
+
</DataTablePrimitive.Row>
|
|
292
|
+
{/each}
|
|
293
|
+
</DataTablePrimitive.Body>
|
|
294
|
+
</DataTablePrimitive.Table>
|
|
295
|
+
</DataTablePrimitive.Root>
|
|
296
|
+
</div>
|
|
297
|
+
{/snippet}
|
|
298
|
+
</Story>
|
|
299
|
+
|
|
300
|
+
<Story name="Basic Preset" {args}>
|
|
301
|
+
{#snippet template(args: Args)}
|
|
302
|
+
<div class="cgui:flex cgui:flex-col cgui:gap-4">
|
|
303
|
+
<DataTable {...args} table={basicPresetTable} />
|
|
304
|
+
|
|
305
|
+
<Pagination.Basic
|
|
306
|
+
bind:page={
|
|
307
|
+
() => basicPresetTable.getState().pagination.pageIndex + 1,
|
|
308
|
+
(value) => basicPresetTable.setPageIndex(value - 1)
|
|
309
|
+
}
|
|
310
|
+
count={MOCK_DATA_TABLE.length}
|
|
311
|
+
perPage={basicPresetTable.getState().pagination.pageSize}
|
|
312
|
+
siblingCount={1}
|
|
313
|
+
orientation="horizontal"
|
|
314
|
+
size="md"
|
|
315
|
+
centered={true}
|
|
316
|
+
/>
|
|
317
|
+
</div>
|
|
318
|
+
{/snippet}
|
|
319
|
+
</Story>
|
|
320
|
+
|
|
321
|
+
<Story name="Infinite" {args}>
|
|
322
|
+
{#snippet template(args: Args)}
|
|
323
|
+
<div class="cgui:flex cgui:flex-col cgui:gap-4">
|
|
324
|
+
<DataTable {...args} table={infiniteTable} resizable class="cgui:h-[300px]" />
|
|
325
|
+
</div>
|
|
326
|
+
{/snippet}
|
|
327
|
+
</Story>
|