@bsol-oss/react-datatable5 7.6.0 → 7.6.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/README.md +16 -7
- package/dist/index.d.ts +11 -11
- package/dist/index.js +122 -122
- package/dist/index.mjs +123 -123
- package/dist/types/components/DataTable/DataTable.d.ts +1 -1
- package/dist/types/components/DataTable/DefaultTable.d.ts +1 -1
- package/dist/types/components/DataTable/context/DataTableContext.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# React Datatable
|
|
2
2
|
|
|
3
|
+
The datetable package is built on top of `@tanstack/react-table` and `chakra-ui` to create a robust datatable. This hook simplifies to initialize the state management for controlling the datatable, and it offers several predefined tables and controls in to enhance data visualization.
|
|
4
|
+
|
|
3
5
|
## Installation
|
|
4
6
|
|
|
5
7
|
```bash
|
|
@@ -10,11 +12,11 @@ npm install @tanstack/react-table @chakra-ui/react @emotion/react @bsol-oss/reac
|
|
|
10
12
|
|
|
11
13
|
### Hook
|
|
12
14
|
|
|
13
|
-
The `DataTable` and `DataTableServer` utilize hook to add props.
|
|
15
|
+
The `DataTable` and `DataTableServer` utilize hook to add props.
|
|
14
16
|
|
|
15
17
|
```tsx
|
|
16
18
|
const datatable = useDataTable();
|
|
17
|
-
const datatableServer = useDataTableServer({url: "<some-url>"});
|
|
19
|
+
const datatableServer = useDataTableServer({ url: "<some-url>" });
|
|
18
20
|
```
|
|
19
21
|
|
|
20
22
|
### DataTable
|
|
@@ -43,10 +45,7 @@ const datatableServer = useDataTableServer({url: "<some-url>"});
|
|
|
43
45
|
### DataTableServer
|
|
44
46
|
|
|
45
47
|
```tsx
|
|
46
|
-
<DataTableServer
|
|
47
|
-
columns={columns}
|
|
48
|
-
{...datatable}
|
|
49
|
-
>
|
|
48
|
+
<DataTableServer columns={columns} {...datatable}>
|
|
50
49
|
<Flex>
|
|
51
50
|
<TablePagination />
|
|
52
51
|
<EditViewButton />
|
|
@@ -76,7 +75,7 @@ const datatableServer = useDataTableServer({url: "<some-url>"});
|
|
|
76
75
|
Example Url generated by the DataTableServer
|
|
77
76
|
|
|
78
77
|
```
|
|
79
|
-
GET http://localhost:
|
|
78
|
+
GET http://localhost:8081/api/g/core_people?offset=0&limit=10&sorting[0][id]=id&sorting[0][desc]=false&where[0][id]=last_name&where[0][value]=nicenice&searching=good
|
|
80
79
|
```
|
|
81
80
|
|
|
82
81
|
### DefaultTable
|
|
@@ -112,6 +111,16 @@ GET http://localhost:8333/api/v1/gpt/chat/history/all?pagination={"offset":0,"ro
|
|
|
112
111
|
</DataTable>
|
|
113
112
|
```
|
|
114
113
|
|
|
114
|
+
### DataDisplay
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
<DataTable columns={columns} data={data} {...datatable}>
|
|
118
|
+
<DataDisplay />
|
|
119
|
+
</DataTable>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
For more details of props and examples, please review the stories in storybook platform.
|
|
123
|
+
|
|
115
124
|
## Development
|
|
116
125
|
|
|
117
126
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -117,7 +117,7 @@ declare module "@tanstack/react-table" {
|
|
|
117
117
|
itemRank: RankingInfo;
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
interface DataTableProps<TData> {
|
|
120
|
+
interface DataTableProps<TData = unknown> {
|
|
121
121
|
children?: ReactNode | ReactNode[];
|
|
122
122
|
data: TData[];
|
|
123
123
|
columns: ColumnDef<TData, unknown>[];
|
|
@@ -292,6 +292,15 @@ interface TableHeaderProps {
|
|
|
292
292
|
}
|
|
293
293
|
declare const TableHeader: ({ canResize, pinnedBgColor, showSelector, isSticky, alwaysShowSelector, tHeadProps, }: TableHeaderProps) => react_jsx_runtime.JSX.Element;
|
|
294
294
|
|
|
295
|
+
interface TableProps extends TableRootProps {
|
|
296
|
+
showLoading?: boolean;
|
|
297
|
+
loadingComponent?: ReactNode;
|
|
298
|
+
emptyComponent?: ReactNode;
|
|
299
|
+
canResize?: boolean;
|
|
300
|
+
children: ReactNode;
|
|
301
|
+
}
|
|
302
|
+
declare const Table: ({ children, emptyComponent, canResize, ...props }: TableProps) => string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | React$1.ReactPortal | React$1.ReactElement<unknown, string | React$1.JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | react_jsx_runtime.JSX.Element | null;
|
|
303
|
+
|
|
295
304
|
interface DefaultTableProps {
|
|
296
305
|
showFooter?: boolean;
|
|
297
306
|
showSelector?: boolean;
|
|
@@ -311,15 +320,6 @@ interface ReloadButtonProps {
|
|
|
311
320
|
}
|
|
312
321
|
declare const ReloadButton: ({ text, variant, }: ReloadButtonProps) => react_jsx_runtime.JSX.Element;
|
|
313
322
|
|
|
314
|
-
interface TableProps extends TableRootProps {
|
|
315
|
-
showLoading?: boolean;
|
|
316
|
-
loadingComponent?: ReactNode;
|
|
317
|
-
emptyComponent?: ReactNode;
|
|
318
|
-
canResize?: boolean;
|
|
319
|
-
children: ReactNode;
|
|
320
|
-
}
|
|
321
|
-
declare const Table: ({ children, emptyComponent, canResize, ...props }: TableProps) => string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | React$1.ReactPortal | React$1.ReactElement<unknown, string | React$1.JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | react_jsx_runtime.JSX.Element | null;
|
|
322
|
-
|
|
323
323
|
interface TableCardContainerProps extends GridProps {
|
|
324
324
|
children: ReactNode;
|
|
325
325
|
variant?: "carousel" | "";
|
|
@@ -366,7 +366,7 @@ interface TextCellProps {
|
|
|
366
366
|
}
|
|
367
367
|
declare const TextCell: ({ label, containerProps, textProps, children, }: TextCellProps) => react_jsx_runtime.JSX.Element;
|
|
368
368
|
|
|
369
|
-
interface DataTableContext<TData> {
|
|
369
|
+
interface DataTableContext<TData = unknown> {
|
|
370
370
|
table: Table$1<TData>;
|
|
371
371
|
globalFilter: string;
|
|
372
372
|
setGlobalFilter: OnChangeFn<string>;
|
package/dist/index.js
CHANGED
|
@@ -11,16 +11,16 @@ var fa6 = require('react-icons/fa6');
|
|
|
11
11
|
var bi = require('react-icons/bi');
|
|
12
12
|
var cg = require('react-icons/cg');
|
|
13
13
|
var io = require('react-icons/io');
|
|
14
|
+
var adapter = require('@atlaskit/pragmatic-drag-and-drop/element/adapter');
|
|
15
|
+
var invariant = require('tiny-invariant');
|
|
14
16
|
var hi2 = require('react-icons/hi2');
|
|
15
17
|
var reactTable = require('@tanstack/react-table');
|
|
16
18
|
var matchSorterUtils = require('@tanstack/match-sorter-utils');
|
|
17
19
|
var bs = require('react-icons/bs');
|
|
18
20
|
var gr = require('react-icons/gr');
|
|
21
|
+
var hi = require('react-icons/hi');
|
|
19
22
|
var reactQuery = require('@tanstack/react-query');
|
|
20
23
|
var io5 = require('react-icons/io5');
|
|
21
|
-
var hi = require('react-icons/hi');
|
|
22
|
-
var adapter = require('@atlaskit/pragmatic-drag-and-drop/element/adapter');
|
|
23
|
-
var invariant = require('tiny-invariant');
|
|
24
24
|
var axios = require('axios');
|
|
25
25
|
var usehooks = require('@uidotdev/usehooks');
|
|
26
26
|
var reactHookForm = require('react-hook-form');
|
|
@@ -458,6 +458,107 @@ const EditSortingButton = ({ text, icon = jsxRuntime.jsx(md.MdOutlineSort, {}),
|
|
|
458
458
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(DialogRoot, { size: ["full", "full", "md", "md"], children: [jsxRuntime.jsx(react.DialogBackdrop, {}), jsxRuntime.jsx(DialogTrigger, { children: jsxRuntime.jsxs(react.Button, { as: "div", variant: "ghost", onClick: sortingModal.onOpen, children: [icon, " ", text] }) }), jsxRuntime.jsxs(DialogContent, { children: [jsxRuntime.jsx(DialogCloseTrigger, {}), jsxRuntime.jsxs(DialogHeader, { children: [jsxRuntime.jsx(DialogTitle, {}), title] }), jsxRuntime.jsx(DialogBody, { children: jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(TableSorter, {}), jsxRuntime.jsx(ResetSortingButton, {})] }) }), jsxRuntime.jsx(DialogFooter, {})] })] }) }));
|
|
459
459
|
};
|
|
460
460
|
|
|
461
|
+
const CheckboxCard = React__namespace.forwardRef(function CheckboxCard(props, ref) {
|
|
462
|
+
const { inputProps, label, description, icon, addon, indicator = jsxRuntime.jsx(react.CheckboxCard.Indicator, {}), indicatorPlacement = "end", ...rest } = props;
|
|
463
|
+
const hasContent = label || description || icon;
|
|
464
|
+
const ContentWrapper = indicator ? react.CheckboxCard.Content : React__namespace.Fragment;
|
|
465
|
+
return (jsxRuntime.jsxs(react.CheckboxCard.Root, { ...rest, children: [jsxRuntime.jsx(react.CheckboxCard.HiddenInput, { ref: ref, ...inputProps }), jsxRuntime.jsxs(react.CheckboxCard.Control, { children: [indicatorPlacement === "start" && indicator, hasContent && (jsxRuntime.jsxs(ContentWrapper, { children: [icon, label && (jsxRuntime.jsx(react.CheckboxCard.Label, { children: label })), description && (jsxRuntime.jsx(react.CheckboxCard.Description, { children: description })), indicatorPlacement === "inside" && indicator] })), indicatorPlacement === "end" && indicator] }), addon && jsxRuntime.jsx(react.CheckboxCard.Addon, { children: addon })] }));
|
|
466
|
+
});
|
|
467
|
+
react.CheckboxCard.Indicator;
|
|
468
|
+
|
|
469
|
+
function ColumnCard({ columnId }) {
|
|
470
|
+
const ref = React.useRef(null);
|
|
471
|
+
const [dragging, setDragging] = React.useState(false); // NEW
|
|
472
|
+
const { table } = useDataTableContext();
|
|
473
|
+
const displayName = columnId;
|
|
474
|
+
const column = table.getColumn(columnId);
|
|
475
|
+
invariant(column);
|
|
476
|
+
React.useEffect(() => {
|
|
477
|
+
const el = ref.current;
|
|
478
|
+
invariant(el);
|
|
479
|
+
return adapter.draggable({
|
|
480
|
+
element: el,
|
|
481
|
+
getInitialData: () => {
|
|
482
|
+
return { column: table.getColumn(columnId) };
|
|
483
|
+
},
|
|
484
|
+
onDragStart: () => setDragging(true), // NEW
|
|
485
|
+
onDrop: () => setDragging(false), // NEW
|
|
486
|
+
});
|
|
487
|
+
}, [columnId, table]);
|
|
488
|
+
return (jsxRuntime.jsxs(react.Grid, { ref: ref, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", style: dragging ? { opacity: 0.4 } : {}, children: [jsxRuntime.jsx(react.Flex, { alignItems: "center", padding: "0", children: jsxRuntime.jsx(fa6.FaGripLinesVertical, { color: "gray.400" }) }), jsxRuntime.jsx(react.Flex, { justifyContent: "space-between", alignItems: "center", children: jsxRuntime.jsx(CheckboxCard, { variant: "surface", label: displayName, checked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() }) })] }));
|
|
489
|
+
}
|
|
490
|
+
function CardContainer({ location, children }) {
|
|
491
|
+
const ref = React.useRef(null);
|
|
492
|
+
const [isDraggedOver, setIsDraggedOver] = React.useState(false);
|
|
493
|
+
React.useEffect(() => {
|
|
494
|
+
const el = ref.current;
|
|
495
|
+
invariant(el);
|
|
496
|
+
return adapter.dropTargetForElements({
|
|
497
|
+
element: el,
|
|
498
|
+
getData: () => ({ location }),
|
|
499
|
+
onDragEnter: () => setIsDraggedOver(true),
|
|
500
|
+
onDragLeave: () => setIsDraggedOver(false),
|
|
501
|
+
onDrop: () => setIsDraggedOver(false),
|
|
502
|
+
});
|
|
503
|
+
}, [location]);
|
|
504
|
+
// const isDark = (location + location) % 2 === 1;
|
|
505
|
+
function getColor(isDraggedOver) {
|
|
506
|
+
if (isDraggedOver) {
|
|
507
|
+
return {
|
|
508
|
+
backgroundColor: "blue.400",
|
|
509
|
+
_dark: {
|
|
510
|
+
backgroundColor: "blue.400",
|
|
511
|
+
},
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
// return isDark ? "lightgrey" : "white";
|
|
515
|
+
return {
|
|
516
|
+
backgroundColor: undefined,
|
|
517
|
+
_dark: {
|
|
518
|
+
backgroundColor: undefined,
|
|
519
|
+
},
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
return (jsxRuntime.jsx(react.Box, { ...getColor(isDraggedOver), ref: ref, children: children }));
|
|
523
|
+
}
|
|
524
|
+
const TableViewer = () => {
|
|
525
|
+
const { table } = useDataTableContext();
|
|
526
|
+
const [order, setOrder] = React.useState(table.getAllLeafColumns().map((column) => {
|
|
527
|
+
return column.id;
|
|
528
|
+
}));
|
|
529
|
+
React.useEffect(() => {
|
|
530
|
+
return adapter.monitorForElements({
|
|
531
|
+
onDrop({ source, location }) {
|
|
532
|
+
const destination = location.current.dropTargets[0];
|
|
533
|
+
if (!destination) {
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
const destinationLocation = destination.data.location;
|
|
537
|
+
// const sourceLocation = source.data.location;
|
|
538
|
+
const sourceColumn = source.data.column;
|
|
539
|
+
const columnOrder = order.map((id) => {
|
|
540
|
+
if (id == sourceColumn.id) {
|
|
541
|
+
return "<marker>";
|
|
542
|
+
}
|
|
543
|
+
return id;
|
|
544
|
+
});
|
|
545
|
+
const columnBefore = columnOrder.slice(0, destinationLocation + 1);
|
|
546
|
+
const columnAfter = columnOrder.slice(destinationLocation + 1, columnOrder.length);
|
|
547
|
+
const newOrder = [
|
|
548
|
+
...columnBefore,
|
|
549
|
+
sourceColumn.id,
|
|
550
|
+
...columnAfter,
|
|
551
|
+
].filter((id) => id != "<marker>");
|
|
552
|
+
table.setColumnOrder(newOrder);
|
|
553
|
+
setOrder(newOrder);
|
|
554
|
+
},
|
|
555
|
+
});
|
|
556
|
+
}, [order, table]);
|
|
557
|
+
return (jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: "0.25rem", children: table.getState().columnOrder.map((columnId, index) => {
|
|
558
|
+
return (jsxRuntime.jsx(CardContainer, { location: index, children: jsxRuntime.jsx(ColumnCard, { columnId: columnId }) }));
|
|
559
|
+
}) }));
|
|
560
|
+
};
|
|
561
|
+
|
|
461
562
|
const EditViewButton = ({ text, icon = jsxRuntime.jsx(io.IoMdEye, {}), title = "Edit View", }) => {
|
|
462
563
|
const viewModel = react.useDisclosure();
|
|
463
564
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(DialogRoot, { children: [jsxRuntime.jsx(react.DialogBackdrop, {}), jsxRuntime.jsx(DialogTrigger, { asChild: true, children: jsxRuntime.jsxs(react.Button, { as: react.Box, variant: "ghost", onClick: viewModel.onOpen, children: [icon, " ", text] }) }), jsxRuntime.jsxs(DialogContent, { children: [jsxRuntime.jsx(DialogCloseTrigger, {}), jsxRuntime.jsxs(DialogHeader, { children: [jsxRuntime.jsx(DialogTitle, {}), title] }), jsxRuntime.jsx(DialogBody, { children: jsxRuntime.jsx(TableViewer, {}) }), jsxRuntime.jsx(DialogFooter, {})] })] }) }));
|
|
@@ -833,7 +934,7 @@ function DataTable({ columns, data, enableRowSelection = true, enableMultiRowSel
|
|
|
833
934
|
onColumnVisibilityChange: setColumnVisibility,
|
|
834
935
|
});
|
|
835
936
|
return (jsxRuntime.jsx(DataTableContext.Provider, { value: {
|
|
836
|
-
table:
|
|
937
|
+
table: table,
|
|
837
938
|
globalFilter: globalFilter,
|
|
838
939
|
setGlobalFilter: setGlobalFilter,
|
|
839
940
|
type: "client",
|
|
@@ -1156,6 +1257,20 @@ const TableHeader = ({ canResize = true, pinnedBgColor = { light: "gray.50", dar
|
|
|
1156
1257
|
})] }, `chakra-table-headergroup-${headerGroup.id}`))) }));
|
|
1157
1258
|
};
|
|
1158
1259
|
|
|
1260
|
+
const EmptyState$1 = React__namespace.forwardRef(function EmptyState(props, ref) {
|
|
1261
|
+
const { title, description, icon, children, ...rest } = props;
|
|
1262
|
+
return (jsxRuntime.jsx(react.EmptyState.Root, { ref: ref, ...rest, children: jsxRuntime.jsxs(react.EmptyState.Content, { children: [icon && (jsxRuntime.jsx(react.EmptyState.Indicator, { children: icon })), description ? (jsxRuntime.jsxs(react.VStack, { textAlign: "center", children: [jsxRuntime.jsx(react.EmptyState.Title, { children: title }), jsxRuntime.jsx(react.EmptyState.Description, { children: description })] })) : (jsxRuntime.jsx(react.EmptyState.Title, { children: title })), children] }) }));
|
|
1263
|
+
});
|
|
1264
|
+
|
|
1265
|
+
const EmptyResult = (jsxRuntime.jsx(EmptyState$1, { icon: jsxRuntime.jsx(hi.HiColorSwatch, {}), title: "No results found", description: "Try adjusting your search", children: jsxRuntime.jsxs(react.List.Root, { variant: "marker", children: [jsxRuntime.jsx(react.List.Item, { children: "Try removing filters" }), jsxRuntime.jsx(react.List.Item, { children: "Try different keywords" })] }) }));
|
|
1266
|
+
const Table = ({ children, emptyComponent = EmptyResult, canResize = true, ...props }) => {
|
|
1267
|
+
const { table } = useDataTableContext();
|
|
1268
|
+
if (table.getRowModel().rows.length <= 0) {
|
|
1269
|
+
return emptyComponent;
|
|
1270
|
+
}
|
|
1271
|
+
return (jsxRuntime.jsx(react.Table.Root, { stickyHeader: true, variant: "outline", width: canResize ? table.getCenterTotalSize() : undefined, ...props, children: children }));
|
|
1272
|
+
};
|
|
1273
|
+
|
|
1159
1274
|
const DefaultTable = ({ showFooter = false, tableProps = {}, tableHeaderProps = {}, tableBodyProps = {}, controlProps = {}, tableFooterProps = {}, variant = "", }) => {
|
|
1160
1275
|
if (variant === "greedy") {
|
|
1161
1276
|
return (jsxRuntime.jsx(TableControls, { ...controlProps, children: jsxRuntime.jsxs(Table, { canResize: false, ...tableProps, children: [jsxRuntime.jsx(TableHeader, { canResize: false, ...tableHeaderProps }), jsxRuntime.jsx(TableBody, { canResize: false, ...tableBodyProps }), showFooter && (jsxRuntime.jsx(TableFooter, { canResize: false, ...tableFooterProps }))] }) }));
|
|
@@ -1183,20 +1298,6 @@ const ReloadButton = ({ text = "Reload", variant = "icon", }) => {
|
|
|
1183
1298
|
}, children: [jsxRuntime.jsx(io5.IoReload, {}), " ", text] }));
|
|
1184
1299
|
};
|
|
1185
1300
|
|
|
1186
|
-
const EmptyState$1 = React__namespace.forwardRef(function EmptyState(props, ref) {
|
|
1187
|
-
const { title, description, icon, children, ...rest } = props;
|
|
1188
|
-
return (jsxRuntime.jsx(react.EmptyState.Root, { ref: ref, ...rest, children: jsxRuntime.jsxs(react.EmptyState.Content, { children: [icon && (jsxRuntime.jsx(react.EmptyState.Indicator, { children: icon })), description ? (jsxRuntime.jsxs(react.VStack, { textAlign: "center", children: [jsxRuntime.jsx(react.EmptyState.Title, { children: title }), jsxRuntime.jsx(react.EmptyState.Description, { children: description })] })) : (jsxRuntime.jsx(react.EmptyState.Title, { children: title })), children] }) }));
|
|
1189
|
-
});
|
|
1190
|
-
|
|
1191
|
-
const EmptyResult = (jsxRuntime.jsx(EmptyState$1, { icon: jsxRuntime.jsx(hi.HiColorSwatch, {}), title: "No results found", description: "Try adjusting your search", children: jsxRuntime.jsxs(react.List.Root, { variant: "marker", children: [jsxRuntime.jsx(react.List.Item, { children: "Try removing filters" }), jsxRuntime.jsx(react.List.Item, { children: "Try different keywords" })] }) }));
|
|
1192
|
-
const Table = ({ children, emptyComponent = EmptyResult, canResize = true, ...props }) => {
|
|
1193
|
-
const { table } = useDataTableContext();
|
|
1194
|
-
if (table.getRowModel().rows.length <= 0) {
|
|
1195
|
-
return emptyComponent;
|
|
1196
|
-
}
|
|
1197
|
-
return (jsxRuntime.jsx(react.Table.Root, { stickyHeader: true, variant: "outline", width: canResize ? table.getCenterTotalSize() : undefined, ...props, children: children }));
|
|
1198
|
-
};
|
|
1199
|
-
|
|
1200
1301
|
const TableCardContainer = ({ children, variant = "", ...props }) => {
|
|
1201
1302
|
if (variant === "carousel") {
|
|
1202
1303
|
return (jsxRuntime.jsx(react.Flex, { overflow: "scroll", gap: "1rem", children: children }));
|
|
@@ -1261,107 +1362,6 @@ const TableSelector = () => {
|
|
|
1261
1362
|
}, "aria-label": "reset selection", children: jsxRuntime.jsx(md.MdClear, {}) }))] }));
|
|
1262
1363
|
};
|
|
1263
1364
|
|
|
1264
|
-
const CheckboxCard = React__namespace.forwardRef(function CheckboxCard(props, ref) {
|
|
1265
|
-
const { inputProps, label, description, icon, addon, indicator = jsxRuntime.jsx(react.CheckboxCard.Indicator, {}), indicatorPlacement = "end", ...rest } = props;
|
|
1266
|
-
const hasContent = label || description || icon;
|
|
1267
|
-
const ContentWrapper = indicator ? react.CheckboxCard.Content : React__namespace.Fragment;
|
|
1268
|
-
return (jsxRuntime.jsxs(react.CheckboxCard.Root, { ...rest, children: [jsxRuntime.jsx(react.CheckboxCard.HiddenInput, { ref: ref, ...inputProps }), jsxRuntime.jsxs(react.CheckboxCard.Control, { children: [indicatorPlacement === "start" && indicator, hasContent && (jsxRuntime.jsxs(ContentWrapper, { children: [icon, label && (jsxRuntime.jsx(react.CheckboxCard.Label, { children: label })), description && (jsxRuntime.jsx(react.CheckboxCard.Description, { children: description })), indicatorPlacement === "inside" && indicator] })), indicatorPlacement === "end" && indicator] }), addon && jsxRuntime.jsx(react.CheckboxCard.Addon, { children: addon })] }));
|
|
1269
|
-
});
|
|
1270
|
-
react.CheckboxCard.Indicator;
|
|
1271
|
-
|
|
1272
|
-
function ColumnCard({ columnId }) {
|
|
1273
|
-
const ref = React.useRef(null);
|
|
1274
|
-
const [dragging, setDragging] = React.useState(false); // NEW
|
|
1275
|
-
const { table } = useDataTableContext();
|
|
1276
|
-
const displayName = columnId;
|
|
1277
|
-
const column = table.getColumn(columnId);
|
|
1278
|
-
invariant(column);
|
|
1279
|
-
React.useEffect(() => {
|
|
1280
|
-
const el = ref.current;
|
|
1281
|
-
invariant(el);
|
|
1282
|
-
return adapter.draggable({
|
|
1283
|
-
element: el,
|
|
1284
|
-
getInitialData: () => {
|
|
1285
|
-
return { column: table.getColumn(columnId) };
|
|
1286
|
-
},
|
|
1287
|
-
onDragStart: () => setDragging(true), // NEW
|
|
1288
|
-
onDrop: () => setDragging(false), // NEW
|
|
1289
|
-
});
|
|
1290
|
-
}, [columnId, table]);
|
|
1291
|
-
return (jsxRuntime.jsxs(react.Grid, { ref: ref, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", style: dragging ? { opacity: 0.4 } : {}, children: [jsxRuntime.jsx(react.Flex, { alignItems: "center", padding: "0", children: jsxRuntime.jsx(fa6.FaGripLinesVertical, { color: "gray.400" }) }), jsxRuntime.jsx(react.Flex, { justifyContent: "space-between", alignItems: "center", children: jsxRuntime.jsx(CheckboxCard, { variant: "surface", label: displayName, checked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() }) })] }));
|
|
1292
|
-
}
|
|
1293
|
-
function CardContainer({ location, children }) {
|
|
1294
|
-
const ref = React.useRef(null);
|
|
1295
|
-
const [isDraggedOver, setIsDraggedOver] = React.useState(false);
|
|
1296
|
-
React.useEffect(() => {
|
|
1297
|
-
const el = ref.current;
|
|
1298
|
-
invariant(el);
|
|
1299
|
-
return adapter.dropTargetForElements({
|
|
1300
|
-
element: el,
|
|
1301
|
-
getData: () => ({ location }),
|
|
1302
|
-
onDragEnter: () => setIsDraggedOver(true),
|
|
1303
|
-
onDragLeave: () => setIsDraggedOver(false),
|
|
1304
|
-
onDrop: () => setIsDraggedOver(false),
|
|
1305
|
-
});
|
|
1306
|
-
}, [location]);
|
|
1307
|
-
// const isDark = (location + location) % 2 === 1;
|
|
1308
|
-
function getColor(isDraggedOver) {
|
|
1309
|
-
if (isDraggedOver) {
|
|
1310
|
-
return {
|
|
1311
|
-
backgroundColor: "blue.400",
|
|
1312
|
-
_dark: {
|
|
1313
|
-
backgroundColor: "blue.400",
|
|
1314
|
-
},
|
|
1315
|
-
};
|
|
1316
|
-
}
|
|
1317
|
-
// return isDark ? "lightgrey" : "white";
|
|
1318
|
-
return {
|
|
1319
|
-
backgroundColor: undefined,
|
|
1320
|
-
_dark: {
|
|
1321
|
-
backgroundColor: undefined,
|
|
1322
|
-
},
|
|
1323
|
-
};
|
|
1324
|
-
}
|
|
1325
|
-
return (jsxRuntime.jsx(react.Box, { ...getColor(isDraggedOver), ref: ref, children: children }));
|
|
1326
|
-
}
|
|
1327
|
-
const TableViewer = () => {
|
|
1328
|
-
const { table } = useDataTableContext();
|
|
1329
|
-
const [order, setOrder] = React.useState(table.getAllLeafColumns().map((column) => {
|
|
1330
|
-
return column.id;
|
|
1331
|
-
}));
|
|
1332
|
-
React.useEffect(() => {
|
|
1333
|
-
return adapter.monitorForElements({
|
|
1334
|
-
onDrop({ source, location }) {
|
|
1335
|
-
const destination = location.current.dropTargets[0];
|
|
1336
|
-
if (!destination) {
|
|
1337
|
-
return;
|
|
1338
|
-
}
|
|
1339
|
-
const destinationLocation = destination.data.location;
|
|
1340
|
-
// const sourceLocation = source.data.location;
|
|
1341
|
-
const sourceColumn = source.data.column;
|
|
1342
|
-
const columnOrder = order.map((id) => {
|
|
1343
|
-
if (id == sourceColumn.id) {
|
|
1344
|
-
return "<marker>";
|
|
1345
|
-
}
|
|
1346
|
-
return id;
|
|
1347
|
-
});
|
|
1348
|
-
const columnBefore = columnOrder.slice(0, destinationLocation + 1);
|
|
1349
|
-
const columnAfter = columnOrder.slice(destinationLocation + 1, columnOrder.length);
|
|
1350
|
-
const newOrder = [
|
|
1351
|
-
...columnBefore,
|
|
1352
|
-
sourceColumn.id,
|
|
1353
|
-
...columnAfter,
|
|
1354
|
-
].filter((id) => id != "<marker>");
|
|
1355
|
-
table.setColumnOrder(newOrder);
|
|
1356
|
-
setOrder(newOrder);
|
|
1357
|
-
},
|
|
1358
|
-
});
|
|
1359
|
-
}, [order, table]);
|
|
1360
|
-
return (jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: "0.25rem", children: table.getState().columnOrder.map((columnId, index) => {
|
|
1361
|
-
return (jsxRuntime.jsx(CardContainer, { location: index, children: jsxRuntime.jsx(ColumnCard, { columnId: columnId }) }));
|
|
1362
|
-
}) }));
|
|
1363
|
-
};
|
|
1364
|
-
|
|
1365
1365
|
const TextCell = ({ label, containerProps = {}, textProps = {}, children, }) => {
|
|
1366
1366
|
if (label) {
|
|
1367
1367
|
return (jsxRuntime.jsx(react.Flex, { alignItems: "center", height: "100%", ...containerProps, children: jsxRuntime.jsx(Tooltip, { content: jsxRuntime.jsx(react.Text, { as: "span", overflow: "hidden", textOverflow: "ellipsis", children: label }), children: jsxRuntime.jsx(react.Text, { as: "span", overflow: "hidden", textOverflow: "ellipsis", wordBreak: "break-all", ...textProps, children: children }) }) }));
|
|
@@ -1706,7 +1706,7 @@ const IdPicker = ({ column, in_table, column_ref, display_column, isMultiple = f
|
|
|
1706
1706
|
const [searchText, setSearchText] = React.useState();
|
|
1707
1707
|
const [limit, setLimit] = React.useState(10);
|
|
1708
1708
|
const [openSearchResult, setOpenSearchResult] = React.useState();
|
|
1709
|
-
const [page, setPage] = React.useState(
|
|
1709
|
+
const [page, setPage] = React.useState(0);
|
|
1710
1710
|
const [idMap, setIdMap] = React.useState({});
|
|
1711
1711
|
const ref = React.useRef(null);
|
|
1712
1712
|
const selectedIds = watch(column) ?? [];
|
|
@@ -1767,7 +1767,7 @@ const IdPicker = ({ column, in_table, column_ref, display_column, isMultiple = f
|
|
|
1767
1767
|
const isDirty = (searchText?.length ?? 0) > 0;
|
|
1768
1768
|
const onSearchChange = async (event) => {
|
|
1769
1769
|
setSearchText(event.target.value);
|
|
1770
|
-
setPage(
|
|
1770
|
+
setPage(0);
|
|
1771
1771
|
setLimit(10);
|
|
1772
1772
|
};
|
|
1773
1773
|
const watchId = watch(column);
|
|
@@ -1820,7 +1820,7 @@ const IdPicker = ({ column, in_table, column_ref, display_column, isMultiple = f
|
|
|
1820
1820
|
}, opacity: 0.7, _hover: { opacity: 1 }, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
|
|
1821
1821
|
? renderDisplay(item)
|
|
1822
1822
|
: item[display_column] }, item[column_ref]));
|
|
1823
|
-
}) }), isDirty && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [dataList.length <= 0 && jsxRuntime.jsx(react.Text, { children: "Empty Search Result" }), " "] }))] }), jsxRuntime.jsx(PaginationRoot, { justifySelf: "center", count: query?.data?.count ?? 0, pageSize: 10, defaultPage: 1, page: page, onPageChange: (e) => setPage(e.page), children: jsxRuntime.jsxs(react.HStack, { gap: "4", children: [jsxRuntime.jsx(PaginationPrevTrigger, {}), jsxRuntime.jsx(PaginationPageText, {}), jsxRuntime.jsx(PaginationNextTrigger, {})] }) })] }))] }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: fieldRequired ?? "The field is requried" }))] }));
|
|
1823
|
+
}) }), isDirty && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [dataList.length <= 0 && jsxRuntime.jsx(react.Text, { children: "Empty Search Result" }), " "] }))] }), jsxRuntime.jsx(PaginationRoot, { justifySelf: "center", count: query?.data?.count ?? 0, pageSize: 10, defaultPage: 1, page: page + 1, onPageChange: (e) => setPage(e.page - 1), children: jsxRuntime.jsxs(react.HStack, { gap: "4", children: [jsxRuntime.jsx(PaginationPrevTrigger, {}), jsxRuntime.jsx(PaginationPageText, {}), jsxRuntime.jsx(PaginationNextTrigger, {})] }) })] }))] }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: fieldRequired ?? "The field is requried" }))] }));
|
|
1824
1824
|
};
|
|
1825
1825
|
|
|
1826
1826
|
const ToggleTip = React__namespace.forwardRef(function ToggleTip(props, ref) {
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import { Button as Button$1, AbsoluteCenter, Spinner, Span, IconButton, Portal, Dialog, RadioGroup as RadioGroup$1, Grid, Box, Slider as Slider$1, HStack, For, Flex, Text, Tag as Tag$1, Input, useDisclosure, DialogBackdrop, Menu, createRecipeContext, createContext as createContext$1, Pagination, usePaginationContext, Image, Card, DataList, Checkbox as Checkbox$1, Table as Table$1, Tooltip as Tooltip$1, Icon, MenuRoot as MenuRoot$1, MenuTrigger as MenuTrigger$1, EmptyState as EmptyState$2, VStack, List,
|
|
2
|
+
import { Button as Button$1, AbsoluteCenter, Spinner, Span, IconButton, Portal, Dialog, RadioGroup as RadioGroup$1, Grid, Box, Slider as Slider$1, HStack, For, Flex, Text, Tag as Tag$1, Input, useDisclosure, DialogBackdrop, CheckboxCard as CheckboxCard$1, Menu, createRecipeContext, createContext as createContext$1, Pagination, usePaginationContext, Image, Card, DataList, Checkbox as Checkbox$1, Table as Table$1, Tooltip as Tooltip$1, Icon, MenuRoot as MenuRoot$1, MenuTrigger as MenuTrigger$1, EmptyState as EmptyState$2, VStack, List, Alert, Group, InputElement, Popover, Field as Field$1, NumberInput, Accordion, Show, RadioCard, CheckboxGroup, Heading, Center } from '@chakra-ui/react';
|
|
3
3
|
import { AiOutlineColumnWidth } from 'react-icons/ai';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import React__default, { createContext, useContext, useState, useEffect, useRef, useMemo } from 'react';
|
|
@@ -10,16 +10,16 @@ import { FaUpDown, FaGripLinesVertical } from 'react-icons/fa6';
|
|
|
10
10
|
import { BiDownArrow, BiUpArrow } from 'react-icons/bi';
|
|
11
11
|
import { CgClose } from 'react-icons/cg';
|
|
12
12
|
import { IoMdEye, IoMdCheckbox } from 'react-icons/io';
|
|
13
|
+
import { monitorForElements, draggable, dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
14
|
+
import invariant from 'tiny-invariant';
|
|
13
15
|
import { HiMiniEllipsisHorizontal, HiChevronLeft, HiChevronRight } from 'react-icons/hi2';
|
|
14
16
|
import { flexRender, makeStateUpdater, functionalUpdate, useReactTable, getCoreRowModel, getFilteredRowModel, getSortedRowModel, getPaginationRowModel, createColumnHelper } from '@tanstack/react-table';
|
|
15
17
|
import { rankItem } from '@tanstack/match-sorter-utils';
|
|
16
18
|
import { BsExclamationCircleFill } from 'react-icons/bs';
|
|
17
19
|
import { GrAscend, GrDescend } from 'react-icons/gr';
|
|
20
|
+
import { HiColorSwatch, HiOutlineInformationCircle } from 'react-icons/hi';
|
|
18
21
|
import { useQueryClient, useQuery, QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
19
22
|
import { IoReload } from 'react-icons/io5';
|
|
20
|
-
import { HiColorSwatch, HiOutlineInformationCircle } from 'react-icons/hi';
|
|
21
|
-
import { monitorForElements, draggable, dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
22
|
-
import invariant from 'tiny-invariant';
|
|
23
23
|
import axios from 'axios';
|
|
24
24
|
import { useDebounce } from '@uidotdev/usehooks';
|
|
25
25
|
import { useFormContext, useForm, FormProvider } from 'react-hook-form';
|
|
@@ -438,6 +438,107 @@ const EditSortingButton = ({ text, icon = jsx(MdOutlineSort, {}), title = "Edit
|
|
|
438
438
|
return (jsx(Fragment, { children: jsxs(DialogRoot, { size: ["full", "full", "md", "md"], children: [jsx(DialogBackdrop, {}), jsx(DialogTrigger, { children: jsxs(Button$1, { as: "div", variant: "ghost", onClick: sortingModal.onOpen, children: [icon, " ", text] }) }), jsxs(DialogContent, { children: [jsx(DialogCloseTrigger, {}), jsxs(DialogHeader, { children: [jsx(DialogTitle, {}), title] }), jsx(DialogBody, { children: jsxs(Flex, { flexFlow: "column", gap: "0.25rem", children: [jsx(TableSorter, {}), jsx(ResetSortingButton, {})] }) }), jsx(DialogFooter, {})] })] }) }));
|
|
439
439
|
};
|
|
440
440
|
|
|
441
|
+
const CheckboxCard = React.forwardRef(function CheckboxCard(props, ref) {
|
|
442
|
+
const { inputProps, label, description, icon, addon, indicator = jsx(CheckboxCard$1.Indicator, {}), indicatorPlacement = "end", ...rest } = props;
|
|
443
|
+
const hasContent = label || description || icon;
|
|
444
|
+
const ContentWrapper = indicator ? CheckboxCard$1.Content : React.Fragment;
|
|
445
|
+
return (jsxs(CheckboxCard$1.Root, { ...rest, children: [jsx(CheckboxCard$1.HiddenInput, { ref: ref, ...inputProps }), jsxs(CheckboxCard$1.Control, { children: [indicatorPlacement === "start" && indicator, hasContent && (jsxs(ContentWrapper, { children: [icon, label && (jsx(CheckboxCard$1.Label, { children: label })), description && (jsx(CheckboxCard$1.Description, { children: description })), indicatorPlacement === "inside" && indicator] })), indicatorPlacement === "end" && indicator] }), addon && jsx(CheckboxCard$1.Addon, { children: addon })] }));
|
|
446
|
+
});
|
|
447
|
+
CheckboxCard$1.Indicator;
|
|
448
|
+
|
|
449
|
+
function ColumnCard({ columnId }) {
|
|
450
|
+
const ref = useRef(null);
|
|
451
|
+
const [dragging, setDragging] = useState(false); // NEW
|
|
452
|
+
const { table } = useDataTableContext();
|
|
453
|
+
const displayName = columnId;
|
|
454
|
+
const column = table.getColumn(columnId);
|
|
455
|
+
invariant(column);
|
|
456
|
+
useEffect(() => {
|
|
457
|
+
const el = ref.current;
|
|
458
|
+
invariant(el);
|
|
459
|
+
return draggable({
|
|
460
|
+
element: el,
|
|
461
|
+
getInitialData: () => {
|
|
462
|
+
return { column: table.getColumn(columnId) };
|
|
463
|
+
},
|
|
464
|
+
onDragStart: () => setDragging(true), // NEW
|
|
465
|
+
onDrop: () => setDragging(false), // NEW
|
|
466
|
+
});
|
|
467
|
+
}, [columnId, table]);
|
|
468
|
+
return (jsxs(Grid, { ref: ref, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", style: dragging ? { opacity: 0.4 } : {}, children: [jsx(Flex, { alignItems: "center", padding: "0", children: jsx(FaGripLinesVertical, { color: "gray.400" }) }), jsx(Flex, { justifyContent: "space-between", alignItems: "center", children: jsx(CheckboxCard, { variant: "surface", label: displayName, checked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() }) })] }));
|
|
469
|
+
}
|
|
470
|
+
function CardContainer({ location, children }) {
|
|
471
|
+
const ref = useRef(null);
|
|
472
|
+
const [isDraggedOver, setIsDraggedOver] = useState(false);
|
|
473
|
+
useEffect(() => {
|
|
474
|
+
const el = ref.current;
|
|
475
|
+
invariant(el);
|
|
476
|
+
return dropTargetForElements({
|
|
477
|
+
element: el,
|
|
478
|
+
getData: () => ({ location }),
|
|
479
|
+
onDragEnter: () => setIsDraggedOver(true),
|
|
480
|
+
onDragLeave: () => setIsDraggedOver(false),
|
|
481
|
+
onDrop: () => setIsDraggedOver(false),
|
|
482
|
+
});
|
|
483
|
+
}, [location]);
|
|
484
|
+
// const isDark = (location + location) % 2 === 1;
|
|
485
|
+
function getColor(isDraggedOver) {
|
|
486
|
+
if (isDraggedOver) {
|
|
487
|
+
return {
|
|
488
|
+
backgroundColor: "blue.400",
|
|
489
|
+
_dark: {
|
|
490
|
+
backgroundColor: "blue.400",
|
|
491
|
+
},
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
// return isDark ? "lightgrey" : "white";
|
|
495
|
+
return {
|
|
496
|
+
backgroundColor: undefined,
|
|
497
|
+
_dark: {
|
|
498
|
+
backgroundColor: undefined,
|
|
499
|
+
},
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
return (jsx(Box, { ...getColor(isDraggedOver), ref: ref, children: children }));
|
|
503
|
+
}
|
|
504
|
+
const TableViewer = () => {
|
|
505
|
+
const { table } = useDataTableContext();
|
|
506
|
+
const [order, setOrder] = useState(table.getAllLeafColumns().map((column) => {
|
|
507
|
+
return column.id;
|
|
508
|
+
}));
|
|
509
|
+
useEffect(() => {
|
|
510
|
+
return monitorForElements({
|
|
511
|
+
onDrop({ source, location }) {
|
|
512
|
+
const destination = location.current.dropTargets[0];
|
|
513
|
+
if (!destination) {
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
const destinationLocation = destination.data.location;
|
|
517
|
+
// const sourceLocation = source.data.location;
|
|
518
|
+
const sourceColumn = source.data.column;
|
|
519
|
+
const columnOrder = order.map((id) => {
|
|
520
|
+
if (id == sourceColumn.id) {
|
|
521
|
+
return "<marker>";
|
|
522
|
+
}
|
|
523
|
+
return id;
|
|
524
|
+
});
|
|
525
|
+
const columnBefore = columnOrder.slice(0, destinationLocation + 1);
|
|
526
|
+
const columnAfter = columnOrder.slice(destinationLocation + 1, columnOrder.length);
|
|
527
|
+
const newOrder = [
|
|
528
|
+
...columnBefore,
|
|
529
|
+
sourceColumn.id,
|
|
530
|
+
...columnAfter,
|
|
531
|
+
].filter((id) => id != "<marker>");
|
|
532
|
+
table.setColumnOrder(newOrder);
|
|
533
|
+
setOrder(newOrder);
|
|
534
|
+
},
|
|
535
|
+
});
|
|
536
|
+
}, [order, table]);
|
|
537
|
+
return (jsx(Flex, { flexFlow: "column", gap: "0.25rem", children: table.getState().columnOrder.map((columnId, index) => {
|
|
538
|
+
return (jsx(CardContainer, { location: index, children: jsx(ColumnCard, { columnId: columnId }) }));
|
|
539
|
+
}) }));
|
|
540
|
+
};
|
|
541
|
+
|
|
441
542
|
const EditViewButton = ({ text, icon = jsx(IoMdEye, {}), title = "Edit View", }) => {
|
|
442
543
|
const viewModel = useDisclosure();
|
|
443
544
|
return (jsx(Fragment, { children: jsxs(DialogRoot, { children: [jsx(DialogBackdrop, {}), jsx(DialogTrigger, { asChild: true, children: jsxs(Button$1, { as: Box, variant: "ghost", onClick: viewModel.onOpen, children: [icon, " ", text] }) }), jsxs(DialogContent, { children: [jsx(DialogCloseTrigger, {}), jsxs(DialogHeader, { children: [jsx(DialogTitle, {}), title] }), jsx(DialogBody, { children: jsx(TableViewer, {}) }), jsx(DialogFooter, {})] })] }) }));
|
|
@@ -813,7 +914,7 @@ function DataTable({ columns, data, enableRowSelection = true, enableMultiRowSel
|
|
|
813
914
|
onColumnVisibilityChange: setColumnVisibility,
|
|
814
915
|
});
|
|
815
916
|
return (jsx(DataTableContext.Provider, { value: {
|
|
816
|
-
table:
|
|
917
|
+
table: table,
|
|
817
918
|
globalFilter: globalFilter,
|
|
818
919
|
setGlobalFilter: setGlobalFilter,
|
|
819
920
|
type: "client",
|
|
@@ -1136,6 +1237,20 @@ const TableHeader = ({ canResize = true, pinnedBgColor = { light: "gray.50", dar
|
|
|
1136
1237
|
})] }, `chakra-table-headergroup-${headerGroup.id}`))) }));
|
|
1137
1238
|
};
|
|
1138
1239
|
|
|
1240
|
+
const EmptyState$1 = React.forwardRef(function EmptyState(props, ref) {
|
|
1241
|
+
const { title, description, icon, children, ...rest } = props;
|
|
1242
|
+
return (jsx(EmptyState$2.Root, { ref: ref, ...rest, children: jsxs(EmptyState$2.Content, { children: [icon && (jsx(EmptyState$2.Indicator, { children: icon })), description ? (jsxs(VStack, { textAlign: "center", children: [jsx(EmptyState$2.Title, { children: title }), jsx(EmptyState$2.Description, { children: description })] })) : (jsx(EmptyState$2.Title, { children: title })), children] }) }));
|
|
1243
|
+
});
|
|
1244
|
+
|
|
1245
|
+
const EmptyResult = (jsx(EmptyState$1, { icon: jsx(HiColorSwatch, {}), title: "No results found", description: "Try adjusting your search", children: jsxs(List.Root, { variant: "marker", children: [jsx(List.Item, { children: "Try removing filters" }), jsx(List.Item, { children: "Try different keywords" })] }) }));
|
|
1246
|
+
const Table = ({ children, emptyComponent = EmptyResult, canResize = true, ...props }) => {
|
|
1247
|
+
const { table } = useDataTableContext();
|
|
1248
|
+
if (table.getRowModel().rows.length <= 0) {
|
|
1249
|
+
return emptyComponent;
|
|
1250
|
+
}
|
|
1251
|
+
return (jsx(Table$1.Root, { stickyHeader: true, variant: "outline", width: canResize ? table.getCenterTotalSize() : undefined, ...props, children: children }));
|
|
1252
|
+
};
|
|
1253
|
+
|
|
1139
1254
|
const DefaultTable = ({ showFooter = false, tableProps = {}, tableHeaderProps = {}, tableBodyProps = {}, controlProps = {}, tableFooterProps = {}, variant = "", }) => {
|
|
1140
1255
|
if (variant === "greedy") {
|
|
1141
1256
|
return (jsx(TableControls, { ...controlProps, children: jsxs(Table, { canResize: false, ...tableProps, children: [jsx(TableHeader, { canResize: false, ...tableHeaderProps }), jsx(TableBody, { canResize: false, ...tableBodyProps }), showFooter && (jsx(TableFooter, { canResize: false, ...tableFooterProps }))] }) }));
|
|
@@ -1163,20 +1278,6 @@ const ReloadButton = ({ text = "Reload", variant = "icon", }) => {
|
|
|
1163
1278
|
}, children: [jsx(IoReload, {}), " ", text] }));
|
|
1164
1279
|
};
|
|
1165
1280
|
|
|
1166
|
-
const EmptyState$1 = React.forwardRef(function EmptyState(props, ref) {
|
|
1167
|
-
const { title, description, icon, children, ...rest } = props;
|
|
1168
|
-
return (jsx(EmptyState$2.Root, { ref: ref, ...rest, children: jsxs(EmptyState$2.Content, { children: [icon && (jsx(EmptyState$2.Indicator, { children: icon })), description ? (jsxs(VStack, { textAlign: "center", children: [jsx(EmptyState$2.Title, { children: title }), jsx(EmptyState$2.Description, { children: description })] })) : (jsx(EmptyState$2.Title, { children: title })), children] }) }));
|
|
1169
|
-
});
|
|
1170
|
-
|
|
1171
|
-
const EmptyResult = (jsx(EmptyState$1, { icon: jsx(HiColorSwatch, {}), title: "No results found", description: "Try adjusting your search", children: jsxs(List.Root, { variant: "marker", children: [jsx(List.Item, { children: "Try removing filters" }), jsx(List.Item, { children: "Try different keywords" })] }) }));
|
|
1172
|
-
const Table = ({ children, emptyComponent = EmptyResult, canResize = true, ...props }) => {
|
|
1173
|
-
const { table } = useDataTableContext();
|
|
1174
|
-
if (table.getRowModel().rows.length <= 0) {
|
|
1175
|
-
return emptyComponent;
|
|
1176
|
-
}
|
|
1177
|
-
return (jsx(Table$1.Root, { stickyHeader: true, variant: "outline", width: canResize ? table.getCenterTotalSize() : undefined, ...props, children: children }));
|
|
1178
|
-
};
|
|
1179
|
-
|
|
1180
1281
|
const TableCardContainer = ({ children, variant = "", ...props }) => {
|
|
1181
1282
|
if (variant === "carousel") {
|
|
1182
1283
|
return (jsx(Flex, { overflow: "scroll", gap: "1rem", children: children }));
|
|
@@ -1241,107 +1342,6 @@ const TableSelector = () => {
|
|
|
1241
1342
|
}, "aria-label": "reset selection", children: jsx(MdClear, {}) }))] }));
|
|
1242
1343
|
};
|
|
1243
1344
|
|
|
1244
|
-
const CheckboxCard = React.forwardRef(function CheckboxCard(props, ref) {
|
|
1245
|
-
const { inputProps, label, description, icon, addon, indicator = jsx(CheckboxCard$1.Indicator, {}), indicatorPlacement = "end", ...rest } = props;
|
|
1246
|
-
const hasContent = label || description || icon;
|
|
1247
|
-
const ContentWrapper = indicator ? CheckboxCard$1.Content : React.Fragment;
|
|
1248
|
-
return (jsxs(CheckboxCard$1.Root, { ...rest, children: [jsx(CheckboxCard$1.HiddenInput, { ref: ref, ...inputProps }), jsxs(CheckboxCard$1.Control, { children: [indicatorPlacement === "start" && indicator, hasContent && (jsxs(ContentWrapper, { children: [icon, label && (jsx(CheckboxCard$1.Label, { children: label })), description && (jsx(CheckboxCard$1.Description, { children: description })), indicatorPlacement === "inside" && indicator] })), indicatorPlacement === "end" && indicator] }), addon && jsx(CheckboxCard$1.Addon, { children: addon })] }));
|
|
1249
|
-
});
|
|
1250
|
-
CheckboxCard$1.Indicator;
|
|
1251
|
-
|
|
1252
|
-
function ColumnCard({ columnId }) {
|
|
1253
|
-
const ref = useRef(null);
|
|
1254
|
-
const [dragging, setDragging] = useState(false); // NEW
|
|
1255
|
-
const { table } = useDataTableContext();
|
|
1256
|
-
const displayName = columnId;
|
|
1257
|
-
const column = table.getColumn(columnId);
|
|
1258
|
-
invariant(column);
|
|
1259
|
-
useEffect(() => {
|
|
1260
|
-
const el = ref.current;
|
|
1261
|
-
invariant(el);
|
|
1262
|
-
return draggable({
|
|
1263
|
-
element: el,
|
|
1264
|
-
getInitialData: () => {
|
|
1265
|
-
return { column: table.getColumn(columnId) };
|
|
1266
|
-
},
|
|
1267
|
-
onDragStart: () => setDragging(true), // NEW
|
|
1268
|
-
onDrop: () => setDragging(false), // NEW
|
|
1269
|
-
});
|
|
1270
|
-
}, [columnId, table]);
|
|
1271
|
-
return (jsxs(Grid, { ref: ref, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", style: dragging ? { opacity: 0.4 } : {}, children: [jsx(Flex, { alignItems: "center", padding: "0", children: jsx(FaGripLinesVertical, { color: "gray.400" }) }), jsx(Flex, { justifyContent: "space-between", alignItems: "center", children: jsx(CheckboxCard, { variant: "surface", label: displayName, checked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() }) })] }));
|
|
1272
|
-
}
|
|
1273
|
-
function CardContainer({ location, children }) {
|
|
1274
|
-
const ref = useRef(null);
|
|
1275
|
-
const [isDraggedOver, setIsDraggedOver] = useState(false);
|
|
1276
|
-
useEffect(() => {
|
|
1277
|
-
const el = ref.current;
|
|
1278
|
-
invariant(el);
|
|
1279
|
-
return dropTargetForElements({
|
|
1280
|
-
element: el,
|
|
1281
|
-
getData: () => ({ location }),
|
|
1282
|
-
onDragEnter: () => setIsDraggedOver(true),
|
|
1283
|
-
onDragLeave: () => setIsDraggedOver(false),
|
|
1284
|
-
onDrop: () => setIsDraggedOver(false),
|
|
1285
|
-
});
|
|
1286
|
-
}, [location]);
|
|
1287
|
-
// const isDark = (location + location) % 2 === 1;
|
|
1288
|
-
function getColor(isDraggedOver) {
|
|
1289
|
-
if (isDraggedOver) {
|
|
1290
|
-
return {
|
|
1291
|
-
backgroundColor: "blue.400",
|
|
1292
|
-
_dark: {
|
|
1293
|
-
backgroundColor: "blue.400",
|
|
1294
|
-
},
|
|
1295
|
-
};
|
|
1296
|
-
}
|
|
1297
|
-
// return isDark ? "lightgrey" : "white";
|
|
1298
|
-
return {
|
|
1299
|
-
backgroundColor: undefined,
|
|
1300
|
-
_dark: {
|
|
1301
|
-
backgroundColor: undefined,
|
|
1302
|
-
},
|
|
1303
|
-
};
|
|
1304
|
-
}
|
|
1305
|
-
return (jsx(Box, { ...getColor(isDraggedOver), ref: ref, children: children }));
|
|
1306
|
-
}
|
|
1307
|
-
const TableViewer = () => {
|
|
1308
|
-
const { table } = useDataTableContext();
|
|
1309
|
-
const [order, setOrder] = useState(table.getAllLeafColumns().map((column) => {
|
|
1310
|
-
return column.id;
|
|
1311
|
-
}));
|
|
1312
|
-
useEffect(() => {
|
|
1313
|
-
return monitorForElements({
|
|
1314
|
-
onDrop({ source, location }) {
|
|
1315
|
-
const destination = location.current.dropTargets[0];
|
|
1316
|
-
if (!destination) {
|
|
1317
|
-
return;
|
|
1318
|
-
}
|
|
1319
|
-
const destinationLocation = destination.data.location;
|
|
1320
|
-
// const sourceLocation = source.data.location;
|
|
1321
|
-
const sourceColumn = source.data.column;
|
|
1322
|
-
const columnOrder = order.map((id) => {
|
|
1323
|
-
if (id == sourceColumn.id) {
|
|
1324
|
-
return "<marker>";
|
|
1325
|
-
}
|
|
1326
|
-
return id;
|
|
1327
|
-
});
|
|
1328
|
-
const columnBefore = columnOrder.slice(0, destinationLocation + 1);
|
|
1329
|
-
const columnAfter = columnOrder.slice(destinationLocation + 1, columnOrder.length);
|
|
1330
|
-
const newOrder = [
|
|
1331
|
-
...columnBefore,
|
|
1332
|
-
sourceColumn.id,
|
|
1333
|
-
...columnAfter,
|
|
1334
|
-
].filter((id) => id != "<marker>");
|
|
1335
|
-
table.setColumnOrder(newOrder);
|
|
1336
|
-
setOrder(newOrder);
|
|
1337
|
-
},
|
|
1338
|
-
});
|
|
1339
|
-
}, [order, table]);
|
|
1340
|
-
return (jsx(Flex, { flexFlow: "column", gap: "0.25rem", children: table.getState().columnOrder.map((columnId, index) => {
|
|
1341
|
-
return (jsx(CardContainer, { location: index, children: jsx(ColumnCard, { columnId: columnId }) }));
|
|
1342
|
-
}) }));
|
|
1343
|
-
};
|
|
1344
|
-
|
|
1345
1345
|
const TextCell = ({ label, containerProps = {}, textProps = {}, children, }) => {
|
|
1346
1346
|
if (label) {
|
|
1347
1347
|
return (jsx(Flex, { alignItems: "center", height: "100%", ...containerProps, children: jsx(Tooltip, { content: jsx(Text, { as: "span", overflow: "hidden", textOverflow: "ellipsis", children: label }), children: jsx(Text, { as: "span", overflow: "hidden", textOverflow: "ellipsis", wordBreak: "break-all", ...textProps, children: children }) }) }));
|
|
@@ -1686,7 +1686,7 @@ const IdPicker = ({ column, in_table, column_ref, display_column, isMultiple = f
|
|
|
1686
1686
|
const [searchText, setSearchText] = useState();
|
|
1687
1687
|
const [limit, setLimit] = useState(10);
|
|
1688
1688
|
const [openSearchResult, setOpenSearchResult] = useState();
|
|
1689
|
-
const [page, setPage] = useState(
|
|
1689
|
+
const [page, setPage] = useState(0);
|
|
1690
1690
|
const [idMap, setIdMap] = useState({});
|
|
1691
1691
|
const ref = useRef(null);
|
|
1692
1692
|
const selectedIds = watch(column) ?? [];
|
|
@@ -1747,7 +1747,7 @@ const IdPicker = ({ column, in_table, column_ref, display_column, isMultiple = f
|
|
|
1747
1747
|
const isDirty = (searchText?.length ?? 0) > 0;
|
|
1748
1748
|
const onSearchChange = async (event) => {
|
|
1749
1749
|
setSearchText(event.target.value);
|
|
1750
|
-
setPage(
|
|
1750
|
+
setPage(0);
|
|
1751
1751
|
setLimit(10);
|
|
1752
1752
|
};
|
|
1753
1753
|
const watchId = watch(column);
|
|
@@ -1800,7 +1800,7 @@ const IdPicker = ({ column, in_table, column_ref, display_column, isMultiple = f
|
|
|
1800
1800
|
}, opacity: 0.7, _hover: { opacity: 1 }, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
|
|
1801
1801
|
? renderDisplay(item)
|
|
1802
1802
|
: item[display_column] }, item[column_ref]));
|
|
1803
|
-
}) }), isDirty && (jsxs(Fragment, { children: [dataList.length <= 0 && jsx(Text, { children: "Empty Search Result" }), " "] }))] }), jsx(PaginationRoot, { justifySelf: "center", count: query?.data?.count ?? 0, pageSize: 10, defaultPage: 1, page: page, onPageChange: (e) => setPage(e.page), children: jsxs(HStack, { gap: "4", children: [jsx(PaginationPrevTrigger, {}), jsx(PaginationPageText, {}), jsx(PaginationNextTrigger, {})] }) })] }))] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: fieldRequired ?? "The field is requried" }))] }));
|
|
1803
|
+
}) }), isDirty && (jsxs(Fragment, { children: [dataList.length <= 0 && jsx(Text, { children: "Empty Search Result" }), " "] }))] }), jsx(PaginationRoot, { justifySelf: "center", count: query?.data?.count ?? 0, pageSize: 10, defaultPage: 1, page: page + 1, onPageChange: (e) => setPage(e.page - 1), children: jsxs(HStack, { gap: "4", children: [jsx(PaginationPrevTrigger, {}), jsx(PaginationPageText, {}), jsx(PaginationNextTrigger, {})] }) })] }))] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: fieldRequired ?? "The field is requried" }))] }));
|
|
1804
1804
|
};
|
|
1805
1805
|
|
|
1806
1806
|
const ToggleTip = React.forwardRef(function ToggleTip(props, ref) {
|
|
@@ -10,7 +10,7 @@ declare module "@tanstack/react-table" {
|
|
|
10
10
|
itemRank: RankingInfo;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
export interface DataTableProps<TData> {
|
|
13
|
+
export interface DataTableProps<TData = unknown> {
|
|
14
14
|
children?: ReactNode | ReactNode[];
|
|
15
15
|
data: TData[];
|
|
16
16
|
columns: ColumnDef<TData, unknown>[];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { TableHeaderProps as ChakraHeaderProps } from "@chakra-ui/react";
|
|
2
|
-
import { TableProps } from "../../index";
|
|
3
2
|
import { TableBodyProps } from "./TableBody";
|
|
4
3
|
import { TableControlsProps } from "./TableControls";
|
|
5
4
|
import { TableFooterProps } from "./TableFooter";
|
|
6
5
|
import { TableHeaderProps } from "./TableHeader";
|
|
6
|
+
import { TableProps } from "./Table";
|
|
7
7
|
export interface DefaultTableProps {
|
|
8
8
|
showFooter?: boolean;
|
|
9
9
|
showSelector?: boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { OnChangeFn, Table } from "@tanstack/react-table";
|
|
3
|
-
export interface DataTableContext<TData> {
|
|
3
|
+
export interface DataTableContext<TData = unknown> {
|
|
4
4
|
table: Table<TData>;
|
|
5
5
|
globalFilter: string;
|
|
6
6
|
setGlobalFilter: OnChangeFn<string>;
|