next-helios-fe 1.1.9 → 1.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-helios-fe",
3
- "version": "1.1.9",
3
+ "version": "1.1.11",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,20 +8,33 @@ import { Action, type ActionProps } from "./action";
8
8
 
9
9
  interface TableProps {
10
10
  title?: string;
11
-
12
11
  header: {
13
12
  title: string;
14
13
  key: string;
15
14
  render?: (item: any) => React.ReactNode;
16
15
  }[];
17
- data: any[];
16
+ data: {
17
+ id: number | string;
18
+ [key: string]: any;
19
+ }[];
18
20
  options?: {
19
21
  hideToolbar?: boolean;
20
22
  hideNumberColumn?: boolean;
21
- checkbox?: boolean;
22
- height?: "full" | "fit" | "20" | "40" | "80";
23
+ enableBorder?: boolean;
23
24
  maxRow?: 10 | 20 | 50 | 100;
24
- border?: boolean;
25
+ height?: "full" | "fit" | "20" | "40" | "80";
26
+ };
27
+ checkbox?: {
28
+ checked?: {
29
+ id: number | string;
30
+ [key: string]: any;
31
+ }[];
32
+ onCheck?: (
33
+ checked: {
34
+ id: number | string;
35
+ [key: string]: any;
36
+ }[]
37
+ ) => void;
25
38
  };
26
39
  actions?: (e: any) => React.ReactNode;
27
40
  onAddData?: (e: React.MouseEvent<HTMLButtonElement>) => void;
@@ -36,6 +49,7 @@ export const Table: TableComponentProps = ({
36
49
  header,
37
50
  data,
38
51
  options,
52
+ checkbox,
39
53
  actions,
40
54
  onAddData,
41
55
  }) => {
@@ -43,7 +57,12 @@ export const Table: TableComponentProps = ({
43
57
  const [filter, setFilter] = useState<any[]>([]);
44
58
  const [maxRow, setMaxRow] = useState<number>(options?.maxRow || 10);
45
59
  const [page, setPage] = useState<number>(1);
46
- const [selected, setSelected] = useState<number[]>([]);
60
+ const [selected, setSelected] = useState<
61
+ {
62
+ id: number | string;
63
+ [key: string]: any;
64
+ }[]
65
+ >([]);
47
66
  const [sortBy, setSortBy] = useState<string[]>(["", ""]);
48
67
  const [excluded, setExcluded] = useState<string[]>([]);
49
68
 
@@ -66,6 +85,18 @@ export const Table: TableComponentProps = ({
66
85
  );
67
86
  }, [header]);
68
87
 
88
+ useEffect(() => {
89
+ if (checkbox?.checked) {
90
+ setSelected(checkbox?.checked);
91
+ }
92
+ }, [checkbox]);
93
+
94
+ useEffect(() => {
95
+ if (selected.length !== 0) {
96
+ checkbox?.onCheck && checkbox.onCheck(selected);
97
+ }
98
+ }, [selected]);
99
+
69
100
  const filteredData = useMemo(() => {
70
101
  return data
71
102
  ?.filter((item) => {
@@ -180,16 +211,22 @@ export const Table: TableComponentProps = ({
180
211
  ?.map((item, index) => {
181
212
  return (
182
213
  <tr key={item.id}>
183
- {options?.checkbox && (
214
+ {checkbox && (
184
215
  <td className="sticky left-0 w-8 px-4 py-1 border-b bg-secondary-bg">
185
216
  <Form.Checkbox
186
217
  options={{ disableHover: true }}
187
- checked={selected.includes(item.id)}
218
+ checked={
219
+ selected.find((selectedItem) => selectedItem.id === item.id)
220
+ ? true
221
+ : false
222
+ }
188
223
  onChange={(e) => {
189
- if (selected.includes(item.id)) {
190
- setSelected(selected.filter((prev) => prev !== item.id));
224
+ if (
225
+ selected.find((selectedItem) => selectedItem.id === item.id)
226
+ ) {
227
+ setSelected(selected.filter((prev) => prev.id !== item.id));
191
228
  } else {
192
- setSelected([...selected, item.id]);
229
+ setSelected((prev) => [...prev, item]);
193
230
  }
194
231
  }}
195
232
  />
@@ -307,13 +344,13 @@ export const Table: TableComponentProps = ({
307
344
  )}
308
345
  <div
309
346
  className={`overflow-auto ${height} ${
310
- options?.border && "border rounded-md"
347
+ options?.enableBorder && "border rounded-md"
311
348
  }`}
312
349
  >
313
350
  <table className="w-full text-sm overflow-x-auto">
314
351
  <thead className="sticky top-0 z-10 border-b">
315
352
  <tr>
316
- {options?.checkbox && (
353
+ {checkbox && (
317
354
  <th className="sticky left-0 w-8 px-4 py-2 bg-secondary-bg">
318
355
  <div className="flex flex-col">
319
356
  <Form.Checkbox
@@ -323,7 +360,7 @@ export const Table: TableComponentProps = ({
323
360
  if (selected.length === data.length) {
324
361
  setSelected([]);
325
362
  } else {
326
- setSelected(data.map((item) => item.id));
363
+ setSelected(data.map((item) => item));
327
364
  }
328
365
  }}
329
366
  />