next-helios-fe 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.
|
@@ -32,6 +32,8 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
32
32
|
|
|
33
33
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
|
|
34
34
|
|
|
35
|
+
/*! sheetjs (C) 2013-present SheetJS -- http://sheetjs.com */
|
|
36
|
+
|
|
35
37
|
/*! svg.draggable.js - v2.2.2 - 2019-01-08
|
|
36
38
|
* https://github.com/svgdotjs/svg.draggable.js
|
|
37
39
|
* Copyright (c) 2019 Wout Fierens; Licensed MIT */
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import React, { useState, useEffect, useMemo } from "react";
|
|
3
3
|
import { Icon } from "@iconify/react";
|
|
4
|
+
import { exportToExcel } from "react-json-to-excel";
|
|
5
|
+
import dayjs from "dayjs";
|
|
4
6
|
import { Form, Button, Dropdown } from "../../components";
|
|
5
7
|
import { Action, type ActionProps } from "./action";
|
|
6
8
|
|
|
7
9
|
interface TableProps {
|
|
8
10
|
title?: string;
|
|
11
|
+
|
|
9
12
|
header: {
|
|
10
13
|
title: string;
|
|
11
14
|
key: string;
|
|
@@ -14,13 +17,14 @@ interface TableProps {
|
|
|
14
17
|
data: any[];
|
|
15
18
|
options?: {
|
|
16
19
|
hideToolbar?: boolean;
|
|
17
|
-
|
|
20
|
+
hideNumberColumn?: boolean;
|
|
18
21
|
checkbox?: boolean;
|
|
19
22
|
height?: "full" | "fit" | "20" | "40" | "80";
|
|
20
23
|
maxRow?: 10 | 20 | 50 | 100;
|
|
21
24
|
border?: boolean;
|
|
22
25
|
};
|
|
23
26
|
actions?: (e: any) => React.ReactNode;
|
|
27
|
+
onAddData?: (e: React.MouseEvent<HTMLButtonElement>) => void;
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
interface TableComponentProps extends React.FC<TableProps> {
|
|
@@ -33,6 +37,7 @@ export const Table: TableComponentProps = ({
|
|
|
33
37
|
data,
|
|
34
38
|
options,
|
|
35
39
|
actions,
|
|
40
|
+
onAddData,
|
|
36
41
|
}) => {
|
|
37
42
|
const [search, setSearch] = useState<string>("");
|
|
38
43
|
const [filter, setFilter] = useState<any[]>([]);
|
|
@@ -68,12 +73,10 @@ export const Table: TableComponentProps = ({
|
|
|
68
73
|
return item;
|
|
69
74
|
} else if (
|
|
70
75
|
header.some((headerItem) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
.includes(search.toLowerCase());
|
|
76
|
-
}
|
|
76
|
+
return item[headerItem.key as keyof typeof item]
|
|
77
|
+
?.toString()
|
|
78
|
+
.toLowerCase()
|
|
79
|
+
.includes(search.toLowerCase());
|
|
77
80
|
})
|
|
78
81
|
) {
|
|
79
82
|
return item;
|
|
@@ -130,22 +133,30 @@ export const Table: TableComponentProps = ({
|
|
|
130
133
|
}`}
|
|
131
134
|
/>
|
|
132
135
|
</button>
|
|
133
|
-
<
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
136
|
+
<div className="relative flex items-center">
|
|
137
|
+
<input
|
|
138
|
+
type="search"
|
|
139
|
+
className="w-full ps-6 pe-0 pt-0 pb-0.5 border-default border-t-0 border-b border-x-0 bg-secondary-bg text-sm font-normal placeholder:duration-300 placeholder:translate-x-0 [&::-webkit-search-cancel-button]:appearance-none focus:placeholder:translate-x-1 placeholder:text-slate-300 focus:outline-none focus:ring-0 focus:border-primary-dark disabled:bg-secondary-light disabled:text-slate-400"
|
|
140
|
+
placeholder="search.."
|
|
141
|
+
value={
|
|
142
|
+
filter.find((filterItem) => filterItem.key === item.key)
|
|
143
|
+
?.value
|
|
144
|
+
}
|
|
145
|
+
onChange={(e) => {
|
|
146
|
+
setFilter(
|
|
147
|
+
filter.map((filterItem) => {
|
|
148
|
+
return filterItem.key === item.key
|
|
149
|
+
? { ...filterItem, value: e.target.value }
|
|
150
|
+
: filterItem;
|
|
151
|
+
})
|
|
152
|
+
);
|
|
153
|
+
}}
|
|
154
|
+
/>
|
|
155
|
+
<Icon
|
|
156
|
+
icon="ic:round-search"
|
|
157
|
+
className="absolute text-sm text-slate-400"
|
|
158
|
+
/>
|
|
159
|
+
</div>
|
|
149
160
|
</div>
|
|
150
161
|
</th>
|
|
151
162
|
);
|
|
@@ -184,7 +195,7 @@ export const Table: TableComponentProps = ({
|
|
|
184
195
|
/>
|
|
185
196
|
</td>
|
|
186
197
|
)}
|
|
187
|
-
{!options?.
|
|
198
|
+
{!options?.hideNumberColumn && (
|
|
188
199
|
<td className="sticky left-0 px-4 py-1 border-b bg-secondary-bg text-center">
|
|
189
200
|
{(page - 1) * maxRow + index + 1}
|
|
190
201
|
</td>
|
|
@@ -227,6 +238,17 @@ export const Table: TableComponentProps = ({
|
|
|
227
238
|
<div className="flex justify-between items-center gap-4 w-full h-fit">
|
|
228
239
|
<span className="text-lg">{title}</span>
|
|
229
240
|
<div className="flex items-center gap-4">
|
|
241
|
+
{onAddData && (
|
|
242
|
+
<button
|
|
243
|
+
type="button"
|
|
244
|
+
className="p-1.5 rounded-full bg-primary text-white hover:bg-primary-dark"
|
|
245
|
+
onClick={(e) => {
|
|
246
|
+
onAddData && onAddData(e);
|
|
247
|
+
}}
|
|
248
|
+
>
|
|
249
|
+
<Icon icon="ic:round-plus" className="text-2xl" />
|
|
250
|
+
</button>
|
|
251
|
+
)}
|
|
230
252
|
<Dropdown
|
|
231
253
|
trigger={
|
|
232
254
|
<button
|
|
@@ -270,7 +292,12 @@ export const Table: TableComponentProps = ({
|
|
|
270
292
|
/>
|
|
271
293
|
<Button
|
|
272
294
|
options={{ variant: "primary", width: "fit" }}
|
|
273
|
-
onClick={() => {
|
|
295
|
+
onClick={() => {
|
|
296
|
+
exportToExcel(
|
|
297
|
+
filteredData,
|
|
298
|
+
`${title}-data_${dayjs().format("YYYY-MM-DD_HH-mm-ss")}`
|
|
299
|
+
);
|
|
300
|
+
}}
|
|
274
301
|
>
|
|
275
302
|
Export
|
|
276
303
|
</Button>
|
|
@@ -308,8 +335,8 @@ export const Table: TableComponentProps = ({
|
|
|
308
335
|
</div>
|
|
309
336
|
</th>
|
|
310
337
|
)}
|
|
311
|
-
{!options?.
|
|
312
|
-
<th className="sticky left-0 w-min px-4 py-2 bg-secondary-bg font-medium text-center whitespace-nowrap">
|
|
338
|
+
{!options?.hideNumberColumn && (
|
|
339
|
+
<th className="sticky left-0 w-min px-4 py-2 z-10 bg-secondary-bg font-medium text-center whitespace-nowrap">
|
|
313
340
|
<div className="flex flex-col">
|
|
314
341
|
<span>NO.</span>
|
|
315
342
|
<div className="invisible w-0 overflow-hidden">
|