kelt-ui-kit-react 1.8.5 → 1.8.9
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/dataTable/dataTable.interface.d.ts +4 -1
- package/dist/index.js +741 -715
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/dataTable/DataTable.tsx +48 -14
- package/src/dataTable/dataTable.css +26 -2
- package/src/dataTable/dataTable.interface.ts +4 -1
- package/src/dataTable/dataTableRow/DataTableRow.tsx +13 -1
package/package.json
CHANGED
|
@@ -55,15 +55,28 @@ export function DataTable<T>(props: DataTableProps<T>) {
|
|
|
55
55
|
|
|
56
56
|
const loaderRef = useRef<HTMLDivElement | null>(null);
|
|
57
57
|
const [selectedRowIds, setSelectedRowIds] = useState<Set<string | number>>(
|
|
58
|
-
new Set()
|
|
58
|
+
new Set(),
|
|
59
59
|
);
|
|
60
|
+
|
|
61
|
+
const isInteractiveClick = useCallback((target: EventTarget | null) => {
|
|
62
|
+
if (!(target instanceof HTMLElement)) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return Boolean(
|
|
67
|
+
target.closest(
|
|
68
|
+
"input,button,a,select,textarea,label,[role='button'],[role='checkbox'],[data-stop-row-click='true']",
|
|
69
|
+
),
|
|
70
|
+
);
|
|
71
|
+
}, []);
|
|
72
|
+
|
|
60
73
|
const toggleSelectAll = useCallback(() => {
|
|
61
74
|
if (selectedRowIds.size === data.length) {
|
|
62
75
|
setSelectedRowIds(new Set());
|
|
63
76
|
onSelectionChange?.([]);
|
|
64
77
|
} else {
|
|
65
78
|
let allIds = data.map((d) =>
|
|
66
|
-
getRowId ? getRowId(d) : (d as any).id ?? d
|
|
79
|
+
getRowId ? getRowId(d) : ((d as any).id ?? d),
|
|
67
80
|
);
|
|
68
81
|
|
|
69
82
|
if (limitSelect && allIds.length > limitSelect) {
|
|
@@ -74,8 +87,8 @@ export function DataTable<T>(props: DataTableProps<T>) {
|
|
|
74
87
|
setSelectedRowIds(newSelection);
|
|
75
88
|
onSelectionChange?.(
|
|
76
89
|
data.filter((d) =>
|
|
77
|
-
newSelection.has(getRowId ? getRowId(d) : (d as any).id ?? d)
|
|
78
|
-
)
|
|
90
|
+
newSelection.has(getRowId ? getRowId(d) : ((d as any).id ?? d)),
|
|
91
|
+
),
|
|
79
92
|
);
|
|
80
93
|
}
|
|
81
94
|
}, [data, onSelectionChange, limitSelect, getRowId, selectedRowIds.size]);
|
|
@@ -83,16 +96,29 @@ export function DataTable<T>(props: DataTableProps<T>) {
|
|
|
83
96
|
const handleClickRow = useCallback(
|
|
84
97
|
(e: React.MouseEvent, row: T) => {
|
|
85
98
|
e.stopPropagation();
|
|
99
|
+
|
|
100
|
+
if (isInteractiveClick(e.target)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const selectedText =
|
|
105
|
+
typeof window !== "undefined"
|
|
106
|
+
? window.getSelection?.()?.toString().trim()
|
|
107
|
+
: "";
|
|
108
|
+
if (selectedText) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
86
112
|
if (onRowClick) {
|
|
87
113
|
onRowClick?.(row);
|
|
88
114
|
}
|
|
89
115
|
},
|
|
90
|
-
[onRowClick]
|
|
116
|
+
[isInteractiveClick, onRowClick],
|
|
91
117
|
);
|
|
92
118
|
const toggleRow = useCallback(
|
|
93
119
|
(e: React.ChangeEvent<HTMLInputElement>, row: T) => {
|
|
94
120
|
e.stopPropagation();
|
|
95
|
-
const rowId = getRowId ? getRowId(row) : (row as any).id ?? row;
|
|
121
|
+
const rowId = getRowId ? getRowId(row) : ((row as any).id ?? row);
|
|
96
122
|
const newSelection = new Set(selectedRowIds);
|
|
97
123
|
|
|
98
124
|
if (newSelection.has(rowId)) {
|
|
@@ -107,11 +133,11 @@ export function DataTable<T>(props: DataTableProps<T>) {
|
|
|
107
133
|
|
|
108
134
|
setSelectedRowIds(newSelection);
|
|
109
135
|
const selectedItems = data.filter((d) =>
|
|
110
|
-
newSelection.has(getRowId ? getRowId(d) : (d as any).id ?? d)
|
|
136
|
+
newSelection.has(getRowId ? getRowId(d) : ((d as any).id ?? d)),
|
|
111
137
|
);
|
|
112
138
|
onSelectionChange?.(selectedItems);
|
|
113
139
|
},
|
|
114
|
-
[data, getRowId, limitSelect, onSelectionChange, selectedRowIds]
|
|
140
|
+
[data, getRowId, limitSelect, onSelectionChange, selectedRowIds],
|
|
115
141
|
);
|
|
116
142
|
useEffect(() => {
|
|
117
143
|
if (!onLoadMore || !hasMore) return;
|
|
@@ -126,7 +152,7 @@ export function DataTable<T>(props: DataTableProps<T>) {
|
|
|
126
152
|
root: null,
|
|
127
153
|
rootMargin: "0px",
|
|
128
154
|
threshold: 1.0,
|
|
129
|
-
}
|
|
155
|
+
},
|
|
130
156
|
);
|
|
131
157
|
|
|
132
158
|
if (loaderRef.current) {
|
|
@@ -198,9 +224,17 @@ export function DataTable<T>(props: DataTableProps<T>) {
|
|
|
198
224
|
)}
|
|
199
225
|
{!loading &&
|
|
200
226
|
data.map((row, rowIndex) => (
|
|
201
|
-
<tr
|
|
227
|
+
<tr
|
|
228
|
+
key={rowIndex}
|
|
229
|
+
className={rowIndex % 2 === 0 ? "even" : "odd"}
|
|
230
|
+
onClick={(e) => handleClickRow?.(e, row)}
|
|
231
|
+
>
|
|
202
232
|
{onSelectionChange && (
|
|
203
|
-
<td
|
|
233
|
+
<td
|
|
234
|
+
className="select-cell"
|
|
235
|
+
style={{ textAlign: "center" }}
|
|
236
|
+
onClick={(e) => e.stopPropagation()}
|
|
237
|
+
>
|
|
204
238
|
<Input
|
|
205
239
|
id={`select-row-${rowIndex}`}
|
|
206
240
|
name={`select-row-${rowIndex}`}
|
|
@@ -209,11 +243,11 @@ export function DataTable<T>(props: DataTableProps<T>) {
|
|
|
209
243
|
limitSelect !== undefined &&
|
|
210
244
|
selectedRowIds.size >= limitSelect &&
|
|
211
245
|
!selectedRowIds.has(
|
|
212
|
-
getRowId ? getRowId(row) : (row as any).id ?? row
|
|
246
|
+
getRowId ? getRowId(row) : ((row as any).id ?? row),
|
|
213
247
|
)
|
|
214
248
|
}
|
|
215
249
|
checked={selectedRowIds.has(
|
|
216
|
-
getRowId ? getRowId(row) : (row as any).id ?? row
|
|
250
|
+
getRowId ? getRowId(row) : ((row as any).id ?? row),
|
|
217
251
|
)}
|
|
218
252
|
onChange={(e) => toggleRow(e, row)} // empêche le clic de déclencher onRowClick
|
|
219
253
|
/>
|
|
@@ -223,7 +257,7 @@ export function DataTable<T>(props: DataTableProps<T>) {
|
|
|
223
257
|
<DataTableRow column={column} idx={idx} row={row} key={idx} />
|
|
224
258
|
))}
|
|
225
259
|
{actions.length > 0 && (
|
|
226
|
-
<td align="right">
|
|
260
|
+
<td align="right" onClick={(e) => e.stopPropagation()}>
|
|
227
261
|
<div className="d-flex align-items-center justify-content-end">
|
|
228
262
|
{actions.map((action, index) => (
|
|
229
263
|
<DataTableAction
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
.data-table-container {
|
|
2
2
|
overflow: auto;
|
|
3
|
+
|
|
3
4
|
.data-table {
|
|
4
5
|
width: 100%;
|
|
5
|
-
border-spacing:
|
|
6
|
+
border-spacing: 0;
|
|
6
7
|
font-size: 14px;
|
|
7
8
|
color: #333;
|
|
9
|
+
|
|
8
10
|
.select-cell {
|
|
9
11
|
min-width: 40px !important;
|
|
12
|
+
|
|
10
13
|
.input-container {
|
|
11
14
|
min-width: 20px;
|
|
15
|
+
|
|
12
16
|
input {
|
|
13
17
|
min-width: 20px;
|
|
14
18
|
width: 20px;
|
|
@@ -16,15 +20,35 @@
|
|
|
16
20
|
}
|
|
17
21
|
}
|
|
18
22
|
}
|
|
23
|
+
|
|
19
24
|
thead {
|
|
20
25
|
margin-bottom: 1rem;
|
|
21
26
|
position: sticky;
|
|
22
27
|
top: 0;
|
|
23
28
|
background-color: #fff;
|
|
29
|
+
|
|
24
30
|
th {
|
|
25
31
|
color: #bdbaba;
|
|
26
32
|
min-width: 100px;
|
|
27
33
|
}
|
|
28
34
|
}
|
|
35
|
+
|
|
36
|
+
tbody {
|
|
37
|
+
td {
|
|
38
|
+
padding: 0.5rem;
|
|
39
|
+
|
|
40
|
+
&:not(:first-child) {
|
|
41
|
+
padding-left: 0 !important;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
tr.even {
|
|
46
|
+
background-color: #ffffff;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
tr.odd {
|
|
50
|
+
background-color: #f5f5f5;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
29
53
|
}
|
|
30
|
-
}
|
|
54
|
+
}
|
|
@@ -16,7 +16,10 @@ export interface dataTableColumnsInterface<T> {
|
|
|
16
16
|
onEdit?: (value: any, row: T) => void;
|
|
17
17
|
onDisable?: (row: T) => boolean;
|
|
18
18
|
onRowStyle?: (row: T) => React.CSSProperties;
|
|
19
|
-
type: HTMLInputTypeAttribute | "select";
|
|
19
|
+
type: HTMLInputTypeAttribute | "select" | "image";
|
|
20
|
+
imageAlt?: (row: T) => string;
|
|
21
|
+
imageStyle?: React.CSSProperties;
|
|
22
|
+
imageSrc?: (row: T) => string;
|
|
20
23
|
}
|
|
21
24
|
export interface dataTableActionsInterface<T> {
|
|
22
25
|
id: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Icon } from "../..";
|
|
1
2
|
import { Select } from "../../select/Select";
|
|
2
3
|
import { dataTableColumnsInterface } from "../dataTable.interface";
|
|
3
4
|
|
|
@@ -10,6 +11,7 @@ export const DataTableRow = ({ column, idx, row }: DataTableRowProps) => {
|
|
|
10
11
|
const value = (row as any)[column.id]; // On utilise [column.id] pour accéder aux bonnes propriétés
|
|
11
12
|
const style = column.onRowStyle ? column.onRowStyle(row) : {};
|
|
12
13
|
const isDisabled = column.onDisable?.(row) ?? false;
|
|
14
|
+
|
|
13
15
|
return (
|
|
14
16
|
<td
|
|
15
17
|
className={`${isDisabled ? "disabled" : ""}`}
|
|
@@ -22,7 +24,17 @@ export const DataTableRow = ({ column, idx, row }: DataTableRowProps) => {
|
|
|
22
24
|
}}
|
|
23
25
|
key={`row-${column.id}-${idx}`}
|
|
24
26
|
>
|
|
25
|
-
{column.
|
|
27
|
+
{column.type === "image" ? (
|
|
28
|
+
value ? (
|
|
29
|
+
<img
|
|
30
|
+
src={column.imageSrc ? column.imageSrc(row) : ""}
|
|
31
|
+
alt={column.imageAlt ? column.imageAlt(row) : ""}
|
|
32
|
+
style={column.imageStyle}
|
|
33
|
+
/>
|
|
34
|
+
) : (
|
|
35
|
+
<Icon classIcon="bi-image" />
|
|
36
|
+
)
|
|
37
|
+
) : column.editable ? (
|
|
26
38
|
column.type === "select" ? (
|
|
27
39
|
<Select
|
|
28
40
|
options={column.options ?? []}
|