@dynostack/react-grid 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +305 -18
- package/dist/index.cjs +375 -97
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +142 -43
- package/dist/index.d.ts +142 -43
- package/dist/index.js +371 -99
- package/dist/index.js.map +1 -1
- package/dist/page.css +24 -0
- package/dist/styles.css +145 -46
- package/package.json +4 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { RowData, ColumnDef, ColumnPinningState, VisibilityState, Column, Table, CellContext, FilterFn } from '@tanstack/react-table';
|
|
2
|
+
import { RowData, ColumnDef, SortingState, ColumnFiltersState, ColumnPinningState, VisibilityState, Column, Table, CellContext, FilterFn } from '@tanstack/react-table';
|
|
3
3
|
import { CSSProperties } from 'react';
|
|
4
4
|
|
|
5
5
|
type RowActionId = "view" | "edit" | "duplicate" | "delete" | string;
|
|
@@ -30,7 +30,7 @@ declare function DataTableRowActions<TData>({ row, actions, customActions, onAct
|
|
|
30
30
|
* values are emitted as inline CSS variables on the table root, scoped
|
|
31
31
|
* through CSS cascade to that instance only.
|
|
32
32
|
*/
|
|
33
|
-
type
|
|
33
|
+
type DataTableTokens = {
|
|
34
34
|
background?: string;
|
|
35
35
|
foreground?: string;
|
|
36
36
|
card?: string;
|
|
@@ -55,51 +55,90 @@ type DataTableTheme = {
|
|
|
55
55
|
/** Font family for the table body. */
|
|
56
56
|
fontFamily?: string;
|
|
57
57
|
};
|
|
58
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* A theme passed to `<DataTable theme={…}>`.
|
|
60
|
+
*
|
|
61
|
+
* Two accepted shapes:
|
|
62
|
+
*
|
|
63
|
+
* 1. A flat token map (`DataTableTokens`) — applied as-is, no dark variant.
|
|
64
|
+
* 2. A moded map (`DataTableModedTheme`) — `light` is applied by default,
|
|
65
|
+
* `dark` is swapped in automatically inside `@media (prefers-color-scheme: dark)`
|
|
66
|
+
* *and* inside any `.dark` ancestor.
|
|
67
|
+
*/
|
|
68
|
+
type DataTableModedTheme = {
|
|
69
|
+
light?: DataTableTokens;
|
|
70
|
+
dark?: DataTableTokens;
|
|
71
|
+
};
|
|
72
|
+
type DataTableTheme = DataTableTokens | DataTableModedTheme;
|
|
73
|
+
/** Convert a DataTableTokens map into a CSS `style` object. */
|
|
74
|
+
declare function tokensToStyle(tokens?: DataTableTokens): CSSProperties;
|
|
75
|
+
/**
|
|
76
|
+
* Back-compat: original API accepted a flat `DataTableTheme`. Still works,
|
|
77
|
+
* but if a moded theme is passed it returns the `light` variant only — use
|
|
78
|
+
* `splitTheme` if you need both variants.
|
|
79
|
+
*/
|
|
59
80
|
declare function themeToStyle(theme?: DataTableTheme): CSSProperties;
|
|
60
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* Split a theme into its `light` (always applied) and optional `dark` (applied
|
|
83
|
+
* via `@media (prefers-color-scheme: dark)` and `.dark` ancestor) variants.
|
|
84
|
+
*
|
|
85
|
+
* For flat themes, returns `{ light: theme, dark: undefined }`.
|
|
86
|
+
*/
|
|
87
|
+
declare function splitTheme(theme?: DataTableTheme): {
|
|
88
|
+
light: DataTableTokens | undefined;
|
|
89
|
+
dark: DataTableTokens | undefined;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Build a full light+dark token set from a single OKLCH hue.
|
|
93
|
+
*
|
|
94
|
+
* @param hue Hue angle 0–360 (e.g. 285 for violet, 162 for emerald).
|
|
95
|
+
* @param chroma Optional base chroma for tinted neutrals (default 0.03).
|
|
96
|
+
*/
|
|
97
|
+
declare function buildPreset(hue: number, chroma?: number): DataTableModedTheme;
|
|
98
|
+
/**
|
|
99
|
+
* Convert a tokens map into a CSS declaration string (no selector, no braces),
|
|
100
|
+
* e.g. `--background:oklch(1 0 0);--foreground:oklch(0.145 0 0)`.
|
|
101
|
+
*
|
|
102
|
+
* Used internally to inject scoped <style> blocks for moded themes.
|
|
103
|
+
*/
|
|
104
|
+
declare function tokensToCssBlock(tokens?: DataTableTokens): string;
|
|
105
|
+
/**
|
|
106
|
+
* Ready-to-use theme presets.
|
|
107
|
+
*
|
|
108
|
+
* Each preset is a full light + dark token set — passing one to
|
|
109
|
+
* `<DataTable theme={…}>` repaints the entire table and auto-flips on OS
|
|
110
|
+
* dark mode (or when a `.dark` ancestor is added).
|
|
111
|
+
*
|
|
112
|
+
* Custom hues:
|
|
113
|
+
*
|
|
114
|
+
* ```ts
|
|
115
|
+
* import { buildPreset } from "@dynostack/react-grid"
|
|
116
|
+
* const tealPreset = buildPreset(180)
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
61
119
|
declare const themePresets: {
|
|
120
|
+
neutral: DataTableModedTheme;
|
|
62
121
|
light: {
|
|
63
|
-
|
|
64
|
-
foreground: string;
|
|
65
|
-
card: string;
|
|
66
|
-
cardForeground: string;
|
|
67
|
-
primary: string;
|
|
68
|
-
primaryForeground: string;
|
|
69
|
-
border: string;
|
|
122
|
+
light: DataTableTokens | undefined;
|
|
70
123
|
};
|
|
71
124
|
dark: {
|
|
72
|
-
|
|
73
|
-
foreground: string;
|
|
74
|
-
card: string;
|
|
75
|
-
cardForeground: string;
|
|
76
|
-
primary: string;
|
|
77
|
-
primaryForeground: string;
|
|
78
|
-
border: string;
|
|
79
|
-
};
|
|
80
|
-
emerald: {
|
|
81
|
-
primary: string;
|
|
82
|
-
primaryForeground: string;
|
|
83
|
-
accent: string;
|
|
84
|
-
accentForeground: string;
|
|
85
|
-
ring: string;
|
|
86
|
-
};
|
|
87
|
-
violet: {
|
|
88
|
-
primary: string;
|
|
89
|
-
primaryForeground: string;
|
|
90
|
-
accent: string;
|
|
91
|
-
accentForeground: string;
|
|
92
|
-
ring: string;
|
|
93
|
-
};
|
|
94
|
-
amber: {
|
|
95
|
-
primary: string;
|
|
96
|
-
primaryForeground: string;
|
|
97
|
-
accent: string;
|
|
98
|
-
accentForeground: string;
|
|
99
|
-
ring: string;
|
|
125
|
+
light: DataTableTokens | undefined;
|
|
100
126
|
};
|
|
127
|
+
violet: DataTableModedTheme;
|
|
128
|
+
emerald: DataTableModedTheme;
|
|
129
|
+
amber: DataTableModedTheme;
|
|
130
|
+
rose: DataTableModedTheme;
|
|
131
|
+
sky: DataTableModedTheme;
|
|
132
|
+
slate: DataTableModedTheme;
|
|
101
133
|
};
|
|
102
134
|
type DataTableThemeName = keyof typeof themePresets;
|
|
135
|
+
/**
|
|
136
|
+
* Bundled fallback tokens used when `<DataTable isolate>` is set. These let
|
|
137
|
+
* the grid render correctly even when the consumer hasn't imported
|
|
138
|
+
* `styles.css` or provided any theme of their own.
|
|
139
|
+
*/
|
|
140
|
+
declare const ISOLATE_LIGHT_TOKENS: DataTableTokens;
|
|
141
|
+
declare const ISOLATE_DARK_TOKENS: DataTableTokens;
|
|
103
142
|
|
|
104
143
|
type CellEditorType = "text" | "number" | "currency" | "date" | "select" | "switch" | "checkbox";
|
|
105
144
|
type FilterType = "text" | "number" | "select" | "multi-select" | "boolean" | "date";
|
|
@@ -168,17 +207,54 @@ type DataTableLabels = {
|
|
|
168
207
|
total?: string;
|
|
169
208
|
noData?: string;
|
|
170
209
|
noResults?: string;
|
|
210
|
+
loadError?: string;
|
|
211
|
+
retry?: string;
|
|
171
212
|
refreshing?: string;
|
|
172
213
|
rowsPerPage?: string;
|
|
173
214
|
page?: string;
|
|
174
215
|
of?: string;
|
|
175
216
|
};
|
|
176
217
|
type DataTableDensity = "compact" | "default" | "comfortable";
|
|
218
|
+
type DataTableFetchParams = {
|
|
219
|
+
pageIndex: number;
|
|
220
|
+
pageSize: number;
|
|
221
|
+
sorting: SortingState;
|
|
222
|
+
columnFilters: ColumnFiltersState;
|
|
223
|
+
globalFilter: string;
|
|
224
|
+
};
|
|
225
|
+
type DataTableDataSourceResult<TData> = TData[] | {
|
|
226
|
+
rows: TData[];
|
|
227
|
+
totalRecords?: number;
|
|
228
|
+
};
|
|
229
|
+
type DataTableErrorContext = {
|
|
230
|
+
type: "load" | "refresh";
|
|
231
|
+
message: string;
|
|
232
|
+
};
|
|
233
|
+
type DataTableDataSource<TData> = {
|
|
234
|
+
/**
|
|
235
|
+
* Fetch rows internally. In "client" mode, return the full data set and the
|
|
236
|
+
* table applies client-side sort/filter/pagination. In "server" mode, return
|
|
237
|
+
* the current page and optionally `totalRecords`.
|
|
238
|
+
*/
|
|
239
|
+
fetchRows: (params: DataTableFetchParams) => Promise<DataTableDataSourceResult<TData>>;
|
|
240
|
+
/** "client" by default. Use "server" for API-side pagination/filter/sort. */
|
|
241
|
+
mode?: "client" | "server";
|
|
242
|
+
/** Set false to pause fetching. */
|
|
243
|
+
enabled?: boolean;
|
|
244
|
+
/** Optional rows to show before the first fetch resolves. */
|
|
245
|
+
initialData?: TData[];
|
|
246
|
+
/** Refetch when these external values change. Memoize this array. */
|
|
247
|
+
deps?: readonly unknown[];
|
|
248
|
+
/** Called for load/refresh errors so apps can show a toast. */
|
|
249
|
+
onError?: (error: unknown, context: DataTableErrorContext) => void;
|
|
250
|
+
};
|
|
177
251
|
type DataTableProps<TData extends {
|
|
178
252
|
id: string | number;
|
|
179
253
|
}> = {
|
|
180
|
-
data
|
|
254
|
+
data?: TData[];
|
|
181
255
|
columns: ColumnDef<TData>[];
|
|
256
|
+
/** Optional internal fetcher. Omit this when using controlled `data`. */
|
|
257
|
+
dataSource?: DataTableDataSource<TData>;
|
|
182
258
|
isLoading?: boolean;
|
|
183
259
|
isFetching?: boolean;
|
|
184
260
|
onRefresh?: () => void;
|
|
@@ -216,12 +292,35 @@ type DataTableProps<TData extends {
|
|
|
216
292
|
labels?: DataTableLabels;
|
|
217
293
|
/** Row + cell padding density. Defaults to "default". */
|
|
218
294
|
density?: DataTableDensity;
|
|
219
|
-
/**
|
|
295
|
+
/**
|
|
296
|
+
* CSS-variable overrides (shadcn-compatible) scoped to this instance.
|
|
297
|
+
*
|
|
298
|
+
* Two accepted shapes:
|
|
299
|
+
*
|
|
300
|
+
* theme={{ primary: "...", accent: "..." }} // flat tokens
|
|
301
|
+
* theme={{ light: { ... }, dark: { ... } }} // moded — auto-flips
|
|
302
|
+
*
|
|
303
|
+
* Moded themes apply `light` always and swap to `dark` inside
|
|
304
|
+
* `@media (prefers-color-scheme: dark)` *and* inside any `.dark` ancestor.
|
|
305
|
+
*
|
|
306
|
+
* Use `themePresets.violet` (or any preset) for a ready-made moded theme.
|
|
307
|
+
*/
|
|
220
308
|
theme?: DataTableTheme;
|
|
309
|
+
/**
|
|
310
|
+
* When `true`, the grid does NOT inherit CSS variables from the app's
|
|
311
|
+
* `:root` (shadcn, custom theme, etc.). Instead it renders with the
|
|
312
|
+
* package's bundled defaults (or whatever you pass via `theme`).
|
|
313
|
+
*
|
|
314
|
+
* Useful when embedding the grid inside a heavily-themed shell where you
|
|
315
|
+
* want the table to keep its own look regardless of surrounding context.
|
|
316
|
+
*
|
|
317
|
+
* Defaults to `false` (inherit app theme).
|
|
318
|
+
*/
|
|
319
|
+
isolate?: boolean;
|
|
221
320
|
};
|
|
222
321
|
declare function DataTable<TData extends {
|
|
223
322
|
id: string | number;
|
|
224
|
-
}>({ data, columns, isLoading, isFetching, onRefresh, totalRecords, exportFileName, enableSelection, renderSubRow, getSubRows, rowActions, customRowActions, onRowAction, onCellEdit, onRowSave, onAddRow, onBulkDelete, initialPageSize, pageSizeOptions, initialColumnPinning, initialColumnVisibility, globalFilter: globalFilterProp, onGlobalFilterChange, className, toolbarSlot, features, labels: labelsProp, density, theme, }: DataTableProps<TData>): react_jsx_runtime.JSX.Element;
|
|
323
|
+
}>({ data, columns, dataSource, isLoading, isFetching, onRefresh, totalRecords, exportFileName, enableSelection, renderSubRow, getSubRows, rowActions, customRowActions, onRowAction, onCellEdit, onRowSave, onAddRow, onBulkDelete, initialPageSize, pageSizeOptions, initialColumnPinning, initialColumnVisibility, globalFilter: globalFilterProp, onGlobalFilterChange, className, toolbarSlot, features, labels: labelsProp, density, theme, isolate, }: DataTableProps<TData>): react_jsx_runtime.JSX.Element;
|
|
225
324
|
|
|
226
325
|
type Props$2<TData, TValue> = {
|
|
227
326
|
column: Column<TData, TValue>;
|
|
@@ -313,4 +412,4 @@ declare function ColumnFilterPanel<TData, TValue>(props: CommonProps<TData, TVal
|
|
|
313
412
|
declare function exportToCsv<TData>(table: Table<TData>, fileName?: string): void;
|
|
314
413
|
declare function exportToExcel<TData>(table: Table<TData>, fileName?: string): void;
|
|
315
414
|
|
|
316
|
-
export { type AdvFilter, type CellEditorType, ColumnFilterPanel, type Combine, type Condition, type CustomRowAction, DataTable, type DataTableColumn, DataTableColumnHeader, type DataTableDensity, type DataTableFeatures, type DataTableLabels, DataTablePagination, type DataTableProps, DataTableRowActions, type DataTableRowActionsProps, type DataTableTheme, type DataTableThemeName, DataTableToolbar, type DateOp, EditableCell, type FilterType, type NumberOp, type RowAction, type RowActionId, type SelectOption, type SetFilter, type TextOp, booleanFilterFn, dateFilterFn, exportToCsv, exportToExcel, isFilterActive, numberFilterFn, setFilterFn, textFilterFn, themePresets, themeToStyle };
|
|
415
|
+
export { type AdvFilter, type CellEditorType, ColumnFilterPanel, type Combine, type Condition, type CustomRowAction, DataTable, type DataTableColumn, DataTableColumnHeader, type DataTableDataSource, type DataTableDataSourceResult, type DataTableDensity, type DataTableErrorContext, type DataTableFeatures, type DataTableFetchParams, type DataTableLabels, type DataTableModedTheme, DataTablePagination, type DataTableProps, DataTableRowActions, type DataTableRowActionsProps, type DataTableTheme, type DataTableThemeName, type DataTableTokens, DataTableToolbar, type DateOp, EditableCell, type FilterType, ISOLATE_DARK_TOKENS, ISOLATE_LIGHT_TOKENS, type NumberOp, type RowAction, type RowActionId, type SelectOption, type SetFilter, type TextOp, booleanFilterFn, buildPreset, dateFilterFn, exportToCsv, exportToExcel, isFilterActive, numberFilterFn, setFilterFn, splitTheme, textFilterFn, themePresets, themeToStyle, tokensToCssBlock, tokensToStyle };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { RowData, ColumnDef, ColumnPinningState, VisibilityState, Column, Table, CellContext, FilterFn } from '@tanstack/react-table';
|
|
2
|
+
import { RowData, ColumnDef, SortingState, ColumnFiltersState, ColumnPinningState, VisibilityState, Column, Table, CellContext, FilterFn } from '@tanstack/react-table';
|
|
3
3
|
import { CSSProperties } from 'react';
|
|
4
4
|
|
|
5
5
|
type RowActionId = "view" | "edit" | "duplicate" | "delete" | string;
|
|
@@ -30,7 +30,7 @@ declare function DataTableRowActions<TData>({ row, actions, customActions, onAct
|
|
|
30
30
|
* values are emitted as inline CSS variables on the table root, scoped
|
|
31
31
|
* through CSS cascade to that instance only.
|
|
32
32
|
*/
|
|
33
|
-
type
|
|
33
|
+
type DataTableTokens = {
|
|
34
34
|
background?: string;
|
|
35
35
|
foreground?: string;
|
|
36
36
|
card?: string;
|
|
@@ -55,51 +55,90 @@ type DataTableTheme = {
|
|
|
55
55
|
/** Font family for the table body. */
|
|
56
56
|
fontFamily?: string;
|
|
57
57
|
};
|
|
58
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* A theme passed to `<DataTable theme={…}>`.
|
|
60
|
+
*
|
|
61
|
+
* Two accepted shapes:
|
|
62
|
+
*
|
|
63
|
+
* 1. A flat token map (`DataTableTokens`) — applied as-is, no dark variant.
|
|
64
|
+
* 2. A moded map (`DataTableModedTheme`) — `light` is applied by default,
|
|
65
|
+
* `dark` is swapped in automatically inside `@media (prefers-color-scheme: dark)`
|
|
66
|
+
* *and* inside any `.dark` ancestor.
|
|
67
|
+
*/
|
|
68
|
+
type DataTableModedTheme = {
|
|
69
|
+
light?: DataTableTokens;
|
|
70
|
+
dark?: DataTableTokens;
|
|
71
|
+
};
|
|
72
|
+
type DataTableTheme = DataTableTokens | DataTableModedTheme;
|
|
73
|
+
/** Convert a DataTableTokens map into a CSS `style` object. */
|
|
74
|
+
declare function tokensToStyle(tokens?: DataTableTokens): CSSProperties;
|
|
75
|
+
/**
|
|
76
|
+
* Back-compat: original API accepted a flat `DataTableTheme`. Still works,
|
|
77
|
+
* but if a moded theme is passed it returns the `light` variant only — use
|
|
78
|
+
* `splitTheme` if you need both variants.
|
|
79
|
+
*/
|
|
59
80
|
declare function themeToStyle(theme?: DataTableTheme): CSSProperties;
|
|
60
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* Split a theme into its `light` (always applied) and optional `dark` (applied
|
|
83
|
+
* via `@media (prefers-color-scheme: dark)` and `.dark` ancestor) variants.
|
|
84
|
+
*
|
|
85
|
+
* For flat themes, returns `{ light: theme, dark: undefined }`.
|
|
86
|
+
*/
|
|
87
|
+
declare function splitTheme(theme?: DataTableTheme): {
|
|
88
|
+
light: DataTableTokens | undefined;
|
|
89
|
+
dark: DataTableTokens | undefined;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Build a full light+dark token set from a single OKLCH hue.
|
|
93
|
+
*
|
|
94
|
+
* @param hue Hue angle 0–360 (e.g. 285 for violet, 162 for emerald).
|
|
95
|
+
* @param chroma Optional base chroma for tinted neutrals (default 0.03).
|
|
96
|
+
*/
|
|
97
|
+
declare function buildPreset(hue: number, chroma?: number): DataTableModedTheme;
|
|
98
|
+
/**
|
|
99
|
+
* Convert a tokens map into a CSS declaration string (no selector, no braces),
|
|
100
|
+
* e.g. `--background:oklch(1 0 0);--foreground:oklch(0.145 0 0)`.
|
|
101
|
+
*
|
|
102
|
+
* Used internally to inject scoped <style> blocks for moded themes.
|
|
103
|
+
*/
|
|
104
|
+
declare function tokensToCssBlock(tokens?: DataTableTokens): string;
|
|
105
|
+
/**
|
|
106
|
+
* Ready-to-use theme presets.
|
|
107
|
+
*
|
|
108
|
+
* Each preset is a full light + dark token set — passing one to
|
|
109
|
+
* `<DataTable theme={…}>` repaints the entire table and auto-flips on OS
|
|
110
|
+
* dark mode (or when a `.dark` ancestor is added).
|
|
111
|
+
*
|
|
112
|
+
* Custom hues:
|
|
113
|
+
*
|
|
114
|
+
* ```ts
|
|
115
|
+
* import { buildPreset } from "@dynostack/react-grid"
|
|
116
|
+
* const tealPreset = buildPreset(180)
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
61
119
|
declare const themePresets: {
|
|
120
|
+
neutral: DataTableModedTheme;
|
|
62
121
|
light: {
|
|
63
|
-
|
|
64
|
-
foreground: string;
|
|
65
|
-
card: string;
|
|
66
|
-
cardForeground: string;
|
|
67
|
-
primary: string;
|
|
68
|
-
primaryForeground: string;
|
|
69
|
-
border: string;
|
|
122
|
+
light: DataTableTokens | undefined;
|
|
70
123
|
};
|
|
71
124
|
dark: {
|
|
72
|
-
|
|
73
|
-
foreground: string;
|
|
74
|
-
card: string;
|
|
75
|
-
cardForeground: string;
|
|
76
|
-
primary: string;
|
|
77
|
-
primaryForeground: string;
|
|
78
|
-
border: string;
|
|
79
|
-
};
|
|
80
|
-
emerald: {
|
|
81
|
-
primary: string;
|
|
82
|
-
primaryForeground: string;
|
|
83
|
-
accent: string;
|
|
84
|
-
accentForeground: string;
|
|
85
|
-
ring: string;
|
|
86
|
-
};
|
|
87
|
-
violet: {
|
|
88
|
-
primary: string;
|
|
89
|
-
primaryForeground: string;
|
|
90
|
-
accent: string;
|
|
91
|
-
accentForeground: string;
|
|
92
|
-
ring: string;
|
|
93
|
-
};
|
|
94
|
-
amber: {
|
|
95
|
-
primary: string;
|
|
96
|
-
primaryForeground: string;
|
|
97
|
-
accent: string;
|
|
98
|
-
accentForeground: string;
|
|
99
|
-
ring: string;
|
|
125
|
+
light: DataTableTokens | undefined;
|
|
100
126
|
};
|
|
127
|
+
violet: DataTableModedTheme;
|
|
128
|
+
emerald: DataTableModedTheme;
|
|
129
|
+
amber: DataTableModedTheme;
|
|
130
|
+
rose: DataTableModedTheme;
|
|
131
|
+
sky: DataTableModedTheme;
|
|
132
|
+
slate: DataTableModedTheme;
|
|
101
133
|
};
|
|
102
134
|
type DataTableThemeName = keyof typeof themePresets;
|
|
135
|
+
/**
|
|
136
|
+
* Bundled fallback tokens used when `<DataTable isolate>` is set. These let
|
|
137
|
+
* the grid render correctly even when the consumer hasn't imported
|
|
138
|
+
* `styles.css` or provided any theme of their own.
|
|
139
|
+
*/
|
|
140
|
+
declare const ISOLATE_LIGHT_TOKENS: DataTableTokens;
|
|
141
|
+
declare const ISOLATE_DARK_TOKENS: DataTableTokens;
|
|
103
142
|
|
|
104
143
|
type CellEditorType = "text" | "number" | "currency" | "date" | "select" | "switch" | "checkbox";
|
|
105
144
|
type FilterType = "text" | "number" | "select" | "multi-select" | "boolean" | "date";
|
|
@@ -168,17 +207,54 @@ type DataTableLabels = {
|
|
|
168
207
|
total?: string;
|
|
169
208
|
noData?: string;
|
|
170
209
|
noResults?: string;
|
|
210
|
+
loadError?: string;
|
|
211
|
+
retry?: string;
|
|
171
212
|
refreshing?: string;
|
|
172
213
|
rowsPerPage?: string;
|
|
173
214
|
page?: string;
|
|
174
215
|
of?: string;
|
|
175
216
|
};
|
|
176
217
|
type DataTableDensity = "compact" | "default" | "comfortable";
|
|
218
|
+
type DataTableFetchParams = {
|
|
219
|
+
pageIndex: number;
|
|
220
|
+
pageSize: number;
|
|
221
|
+
sorting: SortingState;
|
|
222
|
+
columnFilters: ColumnFiltersState;
|
|
223
|
+
globalFilter: string;
|
|
224
|
+
};
|
|
225
|
+
type DataTableDataSourceResult<TData> = TData[] | {
|
|
226
|
+
rows: TData[];
|
|
227
|
+
totalRecords?: number;
|
|
228
|
+
};
|
|
229
|
+
type DataTableErrorContext = {
|
|
230
|
+
type: "load" | "refresh";
|
|
231
|
+
message: string;
|
|
232
|
+
};
|
|
233
|
+
type DataTableDataSource<TData> = {
|
|
234
|
+
/**
|
|
235
|
+
* Fetch rows internally. In "client" mode, return the full data set and the
|
|
236
|
+
* table applies client-side sort/filter/pagination. In "server" mode, return
|
|
237
|
+
* the current page and optionally `totalRecords`.
|
|
238
|
+
*/
|
|
239
|
+
fetchRows: (params: DataTableFetchParams) => Promise<DataTableDataSourceResult<TData>>;
|
|
240
|
+
/** "client" by default. Use "server" for API-side pagination/filter/sort. */
|
|
241
|
+
mode?: "client" | "server";
|
|
242
|
+
/** Set false to pause fetching. */
|
|
243
|
+
enabled?: boolean;
|
|
244
|
+
/** Optional rows to show before the first fetch resolves. */
|
|
245
|
+
initialData?: TData[];
|
|
246
|
+
/** Refetch when these external values change. Memoize this array. */
|
|
247
|
+
deps?: readonly unknown[];
|
|
248
|
+
/** Called for load/refresh errors so apps can show a toast. */
|
|
249
|
+
onError?: (error: unknown, context: DataTableErrorContext) => void;
|
|
250
|
+
};
|
|
177
251
|
type DataTableProps<TData extends {
|
|
178
252
|
id: string | number;
|
|
179
253
|
}> = {
|
|
180
|
-
data
|
|
254
|
+
data?: TData[];
|
|
181
255
|
columns: ColumnDef<TData>[];
|
|
256
|
+
/** Optional internal fetcher. Omit this when using controlled `data`. */
|
|
257
|
+
dataSource?: DataTableDataSource<TData>;
|
|
182
258
|
isLoading?: boolean;
|
|
183
259
|
isFetching?: boolean;
|
|
184
260
|
onRefresh?: () => void;
|
|
@@ -216,12 +292,35 @@ type DataTableProps<TData extends {
|
|
|
216
292
|
labels?: DataTableLabels;
|
|
217
293
|
/** Row + cell padding density. Defaults to "default". */
|
|
218
294
|
density?: DataTableDensity;
|
|
219
|
-
/**
|
|
295
|
+
/**
|
|
296
|
+
* CSS-variable overrides (shadcn-compatible) scoped to this instance.
|
|
297
|
+
*
|
|
298
|
+
* Two accepted shapes:
|
|
299
|
+
*
|
|
300
|
+
* theme={{ primary: "...", accent: "..." }} // flat tokens
|
|
301
|
+
* theme={{ light: { ... }, dark: { ... } }} // moded — auto-flips
|
|
302
|
+
*
|
|
303
|
+
* Moded themes apply `light` always and swap to `dark` inside
|
|
304
|
+
* `@media (prefers-color-scheme: dark)` *and* inside any `.dark` ancestor.
|
|
305
|
+
*
|
|
306
|
+
* Use `themePresets.violet` (or any preset) for a ready-made moded theme.
|
|
307
|
+
*/
|
|
220
308
|
theme?: DataTableTheme;
|
|
309
|
+
/**
|
|
310
|
+
* When `true`, the grid does NOT inherit CSS variables from the app's
|
|
311
|
+
* `:root` (shadcn, custom theme, etc.). Instead it renders with the
|
|
312
|
+
* package's bundled defaults (or whatever you pass via `theme`).
|
|
313
|
+
*
|
|
314
|
+
* Useful when embedding the grid inside a heavily-themed shell where you
|
|
315
|
+
* want the table to keep its own look regardless of surrounding context.
|
|
316
|
+
*
|
|
317
|
+
* Defaults to `false` (inherit app theme).
|
|
318
|
+
*/
|
|
319
|
+
isolate?: boolean;
|
|
221
320
|
};
|
|
222
321
|
declare function DataTable<TData extends {
|
|
223
322
|
id: string | number;
|
|
224
|
-
}>({ data, columns, isLoading, isFetching, onRefresh, totalRecords, exportFileName, enableSelection, renderSubRow, getSubRows, rowActions, customRowActions, onRowAction, onCellEdit, onRowSave, onAddRow, onBulkDelete, initialPageSize, pageSizeOptions, initialColumnPinning, initialColumnVisibility, globalFilter: globalFilterProp, onGlobalFilterChange, className, toolbarSlot, features, labels: labelsProp, density, theme, }: DataTableProps<TData>): react_jsx_runtime.JSX.Element;
|
|
323
|
+
}>({ data, columns, dataSource, isLoading, isFetching, onRefresh, totalRecords, exportFileName, enableSelection, renderSubRow, getSubRows, rowActions, customRowActions, onRowAction, onCellEdit, onRowSave, onAddRow, onBulkDelete, initialPageSize, pageSizeOptions, initialColumnPinning, initialColumnVisibility, globalFilter: globalFilterProp, onGlobalFilterChange, className, toolbarSlot, features, labels: labelsProp, density, theme, isolate, }: DataTableProps<TData>): react_jsx_runtime.JSX.Element;
|
|
225
324
|
|
|
226
325
|
type Props$2<TData, TValue> = {
|
|
227
326
|
column: Column<TData, TValue>;
|
|
@@ -313,4 +412,4 @@ declare function ColumnFilterPanel<TData, TValue>(props: CommonProps<TData, TVal
|
|
|
313
412
|
declare function exportToCsv<TData>(table: Table<TData>, fileName?: string): void;
|
|
314
413
|
declare function exportToExcel<TData>(table: Table<TData>, fileName?: string): void;
|
|
315
414
|
|
|
316
|
-
export { type AdvFilter, type CellEditorType, ColumnFilterPanel, type Combine, type Condition, type CustomRowAction, DataTable, type DataTableColumn, DataTableColumnHeader, type DataTableDensity, type DataTableFeatures, type DataTableLabels, DataTablePagination, type DataTableProps, DataTableRowActions, type DataTableRowActionsProps, type DataTableTheme, type DataTableThemeName, DataTableToolbar, type DateOp, EditableCell, type FilterType, type NumberOp, type RowAction, type RowActionId, type SelectOption, type SetFilter, type TextOp, booleanFilterFn, dateFilterFn, exportToCsv, exportToExcel, isFilterActive, numberFilterFn, setFilterFn, textFilterFn, themePresets, themeToStyle };
|
|
415
|
+
export { type AdvFilter, type CellEditorType, ColumnFilterPanel, type Combine, type Condition, type CustomRowAction, DataTable, type DataTableColumn, DataTableColumnHeader, type DataTableDataSource, type DataTableDataSourceResult, type DataTableDensity, type DataTableErrorContext, type DataTableFeatures, type DataTableFetchParams, type DataTableLabels, type DataTableModedTheme, DataTablePagination, type DataTableProps, DataTableRowActions, type DataTableRowActionsProps, type DataTableTheme, type DataTableThemeName, type DataTableTokens, DataTableToolbar, type DateOp, EditableCell, type FilterType, ISOLATE_DARK_TOKENS, ISOLATE_LIGHT_TOKENS, type NumberOp, type RowAction, type RowActionId, type SelectOption, type SetFilter, type TextOp, booleanFilterFn, buildPreset, dateFilterFn, exportToCsv, exportToExcel, isFilterActive, numberFilterFn, setFilterFn, splitTheme, textFilterFn, themePresets, themeToStyle, tokensToCssBlock, tokensToStyle };
|