@pnkx-lib/ui 1.9.536 → 1.9.539
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/es/constants/index.js +51 -1
- package/es/index.js +2 -8
- package/es/ui/Tabs.js +2 -2
- package/es/ui/index.js +6983 -145
- package/package.json +1 -1
- package/types/components/ui/GenericUploadModal.d.ts +2 -0
- package/es/chunks/RefuseApprovalDropListIcon-DkyYANWt.js +0 -192
- package/es/chunks/table-Btvh90Co.js +0 -50
- package/es/ui/BulkActions/index.js +0 -314
- package/es/ui/Clock/index.js +0 -67
- package/es/ui/CustomeBulkActions/index.js +0 -928
- package/es/ui/Table/index.js +0 -404
- package/es/ui/TableCategory/index.js +0 -4784
- package/es/ui/TableForm/index.js +0 -213
- package/types/ui/BulkActions/index.d.ts +0 -2
- package/types/ui/Clock/index.d.ts +0 -2
- package/types/ui/CustomeBulkActions/index.d.ts +0 -6
- package/types/ui/Table/index.d.ts +0 -2
- package/types/ui/TableCategory/index.d.ts +0 -2
- package/types/ui/TableForm/index.d.ts +0 -2
package/es/ui/Table/index.js
DELETED
|
@@ -1,404 +0,0 @@
|
|
|
1
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { useState, useCallback, useEffect, useRef } from 'react';
|
|
3
|
-
import { Select, Input, Pagination, Table as Table$1 } from 'antd';
|
|
4
|
-
import { Typography } from '../Typography.js';
|
|
5
|
-
import { I as ID_TABLE_WRAPPER } from '../../chunks/common-BcURBmQ-.js';
|
|
6
|
-
import { f as TypeStatusTable } from '../../chunks/table-Btvh90Co.js';
|
|
7
|
-
|
|
8
|
-
const iconTableNoData = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAB4CAYAAAA5ZDbSAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAA7dSURBVHgB7Z1bbFTXFYb/PTO+gDFMApgQkngIvRAgwZFKlbR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0d+wxl91yHsu1t09OlEXMmjWx4SdeDk/Y0EZ5o5qStNlQqbKZ7grcZkm2n2t4tg0zSHpvq+Hh6R0WzO6Xfxs6/Pqbxx54aH3dzj07sHxFzu3yopzr5htzV9VtrbNMcUxKq2vouSP1GTZ6VRK5ZH1UyaqWny05lOUQgz5Oi8qM0kxx14YtbTUralrZkusfD096z/5OBcpzH6sVOYOkiftyU/jVcvH077urD8ps35bgWOSS79GRdNkW3fx2m4SEdY3y5e65JOxE7IAoYXYsX7E8zCKHH6/Hspqa/Vwbz9WZau+iLyyeOm1mq60ImG3pahUJzJutZ6sDOBJ5zm/CMluwvwlG8KSKaEymZILX/56iqT4jfQzNCPHXEtRSaNtEGUachaUa876pZciqg3K3L/d3UhUssha4CLDYwuev462YyU3fXswiRJ/Fgo/5o5fP5U5/Fh2QbcKXc/VkQSJrgWcxXoisBZ7luBVZCzwHcCOyFniOoCqyFngOoSKyFniO4VRkLfAcxInIWuA5SkEil+NhLfAcJq/IAi3ztmXnywB/vxR/LUK29/0ScS3wHCeHyHFYiGmB5wEssgXsmfBlKAZ/TZEXX3aimWXwt9FBo9FoNBqNRqPRaDQajUaj0Wg0Go1Go9FoNBqNRqPRaDQajXP+D0/tlZm0R8ESAAAAAElFTkSuQmCC";
|
|
9
|
-
|
|
10
|
-
const { Option } = Select;
|
|
11
|
-
const CustomPagination = ({
|
|
12
|
-
current = 1,
|
|
13
|
-
pageSize = 10,
|
|
14
|
-
total = 0,
|
|
15
|
-
pageSizeOptions = ["10", "50", "100", "150", "200"],
|
|
16
|
-
onChange,
|
|
17
|
-
onShowSizeChange,
|
|
18
|
-
size,
|
|
19
|
-
...rest
|
|
20
|
-
}) => {
|
|
21
|
-
const [jumpValue, setJumpValue] = useState("");
|
|
22
|
-
const showTotal = (total2, range) => `${range[0]}-${range[1]} trên tổng ${total2}`;
|
|
23
|
-
const totalPages = Math.ceil(total / pageSize);
|
|
24
|
-
const handleJump = () => {
|
|
25
|
-
const pageNumber = parseInt(jumpValue);
|
|
26
|
-
if (pageNumber && pageNumber >= 1 && pageNumber <= totalPages && pageNumber !== current) {
|
|
27
|
-
onChange?.(pageNumber, pageSize);
|
|
28
|
-
}
|
|
29
|
-
setJumpValue("");
|
|
30
|
-
};
|
|
31
|
-
const handleJumpKeyPress = (e) => {
|
|
32
|
-
if (e.key === "Enter") {
|
|
33
|
-
handleJump();
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
const handleJumpInputChange = (e) => {
|
|
37
|
-
const value = e.target.value;
|
|
38
|
-
if (value === "" || /^\d+$/.test(value) && parseInt(value) <= totalPages) {
|
|
39
|
-
setJumpValue(value);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
const handleKeyDown = (e) => {
|
|
43
|
-
const allowedKeys = [
|
|
44
|
-
"Backspace",
|
|
45
|
-
"Delete",
|
|
46
|
-
"Tab",
|
|
47
|
-
"Escape",
|
|
48
|
-
"Enter",
|
|
49
|
-
"ArrowLeft",
|
|
50
|
-
"ArrowRight",
|
|
51
|
-
"ArrowUp",
|
|
52
|
-
"ArrowDown"
|
|
53
|
-
];
|
|
54
|
-
if (!allowedKeys.includes(e.key) && !/^[0-9]$/.test(e.key)) {
|
|
55
|
-
e.preventDefault();
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between py-2", children: [
|
|
59
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4", children: [
|
|
60
|
-
/* @__PURE__ */ jsx("div", { className: "flex items-center gap-2 pnkx-default-select-container !w-fit !h-fit", children: /* @__PURE__ */ jsx(
|
|
61
|
-
Select,
|
|
62
|
-
{
|
|
63
|
-
value: pageSize.toString(),
|
|
64
|
-
onChange: (value) => {
|
|
65
|
-
const newSize = parseInt(value);
|
|
66
|
-
onShowSizeChange?.(current, newSize);
|
|
67
|
-
},
|
|
68
|
-
size: "small",
|
|
69
|
-
className: "min-w-16",
|
|
70
|
-
popupMatchSelectWidth: true,
|
|
71
|
-
getPopupContainer: (trigger) => trigger.parentElement,
|
|
72
|
-
children: pageSizeOptions.map((option) => /* @__PURE__ */ jsx(Option, { value: option, children: option }, option))
|
|
73
|
-
}
|
|
74
|
-
) }),
|
|
75
|
-
showTotal && /* @__PURE__ */ jsx("div", { className: "text-sm text-gray-600", children: showTotal(total, [
|
|
76
|
-
total ? (current - 1) * pageSize + 1 : 0,
|
|
77
|
-
Math.min(current * pageSize, total)
|
|
78
|
-
]) })
|
|
79
|
-
] }),
|
|
80
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
81
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
82
|
-
/* @__PURE__ */ jsx(Typography.Text, { className: "text-sm text-gray-600 whitespace-nowrap", children: "Xem trang" }),
|
|
83
|
-
/* @__PURE__ */ jsx(
|
|
84
|
-
Input,
|
|
85
|
-
{
|
|
86
|
-
value: jumpValue,
|
|
87
|
-
onChange: handleJumpInputChange,
|
|
88
|
-
onKeyUp: handleJumpKeyPress,
|
|
89
|
-
onKeyDown: handleKeyDown,
|
|
90
|
-
onBlur: handleJump,
|
|
91
|
-
placeholder: current.toString(),
|
|
92
|
-
size: "small",
|
|
93
|
-
className: "text-center w-10! !border-[#bde3ff]",
|
|
94
|
-
type: "text",
|
|
95
|
-
min: 1,
|
|
96
|
-
max: totalPages
|
|
97
|
-
}
|
|
98
|
-
)
|
|
99
|
-
] }),
|
|
100
|
-
/* @__PURE__ */ jsx(
|
|
101
|
-
Pagination,
|
|
102
|
-
{
|
|
103
|
-
current,
|
|
104
|
-
pageSize,
|
|
105
|
-
total,
|
|
106
|
-
onChange,
|
|
107
|
-
size,
|
|
108
|
-
showQuickJumper: false,
|
|
109
|
-
showSizeChanger: false,
|
|
110
|
-
...rest
|
|
111
|
-
}
|
|
112
|
-
)
|
|
113
|
-
] })
|
|
114
|
-
] });
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
const useTableHeightWrapper = (options = {}) => {
|
|
118
|
-
const {
|
|
119
|
-
tableContainerId = "table_content",
|
|
120
|
-
extraOffset = 24,
|
|
121
|
-
// Layout padding bottom mặc định
|
|
122
|
-
minHeight = 200
|
|
123
|
-
} = options;
|
|
124
|
-
const [tableHeight, setTableHeight] = useState(minHeight);
|
|
125
|
-
const calculateTableHeight = useCallback(() => {
|
|
126
|
-
try {
|
|
127
|
-
const viewportHeight = window.innerHeight;
|
|
128
|
-
const layoutWrapper = document.getElementById(ID_TABLE_WRAPPER);
|
|
129
|
-
if (!layoutWrapper) {
|
|
130
|
-
console.error("Layout wrapper table container not found");
|
|
131
|
-
setTableHeight(minHeight);
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
const wrapperRect = layoutWrapper.getBoundingClientRect();
|
|
135
|
-
const availableHeight = viewportHeight - wrapperRect.top;
|
|
136
|
-
const tableContainer = document.getElementById(tableContainerId);
|
|
137
|
-
if (!tableContainer) {
|
|
138
|
-
console.error(`Table container "${tableContainerId}" not found`);
|
|
139
|
-
setTableHeight(minHeight);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
const directChildren = Array.from(layoutWrapper.children);
|
|
143
|
-
let otherElementsHeight = 0;
|
|
144
|
-
directChildren.forEach((child) => {
|
|
145
|
-
const rect = child.getBoundingClientRect();
|
|
146
|
-
const styles = window.getComputedStyle(child);
|
|
147
|
-
const marginTop = parseInt(styles.marginTop, 10) || 0;
|
|
148
|
-
const marginBottom = parseInt(styles.marginBottom, 10) || 0;
|
|
149
|
-
const totalHeight = rect.height + marginTop + marginBottom;
|
|
150
|
-
const isTableContent = child.id === tableContainerId;
|
|
151
|
-
const isBulkActionTable = child.id === "bulkaction_table";
|
|
152
|
-
if (!isTableContent && !isBulkActionTable) {
|
|
153
|
-
otherElementsHeight += totalHeight;
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
const tableStyles = window.getComputedStyle(tableContainer);
|
|
157
|
-
const tablePaddingTop = parseInt(tableStyles.paddingTop, 10) || 0;
|
|
158
|
-
const tablePaddingBottom = parseInt(tableStyles.paddingBottom, 10) || 0;
|
|
159
|
-
const tableHeader = tableContainer.querySelector(".ant-table-header");
|
|
160
|
-
const headerHeight = tableHeader ? tableHeader.getBoundingClientRect().height : 0;
|
|
161
|
-
let paginationHeight = 0;
|
|
162
|
-
const paginationSelectors = [
|
|
163
|
-
".ant-pagination",
|
|
164
|
-
".ant-table-pagination",
|
|
165
|
-
".ant-pagination-mini"
|
|
166
|
-
];
|
|
167
|
-
for (const selector of paginationSelectors) {
|
|
168
|
-
const pagination = tableContainer.querySelector(selector);
|
|
169
|
-
if (pagination) {
|
|
170
|
-
const paginationRect = pagination.getBoundingClientRect();
|
|
171
|
-
const paginationStyles = window.getComputedStyle(pagination);
|
|
172
|
-
const paginationMarginTop = parseInt(paginationStyles.marginTop, 10) || 0;
|
|
173
|
-
const paginationMarginBottom = parseInt(paginationStyles.marginBottom, 10) || 0;
|
|
174
|
-
paginationHeight = paginationRect.height + paginationMarginTop + paginationMarginBottom;
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
if (paginationHeight === 0) {
|
|
179
|
-
paginationHeight = 44;
|
|
180
|
-
}
|
|
181
|
-
const bulkActionHeight = 0;
|
|
182
|
-
const tableBodyHeight = availableHeight - otherElementsHeight - tablePaddingTop - tablePaddingBottom - headerHeight - paginationHeight - bulkActionHeight - extraOffset;
|
|
183
|
-
const finalHeight = Math.max(tableBodyHeight, minHeight);
|
|
184
|
-
setTableHeight(finalHeight);
|
|
185
|
-
} catch (error) {
|
|
186
|
-
console.error("Error calculating table height:", error);
|
|
187
|
-
setTableHeight(minHeight);
|
|
188
|
-
}
|
|
189
|
-
}, [tableContainerId, extraOffset, minHeight]);
|
|
190
|
-
useEffect(() => {
|
|
191
|
-
const timer = setTimeout(() => {
|
|
192
|
-
calculateTableHeight();
|
|
193
|
-
}, 300);
|
|
194
|
-
const handleResize = () => {
|
|
195
|
-
calculateTableHeight();
|
|
196
|
-
};
|
|
197
|
-
window.addEventListener("resize", handleResize);
|
|
198
|
-
const observer = new MutationObserver((mutations) => {
|
|
199
|
-
let shouldRecalculate = false;
|
|
200
|
-
mutations.forEach((mutation) => {
|
|
201
|
-
if (mutation.type === "childList") {
|
|
202
|
-
shouldRecalculate = true;
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
if (shouldRecalculate) {
|
|
206
|
-
setTimeout(calculateTableHeight, 100);
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
const layoutWrapper = document.getElementById("ID_TABLE_WRAPPER");
|
|
210
|
-
const tableContainer = document.getElementById(tableContainerId);
|
|
211
|
-
if (layoutWrapper) {
|
|
212
|
-
observer.observe(layoutWrapper, {
|
|
213
|
-
childList: true,
|
|
214
|
-
subtree: true,
|
|
215
|
-
attributes: true,
|
|
216
|
-
attributeFilter: ["style", "class"]
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
if (tableContainer && tableContainer !== layoutWrapper) {
|
|
220
|
-
observer.observe(tableContainer, {
|
|
221
|
-
childList: true,
|
|
222
|
-
subtree: true,
|
|
223
|
-
attributes: true,
|
|
224
|
-
attributeFilter: ["style", "class"]
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
return () => {
|
|
228
|
-
clearTimeout(timer);
|
|
229
|
-
window.removeEventListener("resize", handleResize);
|
|
230
|
-
observer.disconnect();
|
|
231
|
-
};
|
|
232
|
-
}, [calculateTableHeight, tableContainerId]);
|
|
233
|
-
return {
|
|
234
|
-
tableHeight,
|
|
235
|
-
recalculate: calculateTableHeight
|
|
236
|
-
};
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
const Table = ({
|
|
240
|
-
dataSource = [],
|
|
241
|
-
columns,
|
|
242
|
-
loading = false,
|
|
243
|
-
totalItems = 100,
|
|
244
|
-
filters,
|
|
245
|
-
onChangePage,
|
|
246
|
-
onChangePageSize,
|
|
247
|
-
onSort,
|
|
248
|
-
rowsSelected,
|
|
249
|
-
onSelect,
|
|
250
|
-
onRowClick,
|
|
251
|
-
rowKey = "id",
|
|
252
|
-
showIndexColumn = true,
|
|
253
|
-
size = "small",
|
|
254
|
-
defaultEllipsis = true,
|
|
255
|
-
onDoubleClickRow,
|
|
256
|
-
handleSubmit,
|
|
257
|
-
customPagination,
|
|
258
|
-
noPagination,
|
|
259
|
-
...rest
|
|
260
|
-
}) => {
|
|
261
|
-
const status = filters?.status;
|
|
262
|
-
//! State
|
|
263
|
-
const tableContainerRef = useRef(null);
|
|
264
|
-
const rowSelection = {
|
|
265
|
-
selectedRowKeys: rowsSelected,
|
|
266
|
-
onChange: onSelect,
|
|
267
|
-
getCheckboxProps: () => ({
|
|
268
|
-
disabled: status ? status === TypeStatusTable.ALL : void 0
|
|
269
|
-
})
|
|
270
|
-
};
|
|
271
|
-
const ellipsisColumns = columns.map((column) => ({
|
|
272
|
-
...column,
|
|
273
|
-
ellipsis: column?.ellipsis !== void 0 ? column?.ellipsis : defaultEllipsis
|
|
274
|
-
}));
|
|
275
|
-
const startIndex = (filters.page - 1) * filters.size;
|
|
276
|
-
const columnsWithIndex = showIndexColumn ? [
|
|
277
|
-
{
|
|
278
|
-
title: "STT",
|
|
279
|
-
dataIndex: "index",
|
|
280
|
-
key: "index",
|
|
281
|
-
width: 70,
|
|
282
|
-
align: "center",
|
|
283
|
-
render: (_, __, index) => startIndex + index + 1,
|
|
284
|
-
fixed: "left"
|
|
285
|
-
},
|
|
286
|
-
...ellipsisColumns
|
|
287
|
-
] : ellipsisColumns;
|
|
288
|
-
//! Function
|
|
289
|
-
const renderSizePagination = () => {
|
|
290
|
-
switch (size) {
|
|
291
|
-
case "small":
|
|
292
|
-
return "small";
|
|
293
|
-
// Dạng nhỏ gọn
|
|
294
|
-
default:
|
|
295
|
-
return "default";
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
const handleTableChange = (_pagination, _filters, sorter) => {
|
|
299
|
-
if (sorter && onSort) {
|
|
300
|
-
onSort(sorter);
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
const handleOnClickRow = (record, onRowClick2) => (e) => {
|
|
304
|
-
const target = e.target;
|
|
305
|
-
if (target.closest("input") || // ⛔ Checkbox
|
|
306
|
-
target.closest("button") || // ⛔ Button trong row
|
|
307
|
-
target.closest("svg") || // ⛔ Icon
|
|
308
|
-
target.closest(".ant-checkbox") || // ⛔ AntD checkbox
|
|
309
|
-
target.closest("a")) {
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
onRowClick2?.(record);
|
|
313
|
-
};
|
|
314
|
-
const handleDoubleClickRow = (record, onDoubleClickRow2) => (e) => {
|
|
315
|
-
const target = e.target;
|
|
316
|
-
if (target.closest("input") || // ⛔ Checkbox
|
|
317
|
-
target.closest("button") || // ⛔ Button trong row
|
|
318
|
-
target.closest("svg") || // ⛔ Icon
|
|
319
|
-
target.closest(".ant-checkbox") || // ⛔ AntD checkbox
|
|
320
|
-
target.closest("a")) {
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
onDoubleClickRow2?.(record);
|
|
324
|
-
};
|
|
325
|
-
const { tableHeight } = useTableHeightWrapper({
|
|
326
|
-
tableContainerId: "table_content",
|
|
327
|
-
// ID của table container
|
|
328
|
-
minHeight: 200
|
|
329
|
-
// chiều cao tối thiểu
|
|
330
|
-
});
|
|
331
|
-
useEffect(() => {
|
|
332
|
-
const scrollToTop = () => {
|
|
333
|
-
if (tableContainerRef.current) {
|
|
334
|
-
const tableBody = tableContainerRef.current.querySelector(".ant-table-body");
|
|
335
|
-
if (tableBody) {
|
|
336
|
-
tableBody.scrollTop = 0;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
const timeoutId = setTimeout(scrollToTop, 0);
|
|
341
|
-
return () => clearTimeout(timeoutId);
|
|
342
|
-
}, [filters.page]);
|
|
343
|
-
const tableContent = /* @__PURE__ */ jsxs(
|
|
344
|
-
"div",
|
|
345
|
-
{
|
|
346
|
-
ref: tableContainerRef,
|
|
347
|
-
id: "table_content",
|
|
348
|
-
className: "bg-[#FFFFFF] p-2 rounded-bl-lg rounded-br-lg",
|
|
349
|
-
children: [
|
|
350
|
-
/* @__PURE__ */ jsx(
|
|
351
|
-
Table$1,
|
|
352
|
-
{
|
|
353
|
-
rowKey,
|
|
354
|
-
dataSource,
|
|
355
|
-
columns: columnsWithIndex,
|
|
356
|
-
pagination: false,
|
|
357
|
-
loading,
|
|
358
|
-
rowSelection: rowsSelected ? rowSelection : void 0,
|
|
359
|
-
onChange: handleTableChange,
|
|
360
|
-
onRow: (record) => ({
|
|
361
|
-
onClick: handleOnClickRow(record, onRowClick),
|
|
362
|
-
onDoubleClick: handleDoubleClickRow(record, onDoubleClickRow)
|
|
363
|
-
}),
|
|
364
|
-
locale: {
|
|
365
|
-
emptyText: loading ? null : /* @__PURE__ */ jsx(EmptyTable, {})
|
|
366
|
-
},
|
|
367
|
-
scroll: { y: tableHeight, x: 1e3 },
|
|
368
|
-
size,
|
|
369
|
-
...rest,
|
|
370
|
-
className: "table-scroll-bar"
|
|
371
|
-
}
|
|
372
|
-
),
|
|
373
|
-
customPagination || !noPagination && /* @__PURE__ */ jsx(
|
|
374
|
-
CustomPagination,
|
|
375
|
-
{
|
|
376
|
-
current: filters?.page,
|
|
377
|
-
pageSize: filters?.size,
|
|
378
|
-
total: totalItems,
|
|
379
|
-
onChange: (page) => onChangePage(page),
|
|
380
|
-
onShowSizeChange: (_, size2) => onChangePageSize(size2),
|
|
381
|
-
size: renderSizePagination()
|
|
382
|
-
}
|
|
383
|
-
)
|
|
384
|
-
]
|
|
385
|
-
}
|
|
386
|
-
);
|
|
387
|
-
const renderTable = () => {
|
|
388
|
-
if (handleSubmit) {
|
|
389
|
-
return /* @__PURE__ */ jsx("form", { onSubmit: handleSubmit, children: tableContent });
|
|
390
|
-
}
|
|
391
|
-
return tableContent;
|
|
392
|
-
};
|
|
393
|
-
//! Render
|
|
394
|
-
return renderTable();
|
|
395
|
-
};
|
|
396
|
-
const EmptyTable = () => {
|
|
397
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center text-center", children: [
|
|
398
|
-
/* @__PURE__ */ jsx("img", { src: iconTableNoData, alt: "no data" }),
|
|
399
|
-
/* @__PURE__ */ jsx("span", { className: "text-lg font-bold text-black", children: "Không có dữ liệu nào phù hợp" }),
|
|
400
|
-
/* @__PURE__ */ jsx("p", { className: "text-gray-500", children: "Kiểm tra lại bộ lọc hoặc thêm mới dữ liệu" })
|
|
401
|
-
] });
|
|
402
|
-
};
|
|
403
|
-
|
|
404
|
-
export { Table };
|