rez-table-listing-mui 0.0.9 → 0.0.11
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 +17 -21
- package/dist/index.d.ts +27 -5
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/App.tsx +49 -9
- package/src/components/column-visibility-modal/column-list-item.tsx +0 -2
- package/src/components/index-table.tsx +54 -16
- package/src/components/index.scss +1 -5
- package/src/components/table-body.tsx +3 -6
- package/src/components/viewmore/index.tsx +0 -18
- package/src/libs/hooks/useCraftTable.tsx +2 -2
- package/src/libs/hooks/useDefaultColumns.tsx +20 -10
- package/src/types/table.ts +28 -2
|
@@ -28,27 +28,60 @@ function TableWrapper<T>({
|
|
|
28
28
|
featureOptions,
|
|
29
29
|
topbarOptions,
|
|
30
30
|
nestedComponent,
|
|
31
|
-
loadingOptions = {
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
loadingOptions = { isLoading: false },
|
|
32
|
+
customRenderFn = {},
|
|
33
|
+
shouldHideColumn,
|
|
34
|
+
styleOptions,
|
|
34
35
|
}: CraftTableProps<T>) {
|
|
35
|
-
// Throw an error if data is not an array
|
|
36
36
|
if (!Array.isArray(data)) {
|
|
37
37
|
throw new Error("data must be an array of objects.");
|
|
38
38
|
}
|
|
39
|
+
const [metaColumns, setMetaColumns] = useState<ColumnDef<T>[]>([]);
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
const updatedColumns = columns
|
|
43
|
+
.filter((col) => {
|
|
44
|
+
const accessorKey =
|
|
45
|
+
"accessorKey" in col
|
|
46
|
+
? (col as { accessorKey: string }).accessorKey
|
|
47
|
+
: undefined;
|
|
48
|
+
return typeof shouldHideColumn === "function"
|
|
49
|
+
? !shouldHideColumn(accessorKey)
|
|
50
|
+
: true;
|
|
51
|
+
})
|
|
52
|
+
.map((col, index) => {
|
|
53
|
+
const id =
|
|
54
|
+
"accessorKey" in col
|
|
55
|
+
? (col as { accessorKey: string }).accessorKey
|
|
56
|
+
: `col_${index}`;
|
|
57
|
+
|
|
58
|
+
const cell = (ctx: any) => {
|
|
59
|
+
if (col.meta?.type === "custom" && col?.meta?.propName) {
|
|
60
|
+
const customFn = customRenderFn?.[col.meta.propName];
|
|
61
|
+
return typeof customFn === "function"
|
|
62
|
+
? customFn({
|
|
63
|
+
value: ctx.getValue(),
|
|
64
|
+
row: ctx.row,
|
|
65
|
+
table: ctx.table.getRowModel().rows,
|
|
66
|
+
})
|
|
67
|
+
: ctx.getValue();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (typeof col.cell === "function") {
|
|
71
|
+
return col.cell(ctx);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return ctx.getValue();
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return { ...col, id, cell };
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
setMetaColumns(updatedColumns);
|
|
81
|
+
}, [columns, tableStates]);
|
|
49
82
|
|
|
50
83
|
const [columnOrder, setColumnOrder] = useState<string[]>(() =>
|
|
51
|
-
|
|
84
|
+
metaColumns.map((c) => c.id!)
|
|
52
85
|
);
|
|
53
86
|
|
|
54
87
|
const [isCompactTable, setIsCompactTable] = useState<boolean>(
|
|
@@ -132,7 +165,7 @@ function TableWrapper<T>({
|
|
|
132
165
|
|
|
133
166
|
const table = useReactTable({
|
|
134
167
|
data,
|
|
135
|
-
columns,
|
|
168
|
+
columns: metaColumns,
|
|
136
169
|
state: {
|
|
137
170
|
sorting,
|
|
138
171
|
pagination,
|
|
@@ -196,6 +229,11 @@ function TableWrapper<T>({
|
|
|
196
229
|
}
|
|
197
230
|
};
|
|
198
231
|
|
|
232
|
+
const tableWrapperProps = {
|
|
233
|
+
...(styleOptions?.wrapperStyle && { style: styleOptions.wrapperStyle }),
|
|
234
|
+
className: "ts__table__wrapper",
|
|
235
|
+
};
|
|
236
|
+
|
|
199
237
|
return (
|
|
200
238
|
<div className="ts__table__container" ref={tableRef}>
|
|
201
239
|
{isLoading ? (
|
|
@@ -227,7 +265,7 @@ function TableWrapper<T>({
|
|
|
227
265
|
/>
|
|
228
266
|
)}
|
|
229
267
|
|
|
230
|
-
<div
|
|
268
|
+
<div {...tableWrapperProps}>
|
|
231
269
|
{enableColumnReordering ? (
|
|
232
270
|
<TableDND
|
|
233
271
|
table={table}
|
|
@@ -29,11 +29,7 @@
|
|
|
29
29
|
|
|
30
30
|
.ts__table__wrapper {
|
|
31
31
|
overflow-x: auto;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
&.is-fullscreen {
|
|
35
|
-
max-height: calc(100vh - 10px); // override in fullscreen
|
|
36
|
-
}
|
|
32
|
+
max-height: calc(100vh - 110px);
|
|
37
33
|
|
|
38
34
|
.ts__table.ts--striped > .ts__body > .ts__body__tr:nth-of-type(odd) {
|
|
39
35
|
background-color: var(--grey-200);
|
|
@@ -98,12 +98,9 @@ function TableBody<T>({
|
|
|
98
98
|
<React.Fragment key={row.id}>
|
|
99
99
|
{renderedRow}
|
|
100
100
|
<tr>
|
|
101
|
-
{
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
{/* <td colSpan={table.getAllLeafColumns().length}> */}
|
|
105
|
-
{NestedComponent && <NestedComponent {...{ row }} />}
|
|
106
|
-
{/* </td> */}
|
|
101
|
+
<td colSpan={table.getAllLeafColumns().length}>
|
|
102
|
+
{NestedComponent && <NestedComponent {...{ row }} />}
|
|
103
|
+
</td>
|
|
107
104
|
</tr>
|
|
108
105
|
</React.Fragment>
|
|
109
106
|
);
|
|
@@ -135,15 +135,6 @@ const ViewMore = ({
|
|
|
135
135
|
color: "#000",
|
|
136
136
|
fontSize: "13px",
|
|
137
137
|
}}
|
|
138
|
-
MenuProps={{
|
|
139
|
-
container: fullscreenContainer,
|
|
140
|
-
disablePortal: false,
|
|
141
|
-
PaperProps: {
|
|
142
|
-
style: {
|
|
143
|
-
zIndex: 1500,
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
}}
|
|
147
138
|
>
|
|
148
139
|
<MenuItem value="Comfy">Comfy</MenuItem>
|
|
149
140
|
<MenuItem value="Compact">Compact</MenuItem>
|
|
@@ -170,15 +161,6 @@ const ViewMore = ({
|
|
|
170
161
|
color: "#000",
|
|
171
162
|
fontSize: "13px",
|
|
172
163
|
}}
|
|
173
|
-
MenuProps={{
|
|
174
|
-
container: fullscreenContainer,
|
|
175
|
-
disablePortal: false,
|
|
176
|
-
PaperProps: {
|
|
177
|
-
style: {
|
|
178
|
-
zIndex: 1500,
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
}}
|
|
182
164
|
>
|
|
183
165
|
<MenuItem value="None">None</MenuItem>
|
|
184
166
|
<MenuItem value="Status">Status</MenuItem>
|
|
@@ -7,10 +7,10 @@ import {
|
|
|
7
7
|
import { useState } from "react";
|
|
8
8
|
import { CraftTableOptionsProps } from "../../types/table-options";
|
|
9
9
|
|
|
10
|
-
export function useCraftTable() {
|
|
10
|
+
export function useCraftTable(paginationPageSize: number = 25) {
|
|
11
11
|
const [pagination, setPagination] = useState<PaginationState>({
|
|
12
12
|
pageIndex: 0,
|
|
13
|
-
pageSize:
|
|
13
|
+
pageSize: paginationPageSize,
|
|
14
14
|
});
|
|
15
15
|
const [sorting, setSorting] = useState<SortingState>([]);
|
|
16
16
|
const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
|
|
@@ -26,9 +26,7 @@ export const useDefaultColumns = () => {
|
|
|
26
26
|
// ),
|
|
27
27
|
cell: ({ row, getValue }) => {
|
|
28
28
|
return (
|
|
29
|
-
<div
|
|
30
|
-
style={{ paddingLeft: `${row.depth * 2}rem`, display: "flex" }}
|
|
31
|
-
>
|
|
29
|
+
<div style={{ paddingLeft: `${row.depth * 2}rem` }}>
|
|
32
30
|
{row.getCanExpand() ? (
|
|
33
31
|
<button
|
|
34
32
|
style={{
|
|
@@ -50,8 +48,7 @@ export const useDefaultColumns = () => {
|
|
|
50
48
|
) : (
|
|
51
49
|
<span style={{ marginRight: "0.8rem" }}></span>
|
|
52
50
|
)}
|
|
53
|
-
{
|
|
54
|
-
<p style={{ marginTop: "0.5rem" }}>{getValue<boolean>()}</p>
|
|
51
|
+
{getValue<boolean>()}
|
|
55
52
|
</div>
|
|
56
53
|
);
|
|
57
54
|
},
|
|
@@ -86,17 +83,30 @@ export const useDefaultColumns = () => {
|
|
|
86
83
|
size: 150,
|
|
87
84
|
meta: { label: "Progress" },
|
|
88
85
|
},
|
|
89
|
-
{
|
|
90
|
-
header: "Status",
|
|
91
|
-
accessorKey: "status",
|
|
92
|
-
meta: { label: "Status" },
|
|
93
|
-
},
|
|
94
86
|
{
|
|
95
87
|
header: "Department",
|
|
96
88
|
accessorKey: "department",
|
|
97
89
|
size: 150,
|
|
98
90
|
meta: { label: "Department" },
|
|
99
91
|
},
|
|
92
|
+
{
|
|
93
|
+
header: "Status",
|
|
94
|
+
accessorKey: "status",
|
|
95
|
+
meta: {
|
|
96
|
+
label: "Status",
|
|
97
|
+
type: "custom",
|
|
98
|
+
propName: "renderStatus",
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
header: "Action",
|
|
103
|
+
accessorKey: "action",
|
|
104
|
+
meta: {
|
|
105
|
+
label: "Action",
|
|
106
|
+
type: "custom",
|
|
107
|
+
propName: "renderAction",
|
|
108
|
+
},
|
|
109
|
+
},
|
|
100
110
|
],
|
|
101
111
|
[]
|
|
102
112
|
);
|
package/src/types/table.ts
CHANGED
|
@@ -39,17 +39,43 @@ export interface TopbarOptionsProps {
|
|
|
39
39
|
showCustomizationToggle?: boolean;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
export interface CustomRenderContext<T> {
|
|
43
|
+
value: unknown;
|
|
44
|
+
row: Row<T>;
|
|
45
|
+
table: Row<T>[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type CustomRenderFnMap<T> = {
|
|
49
|
+
[key: string]: (ctx: CustomRenderContext<T>) => React.ReactNode;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
type CustomColumnMeta = {
|
|
53
|
+
type?: "custom";
|
|
54
|
+
propName?: string;
|
|
55
|
+
[key: string]: any;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
type CustomColumnDef<T> = ColumnDef<T> & {
|
|
59
|
+
meta?: CustomColumnMeta;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
interface CraftTableStyleProps {
|
|
63
|
+
wrapperStyle?: React.CSSProperties;
|
|
64
|
+
}
|
|
65
|
+
|
|
42
66
|
export interface CraftTableProps<T> {
|
|
43
67
|
data: T[];
|
|
44
|
-
columns:
|
|
68
|
+
columns: CustomColumnDef<T>[];
|
|
45
69
|
tableStates: CraftTableOptionsProps;
|
|
46
70
|
paginationOptions?: CraftTablePaginationProps;
|
|
47
71
|
featureOptions?: CraftTableFeatureProps;
|
|
48
72
|
nestedComponent?: React.ComponentType<{ row: Row<T> }>;
|
|
49
73
|
loadingOptions?: LoadingOptionsProps;
|
|
50
74
|
topbarOptions?: TopbarOptionsProps;
|
|
75
|
+
customRenderFn?: CustomRenderFnMap<T>;
|
|
76
|
+
shouldHideColumn?: (accessorKey?: string) => boolean;
|
|
77
|
+
styleOptions?: CraftTableStyleProps;
|
|
51
78
|
}
|
|
52
|
-
|
|
53
79
|
export interface CraftTableComponentProps<T> {
|
|
54
80
|
table: Table<T>;
|
|
55
81
|
featureOptions: CraftTableFeatureProps;
|