@bsol-oss/react-datatable5 7.3.0 → 7.3.2
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/dist/index.d.ts +65 -64
- package/dist/index.js +8 -6
- package/dist/index.mjs +8 -6
- package/dist/types/components/DataTable/DataTableServer.d.ts +3 -2
- package/dist/types/components/DataTable/components/EmptyState.d.ts +4 -2
- package/dist/types/components/DataTable/components/ErrorAlert.d.ts +1 -1
- package/dist/types/components/DataTable/context/DataTableServerContext.d.ts +5 -2
- package/dist/types/components/DataTable/context/useDataTableServerContext.d.ts +4 -1
- package/dist/types/components/DataTable/useDataTableServer.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -144,7 +144,66 @@ interface DataTableProps<TData> {
|
|
|
144
144
|
}
|
|
145
145
|
declare function DataTable<TData = unknown>({ columns, data, enableRowSelection, enableMultiRowSelection, enableSubRowSelection, columnOrder, columnFilters, columnVisibility, density, globalFilter, pagination, sorting, rowSelection, setPagination, setSorting, setColumnFilters, setRowSelection, setGlobalFilter, setColumnOrder, setDensity, setColumnVisibility, children, }: DataTableProps<TData>): react_jsx_runtime.JSX.Element;
|
|
146
146
|
|
|
147
|
-
interface
|
|
147
|
+
interface DataTableDefaultState {
|
|
148
|
+
sorting?: SortingState;
|
|
149
|
+
columnFilters?: ColumnFiltersState;
|
|
150
|
+
pagination?: PaginationState;
|
|
151
|
+
rowSelection?: RowSelectionState;
|
|
152
|
+
columnOrder?: ColumnOrderState;
|
|
153
|
+
globalFilter?: string;
|
|
154
|
+
columnVisibility?: VisibilityState;
|
|
155
|
+
density?: DensityState;
|
|
156
|
+
}
|
|
157
|
+
interface UseDataTableProps {
|
|
158
|
+
default?: DataTableDefaultState;
|
|
159
|
+
}
|
|
160
|
+
interface UseDataTableReturn {
|
|
161
|
+
sorting: SortingState;
|
|
162
|
+
columnFilters: ColumnFiltersState;
|
|
163
|
+
pagination: PaginationState;
|
|
164
|
+
rowSelection: RowSelectionState;
|
|
165
|
+
columnOrder: ColumnOrderState;
|
|
166
|
+
globalFilter: string;
|
|
167
|
+
columnVisibility: VisibilityState;
|
|
168
|
+
density: DensityState;
|
|
169
|
+
setPagination: OnChangeFn<PaginationState>;
|
|
170
|
+
setSorting: OnChangeFn<SortingState>;
|
|
171
|
+
setColumnFilters: OnChangeFn<ColumnFiltersState>;
|
|
172
|
+
setRowSelection: OnChangeFn<RowSelectionState>;
|
|
173
|
+
setGlobalFilter: OnChangeFn<string>;
|
|
174
|
+
setColumnOrder: OnChangeFn<ColumnOrderState>;
|
|
175
|
+
setDensity: OnChangeFn<DensityState>;
|
|
176
|
+
setColumnVisibility: OnChangeFn<VisibilityState>;
|
|
177
|
+
}
|
|
178
|
+
declare const useDataTable: ({ default: { sorting: defaultSorting, pagination: defaultPagination, rowSelection: defaultRowSelection, columnFilters: defaultColumnFilters, columnOrder: defaultColumnOrder, columnVisibility: defaultColumnVisibility, globalFilter: defaultGlobalFilter, density: defaultDensity, }, }?: UseDataTableProps) => UseDataTableReturn;
|
|
179
|
+
|
|
180
|
+
interface UseDataTableServerProps extends UseDataTableProps {
|
|
181
|
+
/**
|
|
182
|
+
* Delay to send the request if the `refreshData` called multiple times
|
|
183
|
+
*
|
|
184
|
+
* default: `true`
|
|
185
|
+
*/
|
|
186
|
+
debounce?: boolean;
|
|
187
|
+
/**
|
|
188
|
+
* The time to wait before sending the request
|
|
189
|
+
*
|
|
190
|
+
* default: `1000`
|
|
191
|
+
*/
|
|
192
|
+
debounceDelay?: number;
|
|
193
|
+
url: string;
|
|
194
|
+
}
|
|
195
|
+
interface UseDataTableServerReturn<TData> extends UseDataTableReturn {
|
|
196
|
+
query: UseQueryResult<DataResponse<TData>, Error>;
|
|
197
|
+
}
|
|
198
|
+
interface Result<T = unknown> {
|
|
199
|
+
data: T[];
|
|
200
|
+
}
|
|
201
|
+
interface DataResponse<T = unknown> extends Result<T> {
|
|
202
|
+
count: number;
|
|
203
|
+
}
|
|
204
|
+
declare const useDataTableServer: <TData>({ url, default: { sorting: defaultSorting, pagination: defaultPagination, rowSelection: defaultRowSelection, columnFilters: defaultColumnFilters, columnOrder: defaultColumnOrder, columnVisibility: defaultColumnVisibility, globalFilter: defaultGlobalFilter, density: defaultDensity, }, }: UseDataTableServerProps) => UseDataTableServerReturn<TData>;
|
|
205
|
+
|
|
206
|
+
interface DataTableServerProps<TData extends DataResponse = DataResponse<unknown>> {
|
|
148
207
|
children: ReactNode | ReactNode[];
|
|
149
208
|
columns: ColumnDef<TData>[];
|
|
150
209
|
enableRowSelection?: boolean;
|
|
@@ -169,7 +228,7 @@ interface DataTableServerProps<TData> {
|
|
|
169
228
|
query: UseQueryResult<TData>;
|
|
170
229
|
url: string;
|
|
171
230
|
}
|
|
172
|
-
declare function DataTableServer<TData = unknown
|
|
231
|
+
declare function DataTableServer<TData extends DataResponse = DataResponse<unknown>>({ columns, enableRowSelection, enableMultiRowSelection, enableSubRowSelection, columnOrder, columnFilters, columnVisibility, density, globalFilter, pagination, sorting, rowSelection, setPagination, setSorting, setColumnFilters, setRowSelection, setGlobalFilter, setColumnOrder, setDensity, setColumnVisibility, query, children, url, }: DataTableServerProps<TData>): react_jsx_runtime.JSX.Element;
|
|
173
232
|
|
|
174
233
|
interface TableBodyProps {
|
|
175
234
|
pinnedBgColor?: {
|
|
@@ -307,39 +366,6 @@ interface TextCellProps {
|
|
|
307
366
|
}
|
|
308
367
|
declare const TextCell: ({ label, containerProps, textProps, children, }: TextCellProps) => react_jsx_runtime.JSX.Element;
|
|
309
368
|
|
|
310
|
-
interface DataTableDefaultState {
|
|
311
|
-
sorting?: SortingState;
|
|
312
|
-
columnFilters?: ColumnFiltersState;
|
|
313
|
-
pagination?: PaginationState;
|
|
314
|
-
rowSelection?: RowSelectionState;
|
|
315
|
-
columnOrder?: ColumnOrderState;
|
|
316
|
-
globalFilter?: string;
|
|
317
|
-
columnVisibility?: VisibilityState;
|
|
318
|
-
density?: DensityState;
|
|
319
|
-
}
|
|
320
|
-
interface UseDataTableProps {
|
|
321
|
-
default?: DataTableDefaultState;
|
|
322
|
-
}
|
|
323
|
-
interface UseDataTableReturn {
|
|
324
|
-
sorting: SortingState;
|
|
325
|
-
columnFilters: ColumnFiltersState;
|
|
326
|
-
pagination: PaginationState;
|
|
327
|
-
rowSelection: RowSelectionState;
|
|
328
|
-
columnOrder: ColumnOrderState;
|
|
329
|
-
globalFilter: string;
|
|
330
|
-
columnVisibility: VisibilityState;
|
|
331
|
-
density: DensityState;
|
|
332
|
-
setPagination: OnChangeFn<PaginationState>;
|
|
333
|
-
setSorting: OnChangeFn<SortingState>;
|
|
334
|
-
setColumnFilters: OnChangeFn<ColumnFiltersState>;
|
|
335
|
-
setRowSelection: OnChangeFn<RowSelectionState>;
|
|
336
|
-
setGlobalFilter: OnChangeFn<string>;
|
|
337
|
-
setColumnOrder: OnChangeFn<ColumnOrderState>;
|
|
338
|
-
setDensity: OnChangeFn<DensityState>;
|
|
339
|
-
setColumnVisibility: OnChangeFn<VisibilityState>;
|
|
340
|
-
}
|
|
341
|
-
declare const useDataTable: ({ default: { sorting: defaultSorting, pagination: defaultPagination, rowSelection: defaultRowSelection, columnFilters: defaultColumnFilters, columnOrder: defaultColumnOrder, columnVisibility: defaultColumnVisibility, globalFilter: defaultGlobalFilter, density: defaultDensity, }, }?: UseDataTableProps) => UseDataTableReturn;
|
|
342
|
-
|
|
343
369
|
interface DataTableContext<TData> {
|
|
344
370
|
table: Table$1<TData>;
|
|
345
371
|
globalFilter: string;
|
|
@@ -350,32 +376,6 @@ declare const DataTableContext: React$1.Context<DataTableContext<any>>;
|
|
|
350
376
|
|
|
351
377
|
declare const useDataTableContext: <TData>() => DataTableContext<TData>;
|
|
352
378
|
|
|
353
|
-
interface UseDataTableServerProps extends UseDataTableProps {
|
|
354
|
-
/**
|
|
355
|
-
* Delay to send the request if the `refreshData` called multiple times
|
|
356
|
-
*
|
|
357
|
-
* default: `true`
|
|
358
|
-
*/
|
|
359
|
-
debounce?: boolean;
|
|
360
|
-
/**
|
|
361
|
-
* The time to wait before sending the request
|
|
362
|
-
*
|
|
363
|
-
* default: `1000`
|
|
364
|
-
*/
|
|
365
|
-
debounceDelay?: number;
|
|
366
|
-
url: string;
|
|
367
|
-
}
|
|
368
|
-
interface UseDataTableServerReturn<TData> extends UseDataTableReturn {
|
|
369
|
-
query: UseQueryResult<DataResponse<TData>, Error>;
|
|
370
|
-
}
|
|
371
|
-
interface Result<T> {
|
|
372
|
-
data: T[];
|
|
373
|
-
}
|
|
374
|
-
interface DataResponse<T> extends Result<T> {
|
|
375
|
-
count: number;
|
|
376
|
-
}
|
|
377
|
-
declare const useDataTableServer: <TData>({ url, default: { sorting: defaultSorting, pagination: defaultPagination, rowSelection: defaultRowSelection, columnFilters: defaultColumnFilters, columnOrder: defaultColumnOrder, columnVisibility: defaultColumnVisibility, globalFilter: defaultGlobalFilter, density: defaultDensity, }, }: UseDataTableServerProps) => UseDataTableServerReturn<TData>;
|
|
378
|
-
|
|
379
379
|
interface GetColumnsConfigs<K extends RowData> {
|
|
380
380
|
schema: JSONSchema7;
|
|
381
381
|
ignore?: K[];
|
|
@@ -389,13 +389,14 @@ declare const widthSanityCheck: <K extends unknown>(widthList: number[], ignoreL
|
|
|
389
389
|
declare const getColumns: <TData extends unknown>({ schema, ignore, width, meta, defaultWidth, }: GetColumnsConfigs<TData>) => ColumnDef<TData>[];
|
|
390
390
|
|
|
391
391
|
interface EmptyStateProps {
|
|
392
|
-
|
|
393
|
-
|
|
392
|
+
query: UseQueryResult;
|
|
393
|
+
title?: string;
|
|
394
|
+
description?: string;
|
|
394
395
|
}
|
|
395
396
|
declare const EmptyState: ({ title, description, }: EmptyStateProps) => react_jsx_runtime.JSX.Element;
|
|
396
397
|
|
|
397
398
|
interface ErrorAlertProps {
|
|
398
|
-
showMessage
|
|
399
|
+
showMessage?: boolean;
|
|
399
400
|
}
|
|
400
401
|
declare const ErrorAlert: ({ showMessage }: ErrorAlertProps) => react_jsx_runtime.JSX.Element;
|
|
401
402
|
|
package/dist/index.js
CHANGED
|
@@ -846,7 +846,7 @@ function DataTableServer({ columns, enableRowSelection = true, enableMultiRowSel
|
|
|
846
846
|
globalFilter,
|
|
847
847
|
setGlobalFilter,
|
|
848
848
|
type: "server",
|
|
849
|
-
}, children: jsxRuntime.jsx(DataTableServerContext.Provider, { value: { url }, children: children }) }));
|
|
849
|
+
}, children: jsxRuntime.jsx(DataTableServerContext.Provider, { value: { url, query }, children: children }) }));
|
|
850
850
|
}
|
|
851
851
|
|
|
852
852
|
const Checkbox = React__namespace.forwardRef(function Checkbox(props, ref) {
|
|
@@ -1113,7 +1113,10 @@ const DefaultTable = ({ showFooter = false, tableProps = {}, tableHeaderProps =
|
|
|
1113
1113
|
};
|
|
1114
1114
|
|
|
1115
1115
|
const useDataTableServerContext = () => {
|
|
1116
|
-
|
|
1116
|
+
const context = React.useContext(DataTableServerContext);
|
|
1117
|
+
const { query } = context;
|
|
1118
|
+
const isEmpty = (query.data?.count ?? 0) <= 0;
|
|
1119
|
+
return { ...context, isEmpty };
|
|
1117
1120
|
};
|
|
1118
1121
|
|
|
1119
1122
|
const ReloadButton = ({ text = "Reload", variant = "icon", }) => {
|
|
@@ -1501,12 +1504,11 @@ const getColumns = ({ schema, ignore = [], width = [], meta = {}, defaultWidth =
|
|
|
1501
1504
|
};
|
|
1502
1505
|
|
|
1503
1506
|
const EmptyState = ({ title = "No records", description = "Add a new events to get started or refine your search", }) => {
|
|
1504
|
-
const {
|
|
1505
|
-
|
|
1506
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: (data ?? { count: 0 }).count <= 0 && (jsxRuntime.jsx(react.EmptyState.Root, { children: jsxRuntime.jsxs(react.EmptyState.Content, { children: [jsxRuntime.jsx(react.EmptyState.Indicator, { children: jsxRuntime.jsx(hi.HiColorSwatch, {}) }), jsxRuntime.jsxs(react.VStack, { textAlign: "center", children: [jsxRuntime.jsx(react.EmptyState.Title, { children: title }), jsxRuntime.jsx(react.EmptyState.Description, { children: description })] })] }) })) }));
|
|
1507
|
+
const { isEmpty } = useDataTableServerContext();
|
|
1508
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: isEmpty && (jsxRuntime.jsx(react.EmptyState.Root, { children: jsxRuntime.jsxs(react.EmptyState.Content, { children: [jsxRuntime.jsx(react.EmptyState.Indicator, { children: jsxRuntime.jsx(hi.HiColorSwatch, {}) }), jsxRuntime.jsxs(react.VStack, { textAlign: "center", children: [jsxRuntime.jsx(react.EmptyState.Title, { children: title }), jsxRuntime.jsx(react.EmptyState.Description, { children: description })] })] }) })) }));
|
|
1507
1509
|
};
|
|
1508
1510
|
|
|
1509
|
-
const ErrorAlert = ({ showMessage }) => {
|
|
1511
|
+
const ErrorAlert = ({ showMessage = true }) => {
|
|
1510
1512
|
const { query } = useDataTableContext();
|
|
1511
1513
|
const { isError, error } = query;
|
|
1512
1514
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: isError && (jsxRuntime.jsxs(react.Alert.Root, { status: "error", children: [jsxRuntime.jsx(react.Alert.Indicator, {}), jsxRuntime.jsxs(react.Alert.Content, { children: [jsxRuntime.jsx(react.Alert.Title, { children: error.name }), showMessage && (jsxRuntime.jsx(react.Alert.Description, { children: error.message }))] })] })) }));
|
package/dist/index.mjs
CHANGED
|
@@ -826,7 +826,7 @@ function DataTableServer({ columns, enableRowSelection = true, enableMultiRowSel
|
|
|
826
826
|
globalFilter,
|
|
827
827
|
setGlobalFilter,
|
|
828
828
|
type: "server",
|
|
829
|
-
}, children: jsx(DataTableServerContext.Provider, { value: { url }, children: children }) }));
|
|
829
|
+
}, children: jsx(DataTableServerContext.Provider, { value: { url, query }, children: children }) }));
|
|
830
830
|
}
|
|
831
831
|
|
|
832
832
|
const Checkbox = React.forwardRef(function Checkbox(props, ref) {
|
|
@@ -1093,7 +1093,10 @@ const DefaultTable = ({ showFooter = false, tableProps = {}, tableHeaderProps =
|
|
|
1093
1093
|
};
|
|
1094
1094
|
|
|
1095
1095
|
const useDataTableServerContext = () => {
|
|
1096
|
-
|
|
1096
|
+
const context = useContext(DataTableServerContext);
|
|
1097
|
+
const { query } = context;
|
|
1098
|
+
const isEmpty = (query.data?.count ?? 0) <= 0;
|
|
1099
|
+
return { ...context, isEmpty };
|
|
1097
1100
|
};
|
|
1098
1101
|
|
|
1099
1102
|
const ReloadButton = ({ text = "Reload", variant = "icon", }) => {
|
|
@@ -1481,12 +1484,11 @@ const getColumns = ({ schema, ignore = [], width = [], meta = {}, defaultWidth =
|
|
|
1481
1484
|
};
|
|
1482
1485
|
|
|
1483
1486
|
const EmptyState = ({ title = "No records", description = "Add a new events to get started or refine your search", }) => {
|
|
1484
|
-
const {
|
|
1485
|
-
|
|
1486
|
-
return (jsx(Fragment, { children: (data ?? { count: 0 }).count <= 0 && (jsx(EmptyState$2.Root, { children: jsxs(EmptyState$2.Content, { children: [jsx(EmptyState$2.Indicator, { children: jsx(HiColorSwatch, {}) }), jsxs(VStack, { textAlign: "center", children: [jsx(EmptyState$2.Title, { children: title }), jsx(EmptyState$2.Description, { children: description })] })] }) })) }));
|
|
1487
|
+
const { isEmpty } = useDataTableServerContext();
|
|
1488
|
+
return (jsx(Fragment, { children: isEmpty && (jsx(EmptyState$2.Root, { children: jsxs(EmptyState$2.Content, { children: [jsx(EmptyState$2.Indicator, { children: jsx(HiColorSwatch, {}) }), jsxs(VStack, { textAlign: "center", children: [jsx(EmptyState$2.Title, { children: title }), jsx(EmptyState$2.Description, { children: description })] })] }) })) }));
|
|
1487
1489
|
};
|
|
1488
1490
|
|
|
1489
|
-
const ErrorAlert = ({ showMessage }) => {
|
|
1491
|
+
const ErrorAlert = ({ showMessage = true }) => {
|
|
1490
1492
|
const { query } = useDataTableContext();
|
|
1491
1493
|
const { isError, error } = query;
|
|
1492
1494
|
return (jsx(Fragment, { children: isError && (jsxs(Alert.Root, { status: "error", children: [jsx(Alert.Indicator, {}), jsxs(Alert.Content, { children: [jsx(Alert.Title, { children: error.name }), showMessage && (jsx(Alert.Description, { children: error.message }))] })] })) }));
|
|
@@ -2,7 +2,8 @@ import { ReactNode } from "react";
|
|
|
2
2
|
import { UseQueryResult } from "@tanstack/react-query";
|
|
3
3
|
import { ColumnDef, ColumnFiltersState, ColumnOrderState, OnChangeFn, PaginationState, RowSelectionState, SortingState, VisibilityState } from "@tanstack/react-table";
|
|
4
4
|
import { DensityState } from "../Controls/DensityFeature";
|
|
5
|
-
|
|
5
|
+
import { DataResponse } from "./useDataTableServer";
|
|
6
|
+
export interface DataTableServerProps<TData extends DataResponse = DataResponse<unknown>> {
|
|
6
7
|
children: ReactNode | ReactNode[];
|
|
7
8
|
columns: ColumnDef<TData>[];
|
|
8
9
|
enableRowSelection?: boolean;
|
|
@@ -27,4 +28,4 @@ export interface DataTableServerProps<TData> {
|
|
|
27
28
|
query: UseQueryResult<TData>;
|
|
28
29
|
url: string;
|
|
29
30
|
}
|
|
30
|
-
export declare function DataTableServer<TData = unknown
|
|
31
|
+
export declare function DataTableServer<TData extends DataResponse = DataResponse<unknown>>({ columns, enableRowSelection, enableMultiRowSelection, enableSubRowSelection, columnOrder, columnFilters, columnVisibility, density, globalFilter, pagination, sorting, rowSelection, setPagination, setSorting, setColumnFilters, setRowSelection, setGlobalFilter, setColumnOrder, setDensity, setColumnVisibility, query, children, url, }: DataTableServerProps<TData>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { UseQueryResult } from "@tanstack/react-query";
|
|
1
2
|
export interface EmptyStateProps {
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
query: UseQueryResult;
|
|
4
|
+
title?: string;
|
|
5
|
+
description?: string;
|
|
4
6
|
}
|
|
5
7
|
export declare const EmptyState: ({ title, description, }: EmptyStateProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
|
|
2
|
+
import { UseQueryResult } from "@tanstack/react-query";
|
|
3
|
+
import { DataResponse } from "../useDataTableServer";
|
|
4
|
+
export interface DataTableServerContext<T extends DataResponse = DataResponse<unknown>> {
|
|
3
5
|
url: string;
|
|
6
|
+
query: UseQueryResult<T>;
|
|
4
7
|
}
|
|
5
|
-
export declare const DataTableServerContext: import("react").Context<DataTableServerContext
|
|
8
|
+
export declare const DataTableServerContext: import("react").Context<DataTableServerContext<DataResponse<unknown>>>;
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { DataTableServerContext } from "./DataTableServerContext";
|
|
2
|
-
export
|
|
2
|
+
export interface UseDataTableServerContext extends DataTableServerContext {
|
|
3
|
+
isEmpty: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare const useDataTableServerContext: () => UseDataTableServerContext;
|
|
@@ -18,10 +18,10 @@ export interface UseDataTableServerProps extends UseDataTableProps {
|
|
|
18
18
|
export interface UseDataTableServerReturn<TData> extends UseDataTableReturn {
|
|
19
19
|
query: UseQueryResult<DataResponse<TData>, Error>;
|
|
20
20
|
}
|
|
21
|
-
export interface Result<T> {
|
|
21
|
+
export interface Result<T = unknown> {
|
|
22
22
|
data: T[];
|
|
23
23
|
}
|
|
24
|
-
export interface DataResponse<T> extends Result<T> {
|
|
24
|
+
export interface DataResponse<T = unknown> extends Result<T> {
|
|
25
25
|
count: number;
|
|
26
26
|
}
|
|
27
27
|
export declare const useDataTableServer: <TData>({ url, default: { sorting: defaultSorting, pagination: defaultPagination, rowSelection: defaultRowSelection, columnFilters: defaultColumnFilters, columnOrder: defaultColumnOrder, columnVisibility: defaultColumnVisibility, globalFilter: defaultGlobalFilter, density: defaultDensity, }, }: UseDataTableServerProps) => UseDataTableServerReturn<TData>;
|