@mkt-loitd/react-table-grid-custom 1.0.1 → 1.0.3
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.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +118 -237
- package/dist/index.mjs +122 -231
- package/package.json +10 -9
package/dist/index.d.mts
CHANGED
|
@@ -38,8 +38,8 @@ interface IReactTableGridCustom<T = unknown, SR = unknown, K extends Key = Key>
|
|
|
38
38
|
TableLogo?: string;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
declare const ReactTableGridCustom:
|
|
41
|
+
type ReactTableGridCustomComponent = <T, SR = unknown, K extends Key = Key>(props: IReactTableGridCustom<T, SR, K>) => JSX.Element;
|
|
42
|
+
declare const ReactTableGridCustom: ReactTableGridCustomComponent;
|
|
43
43
|
|
|
44
44
|
interface IPaginationParams {
|
|
45
45
|
pageSize?: number;
|
|
@@ -51,13 +51,13 @@ interface ICalculatorTotalPage extends IPaginationParams {
|
|
|
51
51
|
}
|
|
52
52
|
interface ISTTParams extends IPaginationParams {
|
|
53
53
|
}
|
|
54
|
-
interface
|
|
54
|
+
interface UseShowHideColumnParameter<T, SR = unknown> {
|
|
55
55
|
nameLocal?: string;
|
|
56
56
|
/** nếu đầu vào là columns: Functions() thì nên dùng useMemo thì sẽ tối ưu hơn */
|
|
57
57
|
columns: TColumnsTable<T, SR>;
|
|
58
58
|
ignoreColumns?: string[];
|
|
59
59
|
}
|
|
60
|
-
interface
|
|
60
|
+
interface UseShowHideColumnReturn<T, SR> {
|
|
61
61
|
hiddenColumns: string[];
|
|
62
62
|
setHiddenColumns: Dispatch<SetStateAction<string[]>>;
|
|
63
63
|
columnsTable: TColumnsTable<T, SR>;
|
|
@@ -68,4 +68,4 @@ interface useShowHideColumnReturn<T, SR> {
|
|
|
68
68
|
handleChangeLocation?: (arr: string[]) => void;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
export { type ICalculatorTotalPage, type IPaginationParams, type IReactTableGridCustom, type ISTTParams, type Maybe, ReactTableGridCustom,
|
|
71
|
+
export { type ICalculatorTotalPage, type IPaginationParams, type IReactTableGridCustom, type ISTTParams, type Maybe, ReactTableGridCustom, type TColumnsTable, type UseShowHideColumnParameter, type UseShowHideColumnReturn };
|
package/dist/index.d.ts
CHANGED
|
@@ -38,8 +38,8 @@ interface IReactTableGridCustom<T = unknown, SR = unknown, K extends Key = Key>
|
|
|
38
38
|
TableLogo?: string;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
declare const ReactTableGridCustom:
|
|
41
|
+
type ReactTableGridCustomComponent = <T, SR = unknown, K extends Key = Key>(props: IReactTableGridCustom<T, SR, K>) => JSX.Element;
|
|
42
|
+
declare const ReactTableGridCustom: ReactTableGridCustomComponent;
|
|
43
43
|
|
|
44
44
|
interface IPaginationParams {
|
|
45
45
|
pageSize?: number;
|
|
@@ -51,13 +51,13 @@ interface ICalculatorTotalPage extends IPaginationParams {
|
|
|
51
51
|
}
|
|
52
52
|
interface ISTTParams extends IPaginationParams {
|
|
53
53
|
}
|
|
54
|
-
interface
|
|
54
|
+
interface UseShowHideColumnParameter<T, SR = unknown> {
|
|
55
55
|
nameLocal?: string;
|
|
56
56
|
/** nếu đầu vào là columns: Functions() thì nên dùng useMemo thì sẽ tối ưu hơn */
|
|
57
57
|
columns: TColumnsTable<T, SR>;
|
|
58
58
|
ignoreColumns?: string[];
|
|
59
59
|
}
|
|
60
|
-
interface
|
|
60
|
+
interface UseShowHideColumnReturn<T, SR> {
|
|
61
61
|
hiddenColumns: string[];
|
|
62
62
|
setHiddenColumns: Dispatch<SetStateAction<string[]>>;
|
|
63
63
|
columnsTable: TColumnsTable<T, SR>;
|
|
@@ -68,4 +68,4 @@ interface useShowHideColumnReturn<T, SR> {
|
|
|
68
68
|
handleChangeLocation?: (arr: string[]) => void;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
export { type ICalculatorTotalPage, type IPaginationParams, type IReactTableGridCustom, type ISTTParams, type Maybe, ReactTableGridCustom,
|
|
71
|
+
export { type ICalculatorTotalPage, type IPaginationParams, type IReactTableGridCustom, type ISTTParams, type Maybe, ReactTableGridCustom, type TColumnsTable, type UseShowHideColumnParameter, type UseShowHideColumnReturn };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
"use client";
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -21,13 +20,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
20
|
// src/index.ts
|
|
22
21
|
var index_exports = {};
|
|
23
22
|
__export(index_exports, {
|
|
24
|
-
ReactTableGridCustom: () => ReactTableGridCustom
|
|
25
|
-
ReactTableGridCustomDefault: () => ReactTableGridCustom_default
|
|
23
|
+
ReactTableGridCustom: () => ReactTableGridCustom
|
|
26
24
|
});
|
|
27
25
|
module.exports = __toCommonJS(index_exports);
|
|
28
26
|
|
|
29
27
|
// src/ReactTableGridCustom.tsx
|
|
30
|
-
var
|
|
28
|
+
var import_core = require("@mantine/core");
|
|
29
|
+
var import_lodash = require("lodash");
|
|
30
|
+
var import_react2 = require("react");
|
|
31
|
+
var import_react_data_grid = require("react-data-grid");
|
|
32
|
+
var import_styles = require("react-data-grid/lib/styles.css");
|
|
33
|
+
var import_react_i18next2 = require("react-i18next");
|
|
31
34
|
|
|
32
35
|
// src/helpers/table.ts
|
|
33
36
|
var calculatorTotalPage = ({ total = 0, pageSize = 0 }) => {
|
|
@@ -55,65 +58,20 @@ function cn(...inputs) {
|
|
|
55
58
|
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
|
56
59
|
}
|
|
57
60
|
|
|
58
|
-
// src/
|
|
59
|
-
var import_lodash = require("lodash");
|
|
60
|
-
var import_react3 = require("react");
|
|
61
|
-
var import_react_data_grid = require("react-data-grid");
|
|
62
|
-
var import_styles = require("react-data-grid/lib/styles.css");
|
|
63
|
-
var import_react_i18next2 = require("react-i18next");
|
|
64
|
-
|
|
65
|
-
// src/component/ComboboxCustom.tsx
|
|
66
|
-
var import_core = require("@mantine/core");
|
|
61
|
+
// src/hooks/useTranslationTable.ts
|
|
67
62
|
var import_react = require("react");
|
|
68
|
-
var
|
|
69
|
-
var
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
import_core.Combobox.Option,
|
|
76
|
-
{
|
|
77
|
-
className: "page_size-table",
|
|
78
|
-
value: item,
|
|
79
|
-
disabled: item === value,
|
|
80
|
-
children: item
|
|
81
|
-
},
|
|
82
|
-
item
|
|
83
|
-
));
|
|
84
|
-
}, [options, value]);
|
|
85
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
86
|
-
import_core.Combobox,
|
|
87
|
-
{
|
|
88
|
-
size: "sm",
|
|
89
|
-
store: combobox,
|
|
90
|
-
onOptionSubmit: (val) => {
|
|
91
|
-
onChange && onChange(val);
|
|
92
|
-
combobox.closeDropdown();
|
|
93
|
-
},
|
|
94
|
-
children: [
|
|
95
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Combobox.Target, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
96
|
-
import_core.InputBase,
|
|
97
|
-
{
|
|
98
|
-
component: "button",
|
|
99
|
-
type: "button",
|
|
100
|
-
pointer: true,
|
|
101
|
-
rightSectionPointerEvents: "none",
|
|
102
|
-
onClick: () => combobox.toggleDropdown(),
|
|
103
|
-
className: "w-[70px]",
|
|
104
|
-
classNames: { input: "custom_input_table" },
|
|
105
|
-
children: value || /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Input.Placeholder, { children: "Pick value" })
|
|
106
|
-
}
|
|
107
|
-
) }),
|
|
108
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Combobox.Dropdown, { className: "w-[70px]", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Combobox.Options, { children: newOptions }) })
|
|
109
|
-
]
|
|
110
|
-
}
|
|
111
|
-
);
|
|
63
|
+
var import_react_i18next = require("react-i18next");
|
|
64
|
+
var useTranslationTable = (column) => {
|
|
65
|
+
const { i18n, t } = (0, import_react_i18next.useTranslation)();
|
|
66
|
+
const columnTranslation = (0, import_react.useMemo)(() => {
|
|
67
|
+
return column.map((item) => ({ ...item, name: t(`${item == null ? void 0 : item.name}`) }));
|
|
68
|
+
}, [i18n == null ? void 0 : i18n.language, column]);
|
|
69
|
+
return columnTranslation;
|
|
112
70
|
};
|
|
113
|
-
var
|
|
71
|
+
var useTranslationTable_default = useTranslationTable;
|
|
114
72
|
|
|
115
73
|
// src/component/Icons.tsx
|
|
116
|
-
var
|
|
74
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
117
75
|
var LoadingIcon = ({
|
|
118
76
|
isSpin = false,
|
|
119
77
|
h = 30,
|
|
@@ -121,7 +79,7 @@ var LoadingIcon = ({
|
|
|
121
79
|
size = 30,
|
|
122
80
|
className
|
|
123
81
|
}) => {
|
|
124
|
-
return /* @__PURE__ */ (0,
|
|
82
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
125
83
|
"svg",
|
|
126
84
|
{
|
|
127
85
|
className: `${isSpin ? "animate-spin" : ""} ${className != null ? className : ""}`,
|
|
@@ -132,7 +90,7 @@ var LoadingIcon = ({
|
|
|
132
90
|
height: size || h,
|
|
133
91
|
fill: "currentColor",
|
|
134
92
|
"aria-hidden": "true",
|
|
135
|
-
children: /* @__PURE__ */ (0,
|
|
93
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M988 548c-19.9 0-36-16.1-36-36 0-59.4-11.6-117-34.6-171.3a440.45 440.45 0 00-94.3-139.9 437.71 437.71 0 00-139.9-94.3C629 83.6 571.4 72 512 72c-19.9 0-36-16.1-36-36s16.1-36 36-36c69.1 0 136.2 13.5 199.3 40.3C772.3 66 827 103 874 150c47 47 83.9 101.8 109.7 162.7 26.7 63.1 40.2 130.2 40.2 199.3.1 19.9-16 36-35.9 36z" })
|
|
136
94
|
}
|
|
137
95
|
);
|
|
138
96
|
};
|
|
@@ -142,7 +100,7 @@ var ArrowIcon = ({
|
|
|
142
100
|
size,
|
|
143
101
|
className
|
|
144
102
|
}) => {
|
|
145
|
-
return /* @__PURE__ */ (0,
|
|
103
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
146
104
|
"svg",
|
|
147
105
|
{
|
|
148
106
|
className,
|
|
@@ -153,7 +111,7 @@ var ArrowIcon = ({
|
|
|
153
111
|
height: size != null ? size : h,
|
|
154
112
|
width: size != null ? size : w,
|
|
155
113
|
xmlns: "http://www.w3.org/2000/svg",
|
|
156
|
-
children: /* @__PURE__ */ (0,
|
|
114
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
157
115
|
"path",
|
|
158
116
|
{
|
|
159
117
|
fillRule: "evenodd",
|
|
@@ -165,35 +123,23 @@ var ArrowIcon = ({
|
|
|
165
123
|
};
|
|
166
124
|
|
|
167
125
|
// src/component/RenderSortStatus.tsx
|
|
168
|
-
var
|
|
126
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
169
127
|
var RenderSortStatus = ({ sortDirection, priority }) => {
|
|
170
|
-
return /* @__PURE__ */ (0,
|
|
171
|
-
sortDirection !== void 0 && /* @__PURE__ */ (0,
|
|
128
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
129
|
+
sortDirection !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
172
130
|
ArrowIcon,
|
|
173
131
|
{
|
|
174
132
|
className: cn(sortDirection === "DESC" && "-rotate-180", "transition-transform"),
|
|
175
133
|
size: 20
|
|
176
134
|
}
|
|
177
135
|
),
|
|
178
|
-
/* @__PURE__ */ (0,
|
|
136
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: priority })
|
|
179
137
|
] });
|
|
180
138
|
};
|
|
181
139
|
var RenderSortStatus_default = RenderSortStatus;
|
|
182
140
|
|
|
183
|
-
// src/hooks/useTranslationTable.ts
|
|
184
|
-
var import_react2 = require("react");
|
|
185
|
-
var import_react_i18next = require("react-i18next");
|
|
186
|
-
var useTranslationTable = (column) => {
|
|
187
|
-
const { i18n, t } = (0, import_react_i18next.useTranslation)();
|
|
188
|
-
const columnTranslation = (0, import_react2.useMemo)(() => {
|
|
189
|
-
return column.map((item) => ({ ...item, name: t(`${item == null ? void 0 : item.name}`) }));
|
|
190
|
-
}, [i18n == null ? void 0 : i18n.language, column]);
|
|
191
|
-
return columnTranslation;
|
|
192
|
-
};
|
|
193
|
-
var useTranslationTable_default = useTranslationTable;
|
|
194
|
-
|
|
195
141
|
// src/ReactTableGridCustom.tsx
|
|
196
|
-
var
|
|
142
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
197
143
|
var ReactTableGridCustomInner = ({
|
|
198
144
|
classNamePaginationTable,
|
|
199
145
|
classNameWapperTable,
|
|
@@ -216,202 +162,137 @@ var ReactTableGridCustomInner = ({
|
|
|
216
162
|
...spread
|
|
217
163
|
}) => {
|
|
218
164
|
const { t } = (0, import_react_i18next2.useTranslation)();
|
|
219
|
-
const
|
|
220
|
-
const
|
|
221
|
-
const [containerWidth, setContainerWidth] = (0,
|
|
222
|
-
const [sortColumns, setSortColumns] = (0,
|
|
165
|
+
const tableRef = (0, import_react2.useRef)(null);
|
|
166
|
+
const [isLoading, setIsLoading] = (0, import_react2.useState)(true);
|
|
167
|
+
const [containerWidth, setContainerWidth] = (0, import_react2.useState)(0);
|
|
168
|
+
const [sortColumns, setSortColumns] = (0, import_react2.useState)([]);
|
|
223
169
|
const isSelectRow = selectedRows !== void 0;
|
|
224
|
-
const maxPage = (0,
|
|
225
|
-
() => !hiddenPagination ? calculatorTotalPage({
|
|
226
|
-
total,
|
|
227
|
-
pageSize
|
|
228
|
-
}) : 0,
|
|
170
|
+
const maxPage = (0, import_react2.useMemo)(
|
|
171
|
+
() => !hiddenPagination ? calculatorTotalPage({ total, pageSize }) : 0,
|
|
229
172
|
[pageSize, total, hiddenPagination]
|
|
230
173
|
);
|
|
231
|
-
const toInPagination = (0,
|
|
232
|
-
|
|
233
|
-
from
|
|
234
|
-
to: 0
|
|
235
|
-
};
|
|
236
|
-
if (!hiddenPaginationText && pageSize && page) {
|
|
237
|
-
const from = STT(
|
|
238
|
-
{
|
|
239
|
-
page,
|
|
240
|
-
pageSize
|
|
241
|
-
},
|
|
242
|
-
0
|
|
243
|
-
);
|
|
174
|
+
const toInPagination = (0, import_react2.useMemo)(() => {
|
|
175
|
+
if (!hiddenPaginationText && page && pageSize) {
|
|
176
|
+
const from = STT({ page, pageSize }, 0);
|
|
244
177
|
return {
|
|
245
178
|
from,
|
|
246
|
-
to: maxPage === page ? total : page * pageSize
|
|
179
|
+
to: maxPage === page ? total != null ? total : 0 : page * pageSize
|
|
247
180
|
};
|
|
248
181
|
}
|
|
249
|
-
return
|
|
250
|
-
}, [
|
|
251
|
-
const columnTranslation = useTranslationTable_default(
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
newCol.width = 200;
|
|
267
|
-
return newCol;
|
|
268
|
-
});
|
|
269
|
-
const totalMaxWidth = columnsCustom.reduce((sum, col) => {
|
|
270
|
-
var _a;
|
|
271
|
-
return sum + ("width" in col ? Number((_a = col == null ? void 0 : col.width) != null ? _a : 200) : 0);
|
|
272
|
-
}, 0);
|
|
273
|
-
if (totalMaxWidth < adjustedContainerWidth && columnsCustom.length > 0) {
|
|
274
|
-
const evenWidth = Math.floor(adjustedContainerWidth / columnsCustom.length);
|
|
275
|
-
columnsCustom = columnsCustom.map((col) => {
|
|
276
|
-
const newCol = { ...col };
|
|
277
|
-
delete newCol.maxWidth;
|
|
278
|
-
newCol.width = evenWidth;
|
|
279
|
-
return newCol;
|
|
280
|
-
});
|
|
281
|
-
}
|
|
182
|
+
return { from: 0, to: 0 };
|
|
183
|
+
}, [page, pageSize, hiddenPaginationText, maxPage, total]);
|
|
184
|
+
const columnTranslation = useTranslationTable_default(
|
|
185
|
+
columns
|
|
186
|
+
);
|
|
187
|
+
const newColumns = (0, import_react2.useMemo)(() => {
|
|
188
|
+
let cols = [
|
|
189
|
+
...columnTranslation
|
|
190
|
+
];
|
|
191
|
+
const adjustedWidth = containerWidth - 45;
|
|
192
|
+
cols = cols.map(
|
|
193
|
+
(col) => "key" in col ? {
|
|
194
|
+
...col,
|
|
195
|
+
width: 200,
|
|
196
|
+
maxWidth: void 0
|
|
197
|
+
} : col
|
|
198
|
+
);
|
|
282
199
|
if (isSelectRow) {
|
|
283
|
-
|
|
200
|
+
cols.unshift(import_react_data_grid.SelectColumn);
|
|
284
201
|
}
|
|
285
|
-
if (!hiddenSTT
|
|
286
|
-
|
|
202
|
+
if (!hiddenSTT) {
|
|
203
|
+
const sttColumn = {
|
|
287
204
|
key: "index",
|
|
288
205
|
name: "STT",
|
|
289
206
|
width: 80,
|
|
290
207
|
renderCell: ({ rowIdx }) => STT({ page, pageSize }, rowIdx)
|
|
291
|
-
}
|
|
208
|
+
};
|
|
209
|
+
cols.unshift(sttColumn);
|
|
292
210
|
}
|
|
293
|
-
return
|
|
294
|
-
}, [
|
|
295
|
-
|
|
296
|
-
|
|
211
|
+
return cols;
|
|
212
|
+
}, [
|
|
213
|
+
columnTranslation,
|
|
214
|
+
containerWidth,
|
|
215
|
+
hiddenSTT,
|
|
216
|
+
isSelectRow,
|
|
217
|
+
page,
|
|
218
|
+
pageSize
|
|
219
|
+
]);
|
|
220
|
+
const customRowKeyGetter = (0, import_react2.useCallback)(
|
|
221
|
+
(row) => {
|
|
297
222
|
if (typeof rowKeyGetter === "function") {
|
|
298
223
|
return rowKeyGetter(row);
|
|
299
224
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}, [rowKeyGetter]);
|
|
303
|
-
const handlePageChange = (0, import_react3.useCallback)(
|
|
304
|
-
(page2) => {
|
|
305
|
-
if (onChange) {
|
|
306
|
-
onChange(page2);
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
if (setConfigPagination) {
|
|
310
|
-
setConfigPagination((prev) => ({ ...prev, page: page2 }));
|
|
225
|
+
if (typeof rowKeyGetter === "string") {
|
|
226
|
+
return (0, import_lodash.get)(row, rowKeyGetter);
|
|
311
227
|
}
|
|
228
|
+
throw new Error(
|
|
229
|
+
"rowKeyGetter must be a string or a function"
|
|
230
|
+
);
|
|
312
231
|
},
|
|
313
|
-
[
|
|
232
|
+
[rowKeyGetter]
|
|
314
233
|
);
|
|
315
|
-
const sortedRows = (0,
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
const
|
|
320
|
-
|
|
234
|
+
const sortedRows = (0, import_react2.useMemo)(() => {
|
|
235
|
+
if (!sortColumns.length) return data;
|
|
236
|
+
const { columnKey, direction } = sortColumns[0];
|
|
237
|
+
if (!direction) return data;
|
|
238
|
+
const order = direction === "ASC" ? "asc" : "desc";
|
|
239
|
+
const iteratee = typeof columnKey === "string" ? columnKey : String(columnKey);
|
|
240
|
+
return (0, import_lodash.orderBy)(data, [iteratee], [order]);
|
|
321
241
|
}, [data, sortColumns]);
|
|
322
|
-
(0,
|
|
323
|
-
|
|
324
|
-
|
|
242
|
+
(0, import_react2.useEffect)(() => {
|
|
243
|
+
var _a;
|
|
244
|
+
setIsLoading(false);
|
|
245
|
+
if ((_a = tableRef.current) == null ? void 0 : _a.element) {
|
|
246
|
+
setContainerWidth(tableRef.current.element.offsetWidth);
|
|
325
247
|
}
|
|
326
|
-
}, [
|
|
327
|
-
return /* @__PURE__ */ (0,
|
|
248
|
+
}, []);
|
|
249
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
328
250
|
"div",
|
|
329
251
|
{
|
|
330
252
|
className: cn(
|
|
331
|
-
"wapper_table flex
|
|
253
|
+
"wapper_table flex flex-col h-full min-h-0",
|
|
332
254
|
classNameWapperTable
|
|
333
255
|
),
|
|
334
256
|
children: [
|
|
335
|
-
/* @__PURE__ */ (0,
|
|
336
|
-
|
|
337
|
-
import_react_data_grid.DataGrid,
|
|
338
|
-
{
|
|
339
|
-
ref: tableRef,
|
|
340
|
-
"aria-rowcount": sortedRows == null ? void 0 : sortedRows.length,
|
|
341
|
-
selectedRows,
|
|
342
|
-
rows: sortedRows,
|
|
343
|
-
rowKeyGetter: rowKeyGetter && isSelectRow ? customRowKeyGetter : void 0,
|
|
344
|
-
columns: newColumns,
|
|
345
|
-
renderers: {
|
|
346
|
-
renderSortStatus: RenderSortStatus_default,
|
|
347
|
-
renderCheckbox({ onChange: onChange2, checked, ...spread2 }) {
|
|
348
|
-
const handleChange = (e) => {
|
|
349
|
-
onChange2(e.target.checked, e.nativeEvent.shiftKey);
|
|
350
|
-
};
|
|
351
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_core2.Checkbox, { color: "indigo", checked: !!checked, onChange: handleChange, ...spread2 });
|
|
352
|
-
}
|
|
353
|
-
},
|
|
354
|
-
className: "fill-grid flex-1 h-full min-h-0",
|
|
355
|
-
defaultColumnOptions: {
|
|
356
|
-
// minWidth: 200,
|
|
357
|
-
// maxWidth: 200,
|
|
358
|
-
renderCell: ({ column, row }) => {
|
|
359
|
-
const value = (0, import_lodash.get)(row, column.key);
|
|
360
|
-
return [null, void 0, ""].includes(value) ? "-" : value;
|
|
361
|
-
}
|
|
362
|
-
},
|
|
363
|
-
sortColumns,
|
|
364
|
-
onSortColumnsChange: setSortColumns,
|
|
365
|
-
...spread
|
|
366
|
-
}
|
|
367
|
-
),
|
|
368
|
-
total === 0 && TableLogo && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "no_result absolute left-1/2 top-1/2 -translate-y-1/2 -translate-x-1/2 select-none", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "flex flex-col justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("img", { src: TableLogo, alt: "", className: "size-32" }) }) })
|
|
369
|
-
] }),
|
|
370
|
-
!hiddenPagination && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
371
|
-
"div",
|
|
257
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
258
|
+
import_react_data_grid.DataGrid,
|
|
372
259
|
{
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
260
|
+
ref: tableRef,
|
|
261
|
+
rows: sortedRows,
|
|
262
|
+
columns: newColumns,
|
|
263
|
+
selectedRows,
|
|
264
|
+
rowKeyGetter: isSelectRow ? customRowKeyGetter : void 0,
|
|
265
|
+
sortColumns,
|
|
266
|
+
onSortColumnsChange: setSortColumns,
|
|
267
|
+
renderers: {
|
|
268
|
+
renderSortStatus: RenderSortStatus_default,
|
|
269
|
+
renderCheckbox({ onChange: onChange2, checked, ...props }) {
|
|
270
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
271
|
+
import_core.Checkbox,
|
|
272
|
+
{
|
|
273
|
+
...props,
|
|
274
|
+
checked: !!checked,
|
|
275
|
+
onChange: (e) => {
|
|
276
|
+
const nativeEvent = e.nativeEvent;
|
|
277
|
+
const shiftKey = nativeEvent instanceof MouseEvent ? nativeEvent.shiftKey : false;
|
|
278
|
+
onChange2(e.target.checked, shiftKey);
|
|
387
279
|
}
|
|
388
280
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
{
|
|
394
|
-
color: "indigo",
|
|
395
|
-
total: maxPage,
|
|
396
|
-
size: "sm",
|
|
397
|
-
value: page,
|
|
398
|
-
onChange: handlePageChange
|
|
399
|
-
}
|
|
400
|
-
)
|
|
401
|
-
]
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
...spread
|
|
402
285
|
}
|
|
403
286
|
),
|
|
404
|
-
(fetching || isLoading) && /* @__PURE__ */ (0,
|
|
287
|
+
(fetching || isLoading) && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "absolute inset-0 flex items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(LoadingIcon, { isSpin: true }) })
|
|
405
288
|
]
|
|
406
289
|
}
|
|
407
290
|
);
|
|
408
291
|
};
|
|
409
|
-
var ReactTableGridCustom = (0,
|
|
292
|
+
var ReactTableGridCustom = (0, import_react2.memo)(
|
|
410
293
|
ReactTableGridCustomInner
|
|
411
294
|
);
|
|
412
|
-
var ReactTableGridCustom_default = ReactTableGridCustom;
|
|
413
295
|
// Annotate the CommonJS export names for ESM import in node:
|
|
414
296
|
0 && (module.exports = {
|
|
415
|
-
ReactTableGridCustom
|
|
416
|
-
ReactTableGridCustomDefault
|
|
297
|
+
ReactTableGridCustom
|
|
417
298
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
1
|
// src/ReactTableGridCustom.tsx
|
|
4
|
-
import { Checkbox
|
|
2
|
+
import { Checkbox } from "@mantine/core";
|
|
3
|
+
import { get, orderBy } from "lodash";
|
|
4
|
+
import {
|
|
5
|
+
memo,
|
|
6
|
+
useCallback,
|
|
7
|
+
useEffect,
|
|
8
|
+
useMemo as useMemo2,
|
|
9
|
+
useRef,
|
|
10
|
+
useState
|
|
11
|
+
} from "react";
|
|
12
|
+
import {
|
|
13
|
+
DataGrid,
|
|
14
|
+
SelectColumn
|
|
15
|
+
} from "react-data-grid";
|
|
16
|
+
import "react-data-grid/lib/styles.css";
|
|
17
|
+
import { useTranslation as useTranslation2 } from "react-i18next";
|
|
5
18
|
|
|
6
19
|
// src/helpers/table.ts
|
|
7
20
|
var calculatorTotalPage = ({ total = 0, pageSize = 0 }) => {
|
|
@@ -29,65 +42,20 @@ function cn(...inputs) {
|
|
|
29
42
|
return twMerge(clsx(inputs));
|
|
30
43
|
}
|
|
31
44
|
|
|
32
|
-
// src/
|
|
33
|
-
import { get, orderBy } from "lodash";
|
|
34
|
-
import { memo, useCallback, useEffect, useMemo as useMemo3, useRef, useState } from "react";
|
|
35
|
-
import { DataGrid, SelectColumn } from "react-data-grid";
|
|
36
|
-
import "react-data-grid/lib/styles.css";
|
|
37
|
-
import { useTranslation as useTranslation2 } from "react-i18next";
|
|
38
|
-
|
|
39
|
-
// src/component/ComboboxCustom.tsx
|
|
40
|
-
import { Combobox, Input, InputBase, useCombobox } from "@mantine/core";
|
|
45
|
+
// src/hooks/useTranslationTable.ts
|
|
41
46
|
import { useMemo } from "react";
|
|
42
|
-
import {
|
|
43
|
-
var
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
Combobox.Option,
|
|
50
|
-
{
|
|
51
|
-
className: "page_size-table",
|
|
52
|
-
value: item,
|
|
53
|
-
disabled: item === value,
|
|
54
|
-
children: item
|
|
55
|
-
},
|
|
56
|
-
item
|
|
57
|
-
));
|
|
58
|
-
}, [options, value]);
|
|
59
|
-
return /* @__PURE__ */ jsxs(
|
|
60
|
-
Combobox,
|
|
61
|
-
{
|
|
62
|
-
size: "sm",
|
|
63
|
-
store: combobox,
|
|
64
|
-
onOptionSubmit: (val) => {
|
|
65
|
-
onChange && onChange(val);
|
|
66
|
-
combobox.closeDropdown();
|
|
67
|
-
},
|
|
68
|
-
children: [
|
|
69
|
-
/* @__PURE__ */ jsx(Combobox.Target, { children: /* @__PURE__ */ jsx(
|
|
70
|
-
InputBase,
|
|
71
|
-
{
|
|
72
|
-
component: "button",
|
|
73
|
-
type: "button",
|
|
74
|
-
pointer: true,
|
|
75
|
-
rightSectionPointerEvents: "none",
|
|
76
|
-
onClick: () => combobox.toggleDropdown(),
|
|
77
|
-
className: "w-[70px]",
|
|
78
|
-
classNames: { input: "custom_input_table" },
|
|
79
|
-
children: value || /* @__PURE__ */ jsx(Input.Placeholder, { children: "Pick value" })
|
|
80
|
-
}
|
|
81
|
-
) }),
|
|
82
|
-
/* @__PURE__ */ jsx(Combobox.Dropdown, { className: "w-[70px]", children: /* @__PURE__ */ jsx(Combobox.Options, { children: newOptions }) })
|
|
83
|
-
]
|
|
84
|
-
}
|
|
85
|
-
);
|
|
47
|
+
import { useTranslation } from "react-i18next";
|
|
48
|
+
var useTranslationTable = (column) => {
|
|
49
|
+
const { i18n, t } = useTranslation();
|
|
50
|
+
const columnTranslation = useMemo(() => {
|
|
51
|
+
return column.map((item) => ({ ...item, name: t(`${item == null ? void 0 : item.name}`) }));
|
|
52
|
+
}, [i18n == null ? void 0 : i18n.language, column]);
|
|
53
|
+
return columnTranslation;
|
|
86
54
|
};
|
|
87
|
-
var
|
|
55
|
+
var useTranslationTable_default = useTranslationTable;
|
|
88
56
|
|
|
89
57
|
// src/component/Icons.tsx
|
|
90
|
-
import { jsx
|
|
58
|
+
import { jsx } from "react/jsx-runtime";
|
|
91
59
|
var LoadingIcon = ({
|
|
92
60
|
isSpin = false,
|
|
93
61
|
h = 30,
|
|
@@ -95,7 +63,7 @@ var LoadingIcon = ({
|
|
|
95
63
|
size = 30,
|
|
96
64
|
className
|
|
97
65
|
}) => {
|
|
98
|
-
return /* @__PURE__ */
|
|
66
|
+
return /* @__PURE__ */ jsx(
|
|
99
67
|
"svg",
|
|
100
68
|
{
|
|
101
69
|
className: `${isSpin ? "animate-spin" : ""} ${className != null ? className : ""}`,
|
|
@@ -106,7 +74,7 @@ var LoadingIcon = ({
|
|
|
106
74
|
height: size || h,
|
|
107
75
|
fill: "currentColor",
|
|
108
76
|
"aria-hidden": "true",
|
|
109
|
-
children: /* @__PURE__ */
|
|
77
|
+
children: /* @__PURE__ */ jsx("path", { d: "M988 548c-19.9 0-36-16.1-36-36 0-59.4-11.6-117-34.6-171.3a440.45 440.45 0 00-94.3-139.9 437.71 437.71 0 00-139.9-94.3C629 83.6 571.4 72 512 72c-19.9 0-36-16.1-36-36s16.1-36 36-36c69.1 0 136.2 13.5 199.3 40.3C772.3 66 827 103 874 150c47 47 83.9 101.8 109.7 162.7 26.7 63.1 40.2 130.2 40.2 199.3.1 19.9-16 36-35.9 36z" })
|
|
110
78
|
}
|
|
111
79
|
);
|
|
112
80
|
};
|
|
@@ -116,7 +84,7 @@ var ArrowIcon = ({
|
|
|
116
84
|
size,
|
|
117
85
|
className
|
|
118
86
|
}) => {
|
|
119
|
-
return /* @__PURE__ */
|
|
87
|
+
return /* @__PURE__ */ jsx(
|
|
120
88
|
"svg",
|
|
121
89
|
{
|
|
122
90
|
className,
|
|
@@ -127,7 +95,7 @@ var ArrowIcon = ({
|
|
|
127
95
|
height: size != null ? size : h,
|
|
128
96
|
width: size != null ? size : w,
|
|
129
97
|
xmlns: "http://www.w3.org/2000/svg",
|
|
130
|
-
children: /* @__PURE__ */
|
|
98
|
+
children: /* @__PURE__ */ jsx(
|
|
131
99
|
"path",
|
|
132
100
|
{
|
|
133
101
|
fillRule: "evenodd",
|
|
@@ -139,35 +107,23 @@ var ArrowIcon = ({
|
|
|
139
107
|
};
|
|
140
108
|
|
|
141
109
|
// src/component/RenderSortStatus.tsx
|
|
142
|
-
import { Fragment, jsx as
|
|
110
|
+
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
143
111
|
var RenderSortStatus = ({ sortDirection, priority }) => {
|
|
144
|
-
return /* @__PURE__ */
|
|
145
|
-
sortDirection !== void 0 && /* @__PURE__ */
|
|
112
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
113
|
+
sortDirection !== void 0 && /* @__PURE__ */ jsx2(
|
|
146
114
|
ArrowIcon,
|
|
147
115
|
{
|
|
148
116
|
className: cn(sortDirection === "DESC" && "-rotate-180", "transition-transform"),
|
|
149
117
|
size: 20
|
|
150
118
|
}
|
|
151
119
|
),
|
|
152
|
-
/* @__PURE__ */
|
|
120
|
+
/* @__PURE__ */ jsx2("span", { children: priority })
|
|
153
121
|
] });
|
|
154
122
|
};
|
|
155
123
|
var RenderSortStatus_default = RenderSortStatus;
|
|
156
124
|
|
|
157
|
-
// src/hooks/useTranslationTable.ts
|
|
158
|
-
import { useMemo as useMemo2 } from "react";
|
|
159
|
-
import { useTranslation } from "react-i18next";
|
|
160
|
-
var useTranslationTable = (column) => {
|
|
161
|
-
const { i18n, t } = useTranslation();
|
|
162
|
-
const columnTranslation = useMemo2(() => {
|
|
163
|
-
return column.map((item) => ({ ...item, name: t(`${item == null ? void 0 : item.name}`) }));
|
|
164
|
-
}, [i18n == null ? void 0 : i18n.language, column]);
|
|
165
|
-
return columnTranslation;
|
|
166
|
-
};
|
|
167
|
-
var useTranslationTable_default = useTranslationTable;
|
|
168
|
-
|
|
169
125
|
// src/ReactTableGridCustom.tsx
|
|
170
|
-
import { jsx as
|
|
126
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
171
127
|
var ReactTableGridCustomInner = ({
|
|
172
128
|
classNamePaginationTable,
|
|
173
129
|
classNameWapperTable,
|
|
@@ -190,192 +146,129 @@ var ReactTableGridCustomInner = ({
|
|
|
190
146
|
...spread
|
|
191
147
|
}) => {
|
|
192
148
|
const { t } = useTranslation2();
|
|
193
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
194
149
|
const tableRef = useRef(null);
|
|
150
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
195
151
|
const [containerWidth, setContainerWidth] = useState(0);
|
|
196
152
|
const [sortColumns, setSortColumns] = useState([]);
|
|
197
153
|
const isSelectRow = selectedRows !== void 0;
|
|
198
|
-
const maxPage =
|
|
199
|
-
() => !hiddenPagination ? calculatorTotalPage({
|
|
200
|
-
total,
|
|
201
|
-
pageSize
|
|
202
|
-
}) : 0,
|
|
154
|
+
const maxPage = useMemo2(
|
|
155
|
+
() => !hiddenPagination ? calculatorTotalPage({ total, pageSize }) : 0,
|
|
203
156
|
[pageSize, total, hiddenPagination]
|
|
204
157
|
);
|
|
205
|
-
const toInPagination =
|
|
206
|
-
|
|
207
|
-
from
|
|
208
|
-
to: 0
|
|
209
|
-
};
|
|
210
|
-
if (!hiddenPaginationText && pageSize && page) {
|
|
211
|
-
const from = STT(
|
|
212
|
-
{
|
|
213
|
-
page,
|
|
214
|
-
pageSize
|
|
215
|
-
},
|
|
216
|
-
0
|
|
217
|
-
);
|
|
158
|
+
const toInPagination = useMemo2(() => {
|
|
159
|
+
if (!hiddenPaginationText && page && pageSize) {
|
|
160
|
+
const from = STT({ page, pageSize }, 0);
|
|
218
161
|
return {
|
|
219
162
|
from,
|
|
220
|
-
to: maxPage === page ? total : page * pageSize
|
|
163
|
+
to: maxPage === page ? total != null ? total : 0 : page * pageSize
|
|
221
164
|
};
|
|
222
165
|
}
|
|
223
|
-
return
|
|
224
|
-
}, [
|
|
225
|
-
const columnTranslation = useTranslationTable_default(
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
newCol.width = 200;
|
|
241
|
-
return newCol;
|
|
242
|
-
});
|
|
243
|
-
const totalMaxWidth = columnsCustom.reduce((sum, col) => {
|
|
244
|
-
var _a;
|
|
245
|
-
return sum + ("width" in col ? Number((_a = col == null ? void 0 : col.width) != null ? _a : 200) : 0);
|
|
246
|
-
}, 0);
|
|
247
|
-
if (totalMaxWidth < adjustedContainerWidth && columnsCustom.length > 0) {
|
|
248
|
-
const evenWidth = Math.floor(adjustedContainerWidth / columnsCustom.length);
|
|
249
|
-
columnsCustom = columnsCustom.map((col) => {
|
|
250
|
-
const newCol = { ...col };
|
|
251
|
-
delete newCol.maxWidth;
|
|
252
|
-
newCol.width = evenWidth;
|
|
253
|
-
return newCol;
|
|
254
|
-
});
|
|
255
|
-
}
|
|
166
|
+
return { from: 0, to: 0 };
|
|
167
|
+
}, [page, pageSize, hiddenPaginationText, maxPage, total]);
|
|
168
|
+
const columnTranslation = useTranslationTable_default(
|
|
169
|
+
columns
|
|
170
|
+
);
|
|
171
|
+
const newColumns = useMemo2(() => {
|
|
172
|
+
let cols = [
|
|
173
|
+
...columnTranslation
|
|
174
|
+
];
|
|
175
|
+
const adjustedWidth = containerWidth - 45;
|
|
176
|
+
cols = cols.map(
|
|
177
|
+
(col) => "key" in col ? {
|
|
178
|
+
...col,
|
|
179
|
+
width: 200,
|
|
180
|
+
maxWidth: void 0
|
|
181
|
+
} : col
|
|
182
|
+
);
|
|
256
183
|
if (isSelectRow) {
|
|
257
|
-
|
|
184
|
+
cols.unshift(SelectColumn);
|
|
258
185
|
}
|
|
259
|
-
if (!hiddenSTT
|
|
260
|
-
|
|
186
|
+
if (!hiddenSTT) {
|
|
187
|
+
const sttColumn = {
|
|
261
188
|
key: "index",
|
|
262
189
|
name: "STT",
|
|
263
190
|
width: 80,
|
|
264
191
|
renderCell: ({ rowIdx }) => STT({ page, pageSize }, rowIdx)
|
|
265
|
-
}
|
|
192
|
+
};
|
|
193
|
+
cols.unshift(sttColumn);
|
|
266
194
|
}
|
|
267
|
-
return
|
|
268
|
-
}, [
|
|
269
|
-
|
|
270
|
-
|
|
195
|
+
return cols;
|
|
196
|
+
}, [
|
|
197
|
+
columnTranslation,
|
|
198
|
+
containerWidth,
|
|
199
|
+
hiddenSTT,
|
|
200
|
+
isSelectRow,
|
|
201
|
+
page,
|
|
202
|
+
pageSize
|
|
203
|
+
]);
|
|
204
|
+
const customRowKeyGetter = useCallback(
|
|
205
|
+
(row) => {
|
|
271
206
|
if (typeof rowKeyGetter === "function") {
|
|
272
207
|
return rowKeyGetter(row);
|
|
273
208
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}, [rowKeyGetter]);
|
|
277
|
-
const handlePageChange = useCallback(
|
|
278
|
-
(page2) => {
|
|
279
|
-
if (onChange) {
|
|
280
|
-
onChange(page2);
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
if (setConfigPagination) {
|
|
284
|
-
setConfigPagination((prev) => ({ ...prev, page: page2 }));
|
|
209
|
+
if (typeof rowKeyGetter === "string") {
|
|
210
|
+
return get(row, rowKeyGetter);
|
|
285
211
|
}
|
|
212
|
+
throw new Error(
|
|
213
|
+
"rowKeyGetter must be a string or a function"
|
|
214
|
+
);
|
|
286
215
|
},
|
|
287
|
-
[
|
|
216
|
+
[rowKeyGetter]
|
|
288
217
|
);
|
|
289
|
-
const sortedRows =
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
const
|
|
294
|
-
|
|
218
|
+
const sortedRows = useMemo2(() => {
|
|
219
|
+
if (!sortColumns.length) return data;
|
|
220
|
+
const { columnKey, direction } = sortColumns[0];
|
|
221
|
+
if (!direction) return data;
|
|
222
|
+
const order = direction === "ASC" ? "asc" : "desc";
|
|
223
|
+
const iteratee = typeof columnKey === "string" ? columnKey : String(columnKey);
|
|
224
|
+
return orderBy(data, [iteratee], [order]);
|
|
295
225
|
}, [data, sortColumns]);
|
|
296
226
|
useEffect(() => {
|
|
297
|
-
|
|
298
|
-
|
|
227
|
+
var _a;
|
|
228
|
+
setIsLoading(false);
|
|
229
|
+
if ((_a = tableRef.current) == null ? void 0 : _a.element) {
|
|
230
|
+
setContainerWidth(tableRef.current.element.offsetWidth);
|
|
299
231
|
}
|
|
300
|
-
}, [
|
|
301
|
-
return /* @__PURE__ */
|
|
232
|
+
}, []);
|
|
233
|
+
return /* @__PURE__ */ jsxs2(
|
|
302
234
|
"div",
|
|
303
235
|
{
|
|
304
236
|
className: cn(
|
|
305
|
-
"wapper_table flex
|
|
237
|
+
"wapper_table flex flex-col h-full min-h-0",
|
|
306
238
|
classNameWapperTable
|
|
307
239
|
),
|
|
308
240
|
children: [
|
|
309
|
-
/* @__PURE__ */
|
|
310
|
-
|
|
311
|
-
DataGrid,
|
|
312
|
-
{
|
|
313
|
-
ref: tableRef,
|
|
314
|
-
"aria-rowcount": sortedRows == null ? void 0 : sortedRows.length,
|
|
315
|
-
selectedRows,
|
|
316
|
-
rows: sortedRows,
|
|
317
|
-
rowKeyGetter: rowKeyGetter && isSelectRow ? customRowKeyGetter : void 0,
|
|
318
|
-
columns: newColumns,
|
|
319
|
-
renderers: {
|
|
320
|
-
renderSortStatus: RenderSortStatus_default,
|
|
321
|
-
renderCheckbox({ onChange: onChange2, checked, ...spread2 }) {
|
|
322
|
-
const handleChange = (e) => {
|
|
323
|
-
onChange2(e.target.checked, e.nativeEvent.shiftKey);
|
|
324
|
-
};
|
|
325
|
-
return /* @__PURE__ */ jsx4(Checkbox, { color: "indigo", checked: !!checked, onChange: handleChange, ...spread2 });
|
|
326
|
-
}
|
|
327
|
-
},
|
|
328
|
-
className: "fill-grid flex-1 h-full min-h-0",
|
|
329
|
-
defaultColumnOptions: {
|
|
330
|
-
// minWidth: 200,
|
|
331
|
-
// maxWidth: 200,
|
|
332
|
-
renderCell: ({ column, row }) => {
|
|
333
|
-
const value = get(row, column.key);
|
|
334
|
-
return [null, void 0, ""].includes(value) ? "-" : value;
|
|
335
|
-
}
|
|
336
|
-
},
|
|
337
|
-
sortColumns,
|
|
338
|
-
onSortColumnsChange: setSortColumns,
|
|
339
|
-
...spread
|
|
340
|
-
}
|
|
341
|
-
),
|
|
342
|
-
total === 0 && TableLogo && /* @__PURE__ */ jsx4("div", { className: "no_result absolute left-1/2 top-1/2 -translate-y-1/2 -translate-x-1/2 select-none", children: /* @__PURE__ */ jsx4("div", { className: "flex flex-col justify-center", children: /* @__PURE__ */ jsx4("img", { src: TableLogo, alt: "", className: "size-32" }) }) })
|
|
343
|
-
] }),
|
|
344
|
-
!hiddenPagination && /* @__PURE__ */ jsxs3(
|
|
345
|
-
"div",
|
|
241
|
+
/* @__PURE__ */ jsx3(
|
|
242
|
+
DataGrid,
|
|
346
243
|
{
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
244
|
+
ref: tableRef,
|
|
245
|
+
rows: sortedRows,
|
|
246
|
+
columns: newColumns,
|
|
247
|
+
selectedRows,
|
|
248
|
+
rowKeyGetter: isSelectRow ? customRowKeyGetter : void 0,
|
|
249
|
+
sortColumns,
|
|
250
|
+
onSortColumnsChange: setSortColumns,
|
|
251
|
+
renderers: {
|
|
252
|
+
renderSortStatus: RenderSortStatus_default,
|
|
253
|
+
renderCheckbox({ onChange: onChange2, checked, ...props }) {
|
|
254
|
+
return /* @__PURE__ */ jsx3(
|
|
255
|
+
Checkbox,
|
|
256
|
+
{
|
|
257
|
+
...props,
|
|
258
|
+
checked: !!checked,
|
|
259
|
+
onChange: (e) => {
|
|
260
|
+
const nativeEvent = e.nativeEvent;
|
|
261
|
+
const shiftKey = nativeEvent instanceof MouseEvent ? nativeEvent.shiftKey : false;
|
|
262
|
+
onChange2(e.target.checked, shiftKey);
|
|
361
263
|
}
|
|
362
264
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
{
|
|
368
|
-
color: "indigo",
|
|
369
|
-
total: maxPage,
|
|
370
|
-
size: "sm",
|
|
371
|
-
value: page,
|
|
372
|
-
onChange: handlePageChange
|
|
373
|
-
}
|
|
374
|
-
)
|
|
375
|
-
]
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
...spread
|
|
376
269
|
}
|
|
377
270
|
),
|
|
378
|
-
(fetching || isLoading) && /* @__PURE__ */
|
|
271
|
+
(fetching || isLoading) && /* @__PURE__ */ jsx3("div", { className: "absolute inset-0 flex items-center justify-center", children: /* @__PURE__ */ jsx3(LoadingIcon, { isSpin: true }) })
|
|
379
272
|
]
|
|
380
273
|
}
|
|
381
274
|
);
|
|
@@ -383,8 +276,6 @@ var ReactTableGridCustomInner = ({
|
|
|
383
276
|
var ReactTableGridCustom = memo(
|
|
384
277
|
ReactTableGridCustomInner
|
|
385
278
|
);
|
|
386
|
-
var ReactTableGridCustom_default = ReactTableGridCustom;
|
|
387
279
|
export {
|
|
388
|
-
ReactTableGridCustom
|
|
389
|
-
ReactTableGridCustom_default as ReactTableGridCustomDefault
|
|
280
|
+
ReactTableGridCustom
|
|
390
281
|
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mkt-loitd/react-table-grid-custom",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "React Table Grid Custom component",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"private": false,
|
|
4
7
|
"publishConfig": {
|
|
5
8
|
"access": "public"
|
|
6
9
|
},
|
|
7
|
-
"private": false,
|
|
8
|
-
"description": "React Table Grid Custom component",
|
|
9
10
|
"main": "dist/index.cjs",
|
|
10
11
|
"module": "dist/index.js",
|
|
11
12
|
"types": "dist/index.d.ts",
|
|
@@ -28,9 +29,9 @@
|
|
|
28
29
|
"release:patch": "npm version patch --no-git-tag-version"
|
|
29
30
|
},
|
|
30
31
|
"peerDependencies": {
|
|
32
|
+
"next": ">=13",
|
|
31
33
|
"react": ">=18",
|
|
32
|
-
"react-dom": ">=18"
|
|
33
|
-
"next": ">=13"
|
|
34
|
+
"react-dom": ">=18"
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
37
|
"@mantine/core": "^8.3.10",
|
|
@@ -49,19 +50,19 @@
|
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
52
|
"@types/lodash": "^4.17.21",
|
|
52
|
-
"@types/react": "
|
|
53
|
+
"@types/react": ">=18",
|
|
54
|
+
"@types/react-dom": ">=18",
|
|
53
55
|
"tslib": "^2.8.1",
|
|
54
56
|
"tsup": "^8.5.1",
|
|
55
57
|
"typescript": "^5.9.3"
|
|
56
58
|
},
|
|
57
|
-
"license": "ISC",
|
|
58
59
|
"repository": {
|
|
59
60
|
"type": "git",
|
|
60
61
|
"url": "git+ssh://git@github.com/loitd140201/react-table.git"
|
|
61
62
|
},
|
|
62
|
-
"author": "",
|
|
63
63
|
"bugs": {
|
|
64
64
|
"url": "https://github.com/loitd140201/react-table/issues"
|
|
65
65
|
},
|
|
66
|
-
"homepage": "https://github.com/loitd140201/react-table#readme"
|
|
66
|
+
"homepage": "https://github.com/loitd140201/react-table#readme",
|
|
67
|
+
"author": ""
|
|
67
68
|
}
|