react-shadcn-table 1.0.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 +219 -0
- package/dist/components/ui/button-group.d.ts +11 -0
- package/dist/components/ui/button.d.ts +10 -0
- package/dist/components/ui/checkbox.d.ts +4 -0
- package/dist/components/ui/collapsible.d.ts +5 -0
- package/dist/components/ui/debounced-input.d.ts +6 -0
- package/dist/components/ui/dropdown-menu.d.ts +29 -0
- package/dist/components/ui/empty.d.ts +11 -0
- package/dist/components/ui/input-group.d.ts +16 -0
- package/dist/components/ui/input.d.ts +3 -0
- package/dist/components/ui/item.d.ts +23 -0
- package/dist/components/ui/label.d.ts +4 -0
- package/dist/components/ui/native-select.d.ts +8 -0
- package/dist/components/ui/select.d.ts +15 -0
- package/dist/components/ui/separator.d.ts +4 -0
- package/dist/components/ui/skeleton.d.ts +2 -0
- package/dist/components/ui/spinner.d.ts +2 -0
- package/dist/components/ui/table.d.ts +10 -0
- package/dist/components/ui/textarea.d.ts +3 -0
- package/dist/index.cjs +37 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5173 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/package/contexts/grid/GridContext.d.ts +4 -0
- package/dist/package/contexts/grid/types/index.d.ts +58 -0
- package/dist/package/core/index.d.ts +4 -0
- package/dist/package/core/types/index.d.ts +342 -0
- package/dist/package/features/index.d.ts +41 -0
- package/dist/package/hooks/useGrid.d.ts +3 -0
- package/dist/package/hooks/useGridState.d.ts +57 -0
- package/dist/package/hooks/useQueryArgs.d.ts +12 -0
- package/dist/package/hooks/useSyncScroll.d.ts +7 -0
- package/dist/package/index.d.ts +11 -0
- package/dist/package/state/rowDensity.d.ts +28 -0
- package/dist/package/state/useColumnOrderState.d.ts +4 -0
- package/dist/package/state/useColumnPinningState.d.ts +5 -0
- package/dist/package/state/useColumnSizingState.d.ts +5 -0
- package/dist/package/state/useColumnVisibilityState.d.ts +5 -0
- package/dist/package/state/useDensityState.d.ts +5 -0
- package/dist/package/state/useRowPinningState.d.ts +5 -0
- package/dist/package/state/useSplitViewState.d.ts +4 -0
- package/dist/package/ui/grid/sections/center/GridCenter.d.ts +3 -0
- package/dist/package/ui/grid/sections/center/GridCenterBody.d.ts +3 -0
- package/dist/package/ui/grid/sections/center/GridCenterHeader.d.ts +2 -0
- package/dist/package/ui/grid/sections/center/GridCenterRowPin.d.ts +3 -0
- package/dist/package/ui/grid/sections/center/feedback/GridCenterEmpty.d.ts +2 -0
- package/dist/package/ui/grid/sections/center/feedback/GridCenterEmptyMessage.d.ts +2 -0
- package/dist/package/ui/grid/sections/center/feedback/GridCenterError.d.ts +2 -0
- package/dist/package/ui/grid/sections/center/feedback/GridCenterErrorMessage.d.ts +2 -0
- package/dist/package/ui/grid/sections/center/feedback/GridCenterSkeleton.d.ts +2 -0
- package/dist/package/ui/grid/sections/end/GridEnd.d.ts +2 -0
- package/dist/package/ui/grid/sections/end/GridEndBody.d.ts +3 -0
- package/dist/package/ui/grid/sections/end/GridEndHeader.d.ts +2 -0
- package/dist/package/ui/grid/sections/end/GridEndRowPin.d.ts +5 -0
- package/dist/package/ui/grid/sections/end/feedback/GridEndEmpty.d.ts +2 -0
- package/dist/package/ui/grid/sections/end/feedback/GridEndSkeleton.d.ts +2 -0
- package/dist/package/ui/grid/sections/start/GridStart.d.ts +2 -0
- package/dist/package/ui/grid/sections/start/GridStartBody.d.ts +3 -0
- package/dist/package/ui/grid/sections/start/GridStartHeader.d.ts +2 -0
- package/dist/package/ui/grid/sections/start/GridStartRowPin.d.ts +5 -0
- package/dist/package/ui/grid/sections/start/feedback/GridStartEmpty.d.ts +2 -0
- package/dist/package/ui/grid/sections/start/feedback/GridStartSkeleton.d.ts +2 -0
- package/dist/package/ui/grid/shared/GridCell.d.ts +6 -0
- package/dist/package/ui/grid/shared/GridHead.d.ts +6 -0
- package/dist/package/ui/grid/shared/feedback/GridRowSkeleton.d.ts +8 -0
- package/dist/package/ui/header/HeaderFilter.d.ts +6 -0
- package/dist/package/ui/header/HeaderMenu.d.ts +6 -0
- package/dist/package/ui/header/HeaderResizing.d.ts +6 -0
- package/dist/package/ui/header/HeaderSort.d.ts +6 -0
- package/dist/package/ui/pagination/index.d.ts +2 -0
- package/dist/package/ui/toolbar/right/ToolbarRightColumns.d.ts +3 -0
- package/dist/package/ui/toolbar/right/ToolbarRightDnd.d.ts +2 -0
- package/dist/package/ui/toolbar/right/ToolbarRightFilter.d.ts +3 -0
- package/dist/package/ui/toolbar/right/ToolbarRightRows.d.ts +2 -0
- package/dist/package/ui/toolbar/right/ToolbarRightSettings.d.ts +2 -0
- package/dist/package/ui/toolbar/right/index.d.ts +4 -0
- package/dist/package/ui/toolbar/top/index.d.ts +2 -0
- package/dist/package/utils/URLSearch.d.ts +57 -0
- package/dist/package/utils/buildQueryString.d.ts +2 -0
- package/dist/package/utils/buildSortString.d.ts +4 -0
- package/dist/package/utils/getPinStyles.d.ts +4 -0
- package/dist/package/utils/pluckSelected.d.ts +40 -0
- package/dist/package/utils/printTable.d.ts +1 -0
- package/dist/package/utils/toTsv.d.ts +2 -0
- package/package.json +94 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { RowData } from '@tanstack/react-table';
|
|
2
|
+
import { GridContextProps, GridContextProviderProps } from './types';
|
|
3
|
+
export declare const GridContext: import('react').Context<GridContextProps<any> | undefined>;
|
|
4
|
+
export declare const GridContextProvider: <TableData extends RowData>({ children, columns, payload, name, state, onColumnFiltersChange, onPaginationChange, onSortingChange, setGlobalFilter, isError, isLoading, isFetching, refetch, manualFiltering, manualSorting, manualPagination, height, getRowCanExpand, renderSubComponent, onRowSelectionChange, enableCellSelection, enableCellSpanning, enableRowSelection, topRightSlot, }: GridContextProviderProps<TableData>) => import("react").JSX.Element;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { GridFeatures } from '../../../features';
|
|
2
|
+
import { ColumnDef, ColumnFiltersState, OnChangeFn, PaginationState, ReactTable, Row, RowData, RowSelectionState, SortingState, TableState } from '@tanstack/react-table';
|
|
3
|
+
import { default as React } from 'react';
|
|
4
|
+
export interface GridContextProps<TableData extends RowData = RowData> {
|
|
5
|
+
table: ReactTable<GridFeatures, TableData, TableState<GridFeatures>>;
|
|
6
|
+
paneRef1: React.RefObject<HTMLDivElement | null>;
|
|
7
|
+
paneRef2: React.RefObject<HTMLDivElement | null>;
|
|
8
|
+
paneRef3: React.RefObject<HTMLDivElement | null>;
|
|
9
|
+
paneRef4: React.RefObject<HTMLDivElement | null>;
|
|
10
|
+
paneRef5: React.RefObject<HTMLDivElement | null>;
|
|
11
|
+
paneRef6: React.RefObject<HTMLDivElement | null>;
|
|
12
|
+
gridWrapperRef: React.RefObject<HTMLDivElement | null>;
|
|
13
|
+
isSplit: boolean;
|
|
14
|
+
setIsSplit: React.Dispatch<React.SetStateAction<boolean>>;
|
|
15
|
+
isFetching?: boolean;
|
|
16
|
+
isLoading?: boolean;
|
|
17
|
+
isError?: boolean;
|
|
18
|
+
refetch?: () => void;
|
|
19
|
+
height?: string;
|
|
20
|
+
globalFilter: string;
|
|
21
|
+
setGlobalFilter?: React.Dispatch<React.SetStateAction<string>>;
|
|
22
|
+
renderSubComponent?: (props: {
|
|
23
|
+
row: Row<GridFeatures, TableData>;
|
|
24
|
+
}) => React.ReactElement;
|
|
25
|
+
name?: string;
|
|
26
|
+
topRightSlot?: React.ReactNode;
|
|
27
|
+
}
|
|
28
|
+
export interface GridContextProviderProps<TData extends RowData> {
|
|
29
|
+
children: React.ReactNode;
|
|
30
|
+
payload?: {
|
|
31
|
+
data: TData[];
|
|
32
|
+
total: number;
|
|
33
|
+
};
|
|
34
|
+
columns: ColumnDef<GridFeatures, TData>[];
|
|
35
|
+
name?: string;
|
|
36
|
+
height?: string;
|
|
37
|
+
state?: Partial<TableState<GridFeatures>>;
|
|
38
|
+
onColumnFiltersChange?: OnChangeFn<ColumnFiltersState>;
|
|
39
|
+
onPaginationChange?: OnChangeFn<PaginationState>;
|
|
40
|
+
onSortingChange?: OnChangeFn<SortingState>;
|
|
41
|
+
onRowSelectionChange?: OnChangeFn<RowSelectionState>;
|
|
42
|
+
setGlobalFilter?: React.Dispatch<React.SetStateAction<string>>;
|
|
43
|
+
manualPagination?: boolean;
|
|
44
|
+
manualFiltering?: boolean;
|
|
45
|
+
manualSorting?: boolean;
|
|
46
|
+
isLoading?: boolean;
|
|
47
|
+
isError?: boolean;
|
|
48
|
+
isFetching?: boolean;
|
|
49
|
+
refetch?: () => void;
|
|
50
|
+
renderSubComponent?: (props: {
|
|
51
|
+
row: Row<GridFeatures, TData>;
|
|
52
|
+
}) => React.ReactElement;
|
|
53
|
+
getRowCanExpand?: (row: Row<GridFeatures, TData>) => boolean;
|
|
54
|
+
enableCellSelection?: boolean;
|
|
55
|
+
enableCellSpanning?: boolean;
|
|
56
|
+
enableRowSelection?: boolean;
|
|
57
|
+
topRightSlot?: React.ReactNode;
|
|
58
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { RowData } from '@tanstack/react-table';
|
|
2
|
+
import { GridProps } from './types';
|
|
3
|
+
declare const Grid: <T extends RowData>({ payload, columns, name, state, onColumnFiltersChange, onPaginationChange, onSortingChange, onRowSelectionChange, setGlobalFilter, manualPagination, manualFiltering, manualSorting, isLoading, isError, isFetching, refetch, height, getRowCanExpand, renderSubComponent, enableCellSelection, enableCellSpanning, enableRowSelection, topRightSlot, }: GridProps<T>) => import("react").JSX.Element;
|
|
4
|
+
export { Grid };
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { GridFeatures } from '../../features';
|
|
2
|
+
import { ColumnDef, ColumnFiltersState, OnChangeFn, PaginationState, Row, RowData, RowSelectionState, SortingState, TableState } from '@tanstack/react-table';
|
|
3
|
+
/**
|
|
4
|
+
* Props for the `Grid` component.
|
|
5
|
+
*
|
|
6
|
+
* `Grid` is a reusable, feature-rich data-table component built on top of
|
|
7
|
+
* `@tanstack/react-table`. It supports sorting, filtering, pagination,
|
|
8
|
+
* column/row pinning, column resizing, row selection, cell selection,
|
|
9
|
+
* cell spanning, and row expansion out of the box.
|
|
10
|
+
*
|
|
11
|
+
* @typeParam TData - The shape of a single row of data. Must satisfy
|
|
12
|
+
* TanStack Table's `RowData` constraint.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* Basic usage with local state via `useGridState`:
|
|
16
|
+
* ```tsx
|
|
17
|
+
* import { Grid, useGridState, type ColumnDef, type GridFeatures } from 'react-shadcn-table';
|
|
18
|
+
*
|
|
19
|
+
* interface User {
|
|
20
|
+
* id: string;
|
|
21
|
+
* name: string;
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* const columns: ColumnDef<GridFeatures, User, unknown>[] = [
|
|
25
|
+
* { id: 'id', accessorKey: 'id', header: () => 'ID' },
|
|
26
|
+
* { id: 'name', accessorKey: 'name', header: () => 'Name' },
|
|
27
|
+
* ];
|
|
28
|
+
*
|
|
29
|
+
* const App = () => {
|
|
30
|
+
* const { state, handlers } = useGridState();
|
|
31
|
+
*
|
|
32
|
+
* return (
|
|
33
|
+
* <Grid
|
|
34
|
+
* payload={{ data: users, total: users.length }}
|
|
35
|
+
* columns={columns}
|
|
36
|
+
* state={state}
|
|
37
|
+
* {...handlers}
|
|
38
|
+
* />
|
|
39
|
+
* );
|
|
40
|
+
* };
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* Server-side (manual) pagination, sorting, and filtering:
|
|
45
|
+
* ```tsx
|
|
46
|
+
* const { state, handlers } = useGridState();
|
|
47
|
+
* const { data, isLoading, isError, refetch, isFetching } = useUsersQuery({
|
|
48
|
+
* queryString: URLSearch(state),
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* <Grid
|
|
52
|
+
* payload={{ data: data?.rows ?? [], total: data?.total ?? 0 }}
|
|
53
|
+
* columns={columns}
|
|
54
|
+
* manualPagination
|
|
55
|
+
* manualFiltering
|
|
56
|
+
* manualSorting
|
|
57
|
+
* isLoading={isLoading}
|
|
58
|
+
* isError={isError}
|
|
59
|
+
* isFetching={isFetching}
|
|
60
|
+
* refetch={refetch}
|
|
61
|
+
* state={state}
|
|
62
|
+
* {...handlers}
|
|
63
|
+
* />
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export interface GridProps<TData extends RowData> {
|
|
67
|
+
/**
|
|
68
|
+
* The row data to render, plus the total row count (used for
|
|
69
|
+
* server-side/manual pagination to compute total pages).
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```tsx
|
|
73
|
+
* payload={{ data: users, total: 128 }}
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
payload?: {
|
|
77
|
+
data: TData[];
|
|
78
|
+
total: number;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Column definitions for the table. Required. Typed against the grid's
|
|
82
|
+
* internal `GridFeatures` so column APIs (pinning, spanning, etc.) are
|
|
83
|
+
* available inside `header`/`cell` renderers.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```tsx
|
|
87
|
+
* const columns: ColumnDef<GridFeatures, User, unknown>[] = [
|
|
88
|
+
* {
|
|
89
|
+
* id: 'email',
|
|
90
|
+
* accessorKey: 'email',
|
|
91
|
+
* header: () => <div>Email</div>,
|
|
92
|
+
* meta: { filterVariant: 'text' },
|
|
93
|
+
* },
|
|
94
|
+
* ];
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
columns: ColumnDef<GridFeatures, TData>[];
|
|
98
|
+
/**
|
|
99
|
+
* A unique name for this grid instance, used as a storage key to persist
|
|
100
|
+
* per-grid layout (column visibility, pinning, order, sizing, split view)
|
|
101
|
+
* across sessions. Use a distinct name per grid instance in your app.
|
|
102
|
+
*
|
|
103
|
+
* @defaultValue `'munza'`
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```tsx
|
|
107
|
+
* <Grid name="users-grid" ... />
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
name?: string;
|
|
111
|
+
/**
|
|
112
|
+
* Fixed height for the table's scrollable body, as a CSS value.
|
|
113
|
+
*
|
|
114
|
+
* @defaultValue `'65vh'`
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```tsx
|
|
118
|
+
* <Grid height="480px" ... />
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
height?: string;
|
|
122
|
+
/**
|
|
123
|
+
* The current table state (filters, pagination, sorting, selection,
|
|
124
|
+
* global filter, etc.), typically supplied by `useGridState`. Partial,
|
|
125
|
+
* since any field you omit falls back to the grid's own internal state.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```tsx
|
|
129
|
+
* const { state } = useGridState();
|
|
130
|
+
* <Grid state={state} ... />
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
state?: Partial<TableState<GridFeatures>>;
|
|
134
|
+
/**
|
|
135
|
+
* Callback fired when column filters change.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```tsx
|
|
139
|
+
* onColumnFiltersChange={(updater) => setColumnFilters(updater)}
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
onColumnFiltersChange?: OnChangeFn<ColumnFiltersState>;
|
|
143
|
+
/**
|
|
144
|
+
* Callback fired when pagination (page index or page size) changes.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```tsx
|
|
148
|
+
* onPaginationChange={(updater) => setPagination(updater)}
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
onPaginationChange?: OnChangeFn<PaginationState>;
|
|
152
|
+
/**
|
|
153
|
+
* Callback fired when column sorting changes.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```tsx
|
|
157
|
+
* onSortingChange={(updater) => setSorting(updater)}
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
onSortingChange?: OnChangeFn<SortingState>;
|
|
161
|
+
/**
|
|
162
|
+
* Callback fired when row selection changes.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```tsx
|
|
166
|
+
* onRowSelectionChange={(updater) => setRowSelection(updater)}
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
onRowSelectionChange?: OnChangeFn<RowSelectionState>;
|
|
170
|
+
/**
|
|
171
|
+
* Setter for the global (cross-column) search/filter text.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```tsx
|
|
175
|
+
* const [globalFilter, setGlobalFilter] = useState('');
|
|
176
|
+
* <Grid setGlobalFilter={setGlobalFilter} ... />
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
setGlobalFilter?: React.Dispatch<React.SetStateAction<string>>;
|
|
180
|
+
/**
|
|
181
|
+
* Enables server-side (manual) pagination. When `true`, the table will
|
|
182
|
+
* not paginate `payload.data` itself and instead relies on `payload.total`
|
|
183
|
+
* and your `onPaginationChange` handler to fetch the correct page.
|
|
184
|
+
*
|
|
185
|
+
* @defaultValue `false`
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```tsx
|
|
189
|
+
* <Grid manualPagination payload={{ data: pageOfUsers, total: 500 }} ... />
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
manualPagination?: boolean;
|
|
193
|
+
/**
|
|
194
|
+
* Enables server-side (manual) column filtering. When `true`, the table
|
|
195
|
+
* assumes `payload.data` is already filtered and skips its own
|
|
196
|
+
* client-side filtering row model for column filters.
|
|
197
|
+
*
|
|
198
|
+
* @defaultValue `false`
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```tsx
|
|
202
|
+
* <Grid manualFiltering onColumnFiltersChange={setColumnFilters} ... />
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
manualFiltering?: boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Enables server-side (manual) sorting. When `true`, the table assumes
|
|
208
|
+
* `payload.data` already arrives sorted and skips its own client-side
|
|
209
|
+
* sorting row model.
|
|
210
|
+
*
|
|
211
|
+
* @defaultValue `false`
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```tsx
|
|
215
|
+
* <Grid manualSorting onSortingChange={setSorting} ... />
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
manualSorting?: boolean;
|
|
219
|
+
/**
|
|
220
|
+
* Shows a loading state (e.g. skeleton rows) while data is being fetched.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```tsx
|
|
224
|
+
* <Grid isLoading={isPending} ... />
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
isLoading?: boolean;
|
|
228
|
+
/**
|
|
229
|
+
* Shows an error state, typically when a data-fetch request has failed.
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```tsx
|
|
233
|
+
* <Grid isError={isError} ... />
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
isError?: boolean;
|
|
237
|
+
/**
|
|
238
|
+
* Indicates a background refetch is in progress (distinct from the
|
|
239
|
+
* initial `isLoading` state), useful for showing a subtle refresh
|
|
240
|
+
* indicator without blocking the existing rows.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```tsx
|
|
244
|
+
* <Grid isFetching={isFetching} ... />
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
isFetching?: boolean;
|
|
248
|
+
/**
|
|
249
|
+
* Function to manually re-trigger a data fetch, e.g. from a "Retry"
|
|
250
|
+
* button on the error state or a refresh action in the toolbar.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```tsx
|
|
254
|
+
* <Grid refetch={() => queryClient.refetchQueries(['users'])} ... />
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
refetch?: () => void;
|
|
258
|
+
/**
|
|
259
|
+
* Renders custom content inside an expanded row (used together with
|
|
260
|
+
* `getRowCanExpand`).
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```tsx
|
|
264
|
+
* renderSubComponent={({ row }) => (
|
|
265
|
+
* <pre>{JSON.stringify(row.original, null, 2)}</pre>
|
|
266
|
+
* )}
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
renderSubComponent?: (props: {
|
|
270
|
+
row: Row<GridFeatures, TData>;
|
|
271
|
+
}) => React.ReactElement;
|
|
272
|
+
/**
|
|
273
|
+
* Determines whether a given row can be expanded to show
|
|
274
|
+
* `renderSubComponent`. If omitted, no rows are expandable and the
|
|
275
|
+
* expand column is not rendered.
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```tsx
|
|
279
|
+
* getRowCanExpand={(row) => row.original.subRows?.length > 0}
|
|
280
|
+
* ```
|
|
281
|
+
*/
|
|
282
|
+
getRowCanExpand?: (row: Row<GridFeatures, TData>) => boolean;
|
|
283
|
+
/**
|
|
284
|
+
* Enables Excel-like click-and-drag cell range selection, independent
|
|
285
|
+
* of row selection.
|
|
286
|
+
*
|
|
287
|
+
* @defaultValue `false`
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```tsx
|
|
291
|
+
* <Grid enableCellSelection ... />
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
294
|
+
enableCellSelection?: boolean;
|
|
295
|
+
/**
|
|
296
|
+
* Enables merged/spanning cells for columns whose `ColumnDef` opts into
|
|
297
|
+
* spanning.
|
|
298
|
+
*
|
|
299
|
+
* @defaultValue `false`
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```tsx
|
|
303
|
+
* <Grid enableCellSpanning ... />
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
enableCellSpanning?: boolean;
|
|
307
|
+
/**
|
|
308
|
+
* Enables or disables row selection (checkbox column and related
|
|
309
|
+
* selection APIs). When `false`, the selection column is not rendered.
|
|
310
|
+
*
|
|
311
|
+
* @defaultValue `true`
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* ```tsx
|
|
315
|
+
* <Grid enableRowSelection={false} ... />
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
enableRowSelection?: boolean;
|
|
319
|
+
/**
|
|
320
|
+
* Additional content rendered on the right side of the built-in toolbar,
|
|
321
|
+
* next to the global search field (e.g. custom action buttons like
|
|
322
|
+
* Add, Filter, Refresh, or Export).
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```tsx
|
|
326
|
+
* <Grid
|
|
327
|
+
* topRightSlot={
|
|
328
|
+
* <div className="flex items-center gap-2">
|
|
329
|
+
* <Button variant="ghost" size="icon" onClick={refetch}>
|
|
330
|
+
* <RefreshCw className="size-4" />
|
|
331
|
+
* </Button>
|
|
332
|
+
* <Button size="icon" onClick={handleAdd}>
|
|
333
|
+
* <Plus className="size-4" />
|
|
334
|
+
* </Button>
|
|
335
|
+
* </div>
|
|
336
|
+
* }
|
|
337
|
+
* ...
|
|
338
|
+
* />
|
|
339
|
+
* ```
|
|
340
|
+
*/
|
|
341
|
+
topRightSlot?: React.ReactNode;
|
|
342
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
interface MyColumnMeta {
|
|
2
|
+
filterVariant?: 'text' | 'number' | 'tel' | 'url' | 'color' | 'range' | 'select' | 'dateRange' | 'date' | 'datetime-local' | 'month' | 'time' | 'week' | 'search';
|
|
3
|
+
}
|
|
4
|
+
export declare const features: {
|
|
5
|
+
rowExpandingFeature: import('@tanstack/react-table').TableFeature;
|
|
6
|
+
cellSpanningFeature: import('@tanstack/react-table').TableFeature;
|
|
7
|
+
cellSelectionFeature: import('@tanstack/react-table').TableFeature;
|
|
8
|
+
rowPinningFeature: import('@tanstack/react-table').TableFeature;
|
|
9
|
+
columnOrderingFeature: import('@tanstack/react-table').TableFeature;
|
|
10
|
+
columnPinningFeature: import('@tanstack/react-table').TableFeature;
|
|
11
|
+
columnResizingFeature: import('@tanstack/react-table').TableFeature;
|
|
12
|
+
columnSizingFeature: import('@tanstack/react-table').TableFeature;
|
|
13
|
+
columnVisibilityFeature: import('@tanstack/react-table').TableFeature;
|
|
14
|
+
columnFacetingFeature: import('@tanstack/react-table').TableFeature;
|
|
15
|
+
columnFilteringFeature: import('@tanstack/react-table').TableFeature;
|
|
16
|
+
rowPaginationFeature: import('@tanstack/react-table').TableFeature;
|
|
17
|
+
rowSelectionFeature: import('@tanstack/react-table').TableFeature;
|
|
18
|
+
rowSortingFeature: import('@tanstack/react-table').TableFeature;
|
|
19
|
+
filteredRowModel: (table: import('@tanstack/react-table').Table<any, any>) => () => import('@tanstack/react-table').RowModel<any, any>;
|
|
20
|
+
paginatedRowModel: (table: import('@tanstack/react-table').Table<any, any>) => () => import('@tanstack/react-table').RowModel<any, any>;
|
|
21
|
+
sortedRowModel: (table: import('@tanstack/react-table').Table<any, any>) => () => import('@tanstack/react-table').RowModel<any, any>;
|
|
22
|
+
facetedRowModel: (table: import('@tanstack/react-table').Table<any, any>, columnId: string) => () => import('@tanstack/react-table').RowModel<any, any>;
|
|
23
|
+
facetedUniqueValues: (table: import('@tanstack/react-table').Table<import('@tanstack/react-table').TableFeatures, any>, columnId: string) => () => Map<any, number>;
|
|
24
|
+
facetedMinMaxValues: (table: import('@tanstack/react-table').Table<import('@tanstack/react-table').TableFeatures, any>, columnId: string) => () => undefined | [number, number];
|
|
25
|
+
expandedRowModel: (table: import('@tanstack/react-table').Table<any, any>) => () => import('@tanstack/react-table').RowModel<any, any>;
|
|
26
|
+
filterFns: {
|
|
27
|
+
includesString: import('@tanstack/react-table').CreatedFilterFn<any, any>;
|
|
28
|
+
inNumberRange: import('@tanstack/react-table').CreatedFilterFn<any, any>;
|
|
29
|
+
inDateRange: import('@tanstack/react-table').CreatedFilterFn<any, any>;
|
|
30
|
+
equalsString: import('@tanstack/react-table').CreatedFilterFn<any, any>;
|
|
31
|
+
};
|
|
32
|
+
sortFns: {
|
|
33
|
+
alphanumeric: import('@tanstack/react-table').CreatedSortFn<any, any>;
|
|
34
|
+
text: import('@tanstack/react-table').CreatedSortFn<any, any>;
|
|
35
|
+
};
|
|
36
|
+
globalFilteringFeature: import('@tanstack/react-table').TableFeature;
|
|
37
|
+
columnMeta: MyColumnMeta;
|
|
38
|
+
densityPlugin: import('@tanstack/react-table').TableFeature;
|
|
39
|
+
};
|
|
40
|
+
export type GridFeatures = typeof features;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ColumnFiltersState, PaginationState, RowSelectionState, SortingState } from '@tanstack/react-table';
|
|
2
|
+
import { default as React } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* A React hook that manages all controlled state required to drive a
|
|
5
|
+
* TanStack Table instance (column filters, pagination, sorting, row
|
|
6
|
+
* selection, and global filter), and returns them pre-packaged in the
|
|
7
|
+
* shape expected by both the table's `state`/`onXChange` props and by
|
|
8
|
+
* consumers who need direct access to the current `rowSelection`.
|
|
9
|
+
*
|
|
10
|
+
* Internally, each piece of state is backed by its own `useState`, so
|
|
11
|
+
* updating one (e.g. `sorting`) does not cause unrelated state (e.g.
|
|
12
|
+
* `rowSelection`) to reset.
|
|
13
|
+
*
|
|
14
|
+
* @returns An object containing:
|
|
15
|
+
* - `state` - The combined table state object
|
|
16
|
+
* (`columnFilters`, `globalFilter`, `pagination`, `sorting`,
|
|
17
|
+
* `rowSelection`), meant to be spread into the table's `state` prop.
|
|
18
|
+
* - `handlers` - The corresponding change handlers
|
|
19
|
+
* (`onColumnFiltersChange`, `onPaginationChange`, `onSortingChange`,
|
|
20
|
+
* `setGlobalFilter`, `onRowSelectionChange`), meant to be spread as
|
|
21
|
+
* props onto the table component.
|
|
22
|
+
* - `rowSelection` - The current `RowSelectionState` on its own, exposed
|
|
23
|
+
* separately for convenience (e.g. to pass into utilities like
|
|
24
|
+
* `pluckSelected` without destructuring it out of `state` again).
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* const { state, handlers, rowSelection } = useGridState();
|
|
29
|
+
*
|
|
30
|
+
* <Grid
|
|
31
|
+
* columns={columns}
|
|
32
|
+
* data={data}
|
|
33
|
+
* state={state}
|
|
34
|
+
* {...handlers}
|
|
35
|
+
* />
|
|
36
|
+
*
|
|
37
|
+
* // Use rowSelection directly elsewhere, e.g.:
|
|
38
|
+
* const selectedIds = pluckSelected(data, rowSelection, 'id');
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare const useGridState: () => {
|
|
42
|
+
state: {
|
|
43
|
+
columnFilters: ColumnFiltersState;
|
|
44
|
+
globalFilter: string;
|
|
45
|
+
pagination: PaginationState;
|
|
46
|
+
sorting: SortingState;
|
|
47
|
+
rowSelection: RowSelectionState;
|
|
48
|
+
};
|
|
49
|
+
handlers: {
|
|
50
|
+
onColumnFiltersChange: React.Dispatch<React.SetStateAction<ColumnFiltersState>>;
|
|
51
|
+
onPaginationChange: React.Dispatch<React.SetStateAction<PaginationState>>;
|
|
52
|
+
onSortingChange: React.Dispatch<React.SetStateAction<SortingState>>;
|
|
53
|
+
setGlobalFilter: React.Dispatch<React.SetStateAction<string>>;
|
|
54
|
+
onRowSelectionChange: React.Dispatch<React.SetStateAction<RowSelectionState>>;
|
|
55
|
+
};
|
|
56
|
+
rowSelection: RowSelectionState;
|
|
57
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ColumnFiltersState, PaginationState, SortingState } from '@tanstack/react-table';
|
|
2
|
+
export declare const useQueryArgs: (state: {
|
|
3
|
+
columnFilters: ColumnFiltersState;
|
|
4
|
+
globalFilter: string;
|
|
5
|
+
pagination: PaginationState;
|
|
6
|
+
sorting: SortingState;
|
|
7
|
+
}) => {
|
|
8
|
+
pagination: PaginationState;
|
|
9
|
+
queryParams: string;
|
|
10
|
+
sort: string;
|
|
11
|
+
globalFilter: string;
|
|
12
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ColumnDef, ColumnFiltersState, PaginationState, Row, SortingState } from '@tanstack/react-table';
|
|
2
|
+
export { type GridContextProps } from './contexts/grid/types';
|
|
3
|
+
export { Grid } from './core/index';
|
|
4
|
+
export type { GridProps } from './core/types';
|
|
5
|
+
export type { GridFeatures } from './features';
|
|
6
|
+
export { useGrid } from './hooks/useGrid';
|
|
7
|
+
export { useGridState } from './hooks/useGridState';
|
|
8
|
+
export { useQueryArgs } from './hooks/useQueryArgs';
|
|
9
|
+
export { pluckSelected } from './utils/pluckSelected';
|
|
10
|
+
export { URLSearch } from './utils/URLSearch';
|
|
11
|
+
export type { ColumnDef, ColumnFiltersState, PaginationState, Row, SortingState, };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { OnChangeFn, RowData, TableFeature, TableFeatures, Updater } from '@tanstack/react-table';
|
|
2
|
+
export type DensityState = 'sm' | 'md' | 'lg';
|
|
3
|
+
export interface TableState_Density {
|
|
4
|
+
density: DensityState;
|
|
5
|
+
}
|
|
6
|
+
export interface TableOptions_Density {
|
|
7
|
+
enableDensity?: boolean;
|
|
8
|
+
onDensityChange?: OnChangeFn<DensityState>;
|
|
9
|
+
}
|
|
10
|
+
export interface Table_Density {
|
|
11
|
+
setDensity: (updater: Updater<DensityState>) => void;
|
|
12
|
+
toggleDensity: (value?: DensityState) => void;
|
|
13
|
+
}
|
|
14
|
+
declare module '@tanstack/react-table' {
|
|
15
|
+
interface Plugins {
|
|
16
|
+
densityPlugin: TableFeature;
|
|
17
|
+
}
|
|
18
|
+
interface TableState_FeatureMap {
|
|
19
|
+
densityPlugin: TableState_Density;
|
|
20
|
+
}
|
|
21
|
+
interface TableOptions_FeatureMap<TFeatures extends TableFeatures, TData extends RowData> {
|
|
22
|
+
densityPlugin: TableOptions_Density;
|
|
23
|
+
}
|
|
24
|
+
interface Table_FeatureMap<TFeatures extends TableFeatures, TData extends RowData> {
|
|
25
|
+
densityPlugin: Table_Density;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export declare const densityPlugin: TableFeature;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
export declare function getStoredColumnOrder(gridId: string, defaultOrder: string[]): string[];
|
|
3
|
+
export declare function setStoredColumnOrder(gridId: string, order: string[]): void;
|
|
4
|
+
export declare function useColumnOrderState(gridId: string, defaultOrder: string[]): readonly [string[], Dispatch<SetStateAction<string[]>>];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ColumnPinningState } from '@tanstack/react-table';
|
|
2
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
3
|
+
export declare function getStoredColumnPinning(gridId: string, columnIds?: string[]): ColumnPinningState;
|
|
4
|
+
export declare function setStoredColumnPinning(gridId: string, pinning: ColumnPinningState): void;
|
|
5
|
+
export declare function useColumnPinningState(gridId: string, columnIds?: string[]): readonly [ColumnPinningState, Dispatch<SetStateAction<ColumnPinningState>>];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ColumnSizingState } from '@tanstack/react-table';
|
|
2
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
3
|
+
export declare function getStoredColumnSizing(gridId: string): ColumnSizingState;
|
|
4
|
+
export declare function setStoredColumnSizing(gridId: string, sizing: ColumnSizingState): void;
|
|
5
|
+
export declare function useColumnSizingState(gridId: string): readonly [ColumnSizingState, Dispatch<SetStateAction<ColumnSizingState>>];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ColumnVisibilityState } from '@tanstack/react-table';
|
|
2
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
3
|
+
export declare function getStoredColumnVisibility(gridId: string): ColumnVisibilityState;
|
|
4
|
+
export declare function setStoredColumnVisibility(gridId: string, visibility: ColumnVisibilityState): void;
|
|
5
|
+
export declare function useColumnVisibilityState(gridId: string): readonly [ColumnVisibilityState, Dispatch<SetStateAction<ColumnVisibilityState>>];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { DensityState } from './rowDensity';
|
|
3
|
+
export declare function getStoredDensity(gridId: string): DensityState;
|
|
4
|
+
export declare function setStoredDensity(gridId: string, density: DensityState): void;
|
|
5
|
+
export declare function useDensityState(gridId: string): readonly [DensityState, Dispatch<SetStateAction<DensityState>>];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RowPinningState } from '@tanstack/react-table';
|
|
2
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
3
|
+
export declare function getStoredRowPinning(gridId: string): RowPinningState;
|
|
4
|
+
export declare function setStoredRowPinning(gridId: string, pinning: RowPinningState): void;
|
|
5
|
+
export declare function useRowPinningState(gridId: string): readonly [RowPinningState, Dispatch<SetStateAction<RowPinningState>>];
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
export declare function getStoredIsSplit(gridId: string): boolean;
|
|
3
|
+
export declare function setStoredIsSplit(gridId: string, isSplit: boolean): void;
|
|
4
|
+
export declare function useSplitViewState(gridId: string): readonly [boolean, Dispatch<SetStateAction<boolean>>];
|