kelt-ui-kit-react 1.2.4 → 1.2.5
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/README.md +46 -46
- package/dist/App.d.ts +3 -2
- package/dist/App.menu.d.ts +10 -10
- package/dist/App.routes.d.ts +1 -1
- package/dist/_core/hooks/ImageChecker.d.ts +6 -5
- package/dist/_core/hooks/useIsMobile.d.ts +1 -1
- package/dist/action/Action.view.d.ts +1 -1
- package/dist/action/ButtonAction.d.ts +9 -8
- package/dist/badge/Badge.d.ts +9 -8
- package/dist/badge/Badge.view.d.ts +1 -1
- package/dist/button/Button.d.ts +2 -1
- package/dist/button/Button.view.d.ts +1 -1
- package/dist/button/button.interface.d.ts +18 -17
- package/dist/button/buttonActions/ButtonActions.d.ts +11 -10
- package/dist/card/Card.d.ts +13 -12
- package/dist/card/Card.view.d.ts +1 -1
- package/dist/card/card.interface.d.ts +10 -10
- package/dist/card/cardAction/CardAction.d.ts +14 -13
- package/dist/card/cardAction.interface.d.ts +9 -8
- package/dist/card/hook/useCardInteractions.d.ts +8 -8
- package/dist/carousel/Carousel.d.ts +15 -14
- package/dist/carousel/Carousel.view.d.ts +1 -1
- package/dist/damier/Damier.d.ts +10 -9
- package/dist/damier/Damier.view.d.ts +1 -1
- package/dist/damier/damierCell/DamierCell.d.ts +7 -6
- package/dist/damier/damierCell/damierCell.interface.d.ts +6 -6
- package/dist/dataTable/DataTable.d.ts +18 -17
- package/dist/dataTable/DataTable.view.d.ts +1 -1
- package/dist/dataTable/dataTable.interface.d.ts +31 -30
- package/dist/datePicker/DatePicker.d.ts +8 -7
- package/dist/datePicker/DatePicker.view.d.ts +1 -1
- package/dist/expands/Expands.d.ts +10 -9
- package/dist/expands/Expands.view.d.ts +1 -1
- package/dist/expands/expand/expand.d.ts +9 -8
- package/dist/expands/expand/expand.interface.d.ts +9 -9
- package/dist/filAriane/FilAriane.d.ts +9 -8
- package/dist/filAriane/FilAriane.view.d.ts +1 -1
- package/dist/filAriane/filAriane.interface.d.ts +6 -6
- package/dist/form/Form.d.ts +24 -23
- package/dist/form/Form.view.d.ts +1 -1
- package/dist/form/form.enum.d.ts +11 -11
- package/dist/form/form.interface.d.ts +30 -29
- package/dist/form/textArea/TextArea.d.ts +13 -12
- package/dist/form/textArea/TextArea.view.d.ts +1 -1
- package/dist/grid/Grid.d.ts +8 -7
- package/dist/grid/Grid.view.d.ts +1 -1
- package/dist/grid/col/Col.d.ts +10 -10
- package/dist/grid/col/colStyled/ColStyled.d.ts +9 -9
- package/dist/grid/container/Container.d.ts +6 -5
- package/dist/grid/grid.interface.d.ts +8 -8
- package/dist/grid/row/Row.d.ts +8 -7
- package/dist/header/Header.d.ts +2 -1
- package/dist/header/Header.view.d.ts +1 -1
- package/dist/header/header.interface.d.ts +9 -9
- package/dist/home/Home.d.ts +1 -1
- package/dist/icon/Icon.d.ts +2 -1
- package/dist/icon/Icons.view.d.ts +1 -1
- package/dist/icon/icon.interface.d.ts +5 -4
- package/dist/icon/iconSize.enum.d.ts +7 -7
- package/dist/index.d.ts +32 -31
- package/dist/index.html +18 -18
- package/dist/index.js +1 -1
- package/dist/loader/Loader.d.ts +8 -7
- package/dist/loader/Loader.view.d.ts +1 -1
- package/dist/main.d.ts +1 -0
- package/dist/manifest.json +25 -25
- package/dist/menus/Menus.d.ts +6 -5
- package/dist/menus/Menus.view.d.ts +1 -1
- package/dist/menus/menu/Menu.d.ts +7 -6
- package/dist/menus/menu/menu.interface.d.ts +10 -10
- package/dist/modal/Modal.d.ts +13 -12
- package/dist/modal/Modal.view.d.ts +1 -1
- package/dist/notFound/NotFound.d.ts +1 -1
- package/dist/overlayPanel/OverlayPanel.d.ts +19 -18
- package/dist/overlayPanel/OverlayPanel.view.d.ts +1 -1
- package/dist/overlayPanel/overlay.context.d.ts +10 -9
- package/dist/overlayPanel/overlayPanelStyled/OverlayPanelStyled.d.ts +7 -7
- package/dist/quantity/Quantity.d.ts +11 -10
- package/dist/robots.txt +3 -3
- package/dist/search/Search.d.ts +22 -21
- package/dist/search/Search.view.d.ts +1 -1
- package/dist/select/Select.d.ts +14 -13
- package/dist/select/Select.view.d.ts +1 -1
- package/dist/select/selectOption.interface.d.ts +4 -4
- package/dist/sidebar/Sidebar.d.ts +13 -12
- package/dist/sidebar/Sidebar.view.d.ts +1 -1
- package/dist/sidebarData/SidebarData.d.ts +7 -6
- package/dist/sidebarData/SidebarData.view.d.ts +1 -1
- package/dist/style.css +1 -1
- package/dist/toaster/Toaster.d.ts +2 -1
- package/dist/toaster/Toaster.view.d.ts +1 -1
- package/dist/toaster/store/useToasterStore.d.ts +18 -18
- package/index.html +19 -19
- package/package.json +55 -55
- package/public/index.html +18 -18
- package/public/manifest.json +25 -25
- package/public/robots.txt +3 -3
- package/src/App.css +11 -11
- package/src/App.menu.tsx +209 -209
- package/src/App.routes.tsx +16 -16
- package/src/App.tsx +28 -28
- package/src/_core/hooks/ImageChecker.tsx +26 -26
- package/src/_core/hooks/useIsMobile.ts +18 -18
- package/src/action/Action.view.tsx +21 -21
- package/src/action/ButtonAction.tsx +32 -32
- package/src/action/action.css +20 -20
- package/src/badge/Badge.tsx +34 -34
- package/src/badge/Badge.view.tsx +15 -15
- package/src/badge/badge.css +55 -55
- package/src/button/Button.tsx +44 -44
- package/src/button/Button.view.tsx +61 -61
- package/src/button/button.css +53 -53
- package/src/button/button.interface.tsx +20 -20
- package/src/button/buttonActions/ButtonActions.tsx +101 -101
- package/src/card/Card.tsx +125 -125
- package/src/card/Card.view.tsx +73 -73
- package/src/card/card.css +145 -145
- package/src/card/card.interface.tsx +9 -9
- package/src/card/cardAction/CardAction.tsx +135 -135
- package/src/card/cardAction/cardAction.css +10 -10
- package/src/card/cardAction.interface.tsx +10 -10
- package/src/card/hook/useCardInteractions.tsx +30 -30
- package/src/carousel/Carousel.css +44 -44
- package/src/carousel/Carousel.tsx +115 -115
- package/src/carousel/Carousel.view.tsx +13 -13
- package/src/damier/Damier.tsx +55 -55
- package/src/damier/Damier.view.tsx +31 -31
- package/src/damier/damier.css +44 -44
- package/src/damier/damierCell/DamierCell.tsx +18 -18
- package/src/damier/damierCell/damierCell.interface.tsx +5 -5
- package/src/dataTable/DataTable.tsx +241 -241
- package/src/dataTable/DataTable.view.tsx +59 -59
- package/src/dataTable/dataTable.css +17 -17
- package/src/dataTable/dataTable.interface.ts +29 -29
- package/src/datePicker/DatePicker.tsx +110 -110
- package/src/datePicker/DatePicker.view.tsx +9 -9
- package/src/datePicker/datePicker.css +77 -77
- package/src/expands/Expands.tsx +42 -42
- package/src/expands/Expands.view.tsx +90 -90
- package/src/expands/expand/expand.interface.tsx +8 -8
- package/src/expands/expand/expand.tsx +75 -75
- package/src/expands/expands.css +97 -97
- package/src/filAriane/FilAriane.tsx +57 -57
- package/src/filAriane/FilAriane.view.tsx +28 -28
- package/src/filAriane/filAriane.css +22 -22
- package/src/filAriane/filAriane.interface.tsx +6 -6
- package/src/form/Form.tsx +175 -175
- package/src/form/Form.view.tsx +47 -47
- package/src/form/form.css +37 -37
- package/src/form/form.enum.ts +11 -11
- package/src/form/form.interface.tsx +31 -31
- package/src/form/textArea/TextArea.tsx +53 -53
- package/src/form/textArea/TextArea.view.tsx +34 -34
- package/src/form/textArea/textArea.css +9 -9
- package/src/grid/Grid.tsx +21 -21
- package/src/grid/Grid.view.tsx +24 -24
- package/src/grid/col/Col.tsx +15 -15
- package/src/grid/col/colStyled/ColStyled.tsx +41 -41
- package/src/grid/container/Container.tsx +8 -8
- package/src/grid/container/container.css +5 -5
- package/src/grid/grid.interface.tsx +7 -7
- package/src/grid/row/Row.tsx +12 -12
- package/src/grid/row/row.css +18 -18
- package/src/header/Header.tsx +51 -51
- package/src/header/Header.view.tsx +5 -5
- package/src/header/header.css +26 -26
- package/src/header/header.interface.tsx +8 -8
- package/src/home/Home.tsx +3 -3
- package/src/icon/Icon.tsx +6 -6
- package/src/icon/Icons.view.tsx +29 -29
- package/src/icon/icon.css +20 -20
- package/src/icon/icon.interface.tsx +6 -6
- package/src/icon/iconSize.enum.ts +7 -7
- package/src/index.css +502 -502
- package/src/index.ts +33 -33
- package/src/loader/Loader.tsx +37 -37
- package/src/loader/Loader.view.tsx +20 -20
- package/src/loader/loader.css +30 -30
- package/src/main.tsx +10 -10
- package/src/menus/Menus.tsx +42 -42
- package/src/menus/Menus.view.tsx +39 -39
- package/src/menus/menu/Menu.tsx +17 -17
- package/src/menus/menu/menu.interface.tsx +9 -9
- package/src/menus/menus.css +47 -47
- package/src/modal/Modal.tsx +53 -53
- package/src/modal/Modal.view.tsx +25 -25
- package/src/modal/modal.css +71 -70
- package/src/notFound/NotFound.tsx +3 -3
- package/src/overlayPanel/OverlayPanel.tsx +189 -189
- package/src/overlayPanel/OverlayPanel.view.tsx +25 -25
- package/src/overlayPanel/overlay.context.tsx +28 -28
- package/src/overlayPanel/overlayPanel.css +35 -35
- package/src/overlayPanel/overlayPanelStyled/OverlayPanelStyled.tsx +18 -18
- package/src/quantity/Quantity.tsx +103 -103
- package/src/quantity/quantity.css +26 -26
- package/src/search/Search.tsx +161 -161
- package/src/search/Search.view.tsx +14 -14
- package/src/search/search.css +59 -59
- package/src/select/Select.tsx +53 -53
- package/src/select/Select.view.tsx +71 -71
- package/src/select/select.css +51 -51
- package/src/select/selectOption.interface.ts +4 -4
- package/src/sidebar/Sidebar.tsx +111 -111
- package/src/sidebar/Sidebar.view.tsx +17 -17
- package/src/sidebar/sidebar.css +87 -87
- package/src/sidebarData/SidebarData.tsx +19 -19
- package/src/sidebarData/SidebarData.view.tsx +19 -19
- package/src/sidebarData/sidebarData.css +27 -27
- package/src/toaster/Toaster.tsx +47 -47
- package/src/toaster/Toaster.view.tsx +3 -3
- package/src/toaster/store/useToasterStore.tsx +39 -39
- package/src/toaster/toaster.css +57 -57
- package/tsconfig.json +28 -28
- package/vite.config.ts +20 -20
- package/vite.config.ts.timestamp-1733262892554-a13dfef6e8a29.mjs +24 -24
|
@@ -1,241 +1,241 @@
|
|
|
1
|
-
import { useEffect, useRef } from "react";
|
|
2
|
-
import { Button } from "../button/Button";
|
|
3
|
-
import { Icon } from "../icon/Icon";
|
|
4
|
-
import { Loader } from "../loader/Loader";
|
|
5
|
-
import { Select } from "../select/Select";
|
|
6
|
-
import "./dataTable.css";
|
|
7
|
-
import {
|
|
8
|
-
dataTableActionsInterface,
|
|
9
|
-
dataTableColumnsInterface,
|
|
10
|
-
} from "./dataTable.interface";
|
|
11
|
-
export type DataTableProps<T> = {
|
|
12
|
-
id: string;
|
|
13
|
-
name?: string;
|
|
14
|
-
className?: string;
|
|
15
|
-
children?: JSX.Element;
|
|
16
|
-
element?: JSX.Element;
|
|
17
|
-
data: T[];
|
|
18
|
-
emptyMessage?: string;
|
|
19
|
-
actions?: dataTableActionsInterface<T>[];
|
|
20
|
-
columns: dataTableColumnsInterface<T>[];
|
|
21
|
-
loading?: boolean;
|
|
22
|
-
onRowClick?: (row: any) => void;
|
|
23
|
-
onColumnClick?: (column: any) => void;
|
|
24
|
-
onLoadMore?: () => void;
|
|
25
|
-
hasMore?: boolean; // pour savoir s'il reste des données à charger
|
|
26
|
-
};
|
|
27
|
-
export function DataTable<T>(props: DataTableProps<T>) {
|
|
28
|
-
const {
|
|
29
|
-
id,
|
|
30
|
-
name,
|
|
31
|
-
className,
|
|
32
|
-
children,
|
|
33
|
-
element,
|
|
34
|
-
data = [],
|
|
35
|
-
actions = [],
|
|
36
|
-
columns = [],
|
|
37
|
-
loading,
|
|
38
|
-
onRowClick,
|
|
39
|
-
onColumnClick,
|
|
40
|
-
onLoadMore,
|
|
41
|
-
hasMore
|
|
42
|
-
} = props;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const loaderRef = useRef<HTMLDivElement | null>(null);
|
|
46
|
-
|
|
47
|
-
useEffect(() => {
|
|
48
|
-
if (!onLoadMore || !hasMore) return;
|
|
49
|
-
|
|
50
|
-
const observer = new IntersectionObserver(
|
|
51
|
-
(entries) => {
|
|
52
|
-
if (entries[0].isIntersecting) {
|
|
53
|
-
onLoadMore();
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
root: null,
|
|
58
|
-
rootMargin: "0px",
|
|
59
|
-
threshold: 1.0,
|
|
60
|
-
}
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
if (loaderRef.current) {
|
|
64
|
-
observer.observe(loaderRef.current);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return () => {
|
|
68
|
-
if (loaderRef.current) {
|
|
69
|
-
observer.unobserve(loaderRef.current);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
}, [onLoadMore, hasMore]);
|
|
73
|
-
return (
|
|
74
|
-
<div>
|
|
75
|
-
{name && <h2 className="mb-2">{name}</h2>}
|
|
76
|
-
{element}
|
|
77
|
-
<table className={`data-table ${className ? className : ""}`} id={id}>
|
|
78
|
-
<thead>
|
|
79
|
-
<tr>
|
|
80
|
-
{columns.map((column, idx) => (
|
|
81
|
-
<>
|
|
82
|
-
<th
|
|
83
|
-
key={`colonne-${column.id}-${idx}`}
|
|
84
|
-
style={{
|
|
85
|
-
minWidth: column.minWidth,
|
|
86
|
-
maxWidth: column.maxWidth,
|
|
87
|
-
width: column.width,
|
|
88
|
-
textAlign: column.align || "left",
|
|
89
|
-
}}
|
|
90
|
-
onClick={() => onColumnClick?.(column)}
|
|
91
|
-
>
|
|
92
|
-
{column.label}
|
|
93
|
-
</th>
|
|
94
|
-
</>
|
|
95
|
-
))}
|
|
96
|
-
{actions.length > 0 && (
|
|
97
|
-
<th
|
|
98
|
-
style={{
|
|
99
|
-
width: "200px",
|
|
100
|
-
}}
|
|
101
|
-
align="right"
|
|
102
|
-
key={"actions"}
|
|
103
|
-
></th>
|
|
104
|
-
)}
|
|
105
|
-
</tr>
|
|
106
|
-
</thead>
|
|
107
|
-
<tbody>
|
|
108
|
-
{loading ? (
|
|
109
|
-
<tr>
|
|
110
|
-
<td
|
|
111
|
-
align="center"
|
|
112
|
-
colSpan={columns.length + (actions.length > 0 ? 1 : 0)}
|
|
113
|
-
>
|
|
114
|
-
<div className="mt-3">
|
|
115
|
-
<Loader display={loading} />
|
|
116
|
-
</div>
|
|
117
|
-
</td>
|
|
118
|
-
</tr>
|
|
119
|
-
) : (
|
|
120
|
-
<></>
|
|
121
|
-
)}
|
|
122
|
-
{!loading &&
|
|
123
|
-
data.map((row, rowIndex) => (
|
|
124
|
-
<tr key={rowIndex} onClick={() => onRowClick?.(row)}>
|
|
125
|
-
{columns.map((column, idx) => {
|
|
126
|
-
const value = (row as any)[column.id]; // On utilise [column.id] pour accéder aux bonnes propriétés
|
|
127
|
-
return (
|
|
128
|
-
<>
|
|
129
|
-
<td
|
|
130
|
-
style={{
|
|
131
|
-
minWidth: column.minWidth,
|
|
132
|
-
textAlign: column.align || "left",
|
|
133
|
-
maxWidth: column.maxWidth,
|
|
134
|
-
width: column.width,
|
|
135
|
-
}}
|
|
136
|
-
key={`row-${column.id}-${idx}`}
|
|
137
|
-
>
|
|
138
|
-
{column.editable ? (
|
|
139
|
-
column.type === "select" ? (
|
|
140
|
-
<Select
|
|
141
|
-
options={column.options ?? []}
|
|
142
|
-
value={value}
|
|
143
|
-
onChange={(e) => {
|
|
144
|
-
if (column.onEdit) {
|
|
145
|
-
column.onEdit(e, row);
|
|
146
|
-
}
|
|
147
|
-
}}
|
|
148
|
-
/>
|
|
149
|
-
) : (
|
|
150
|
-
<input
|
|
151
|
-
type={column.type}
|
|
152
|
-
value={value}
|
|
153
|
-
step="0.01"
|
|
154
|
-
style={{ textAlign: column.align || "left" }}
|
|
155
|
-
onChange={(e) => {
|
|
156
|
-
if (column.onEdit) {
|
|
157
|
-
column.onEdit(e.target.value, row);
|
|
158
|
-
}
|
|
159
|
-
}}
|
|
160
|
-
/>
|
|
161
|
-
)
|
|
162
|
-
) : column.format ? (
|
|
163
|
-
column.format(value)
|
|
164
|
-
) : (
|
|
165
|
-
value
|
|
166
|
-
)}
|
|
167
|
-
</td>
|
|
168
|
-
</>
|
|
169
|
-
);
|
|
170
|
-
})}
|
|
171
|
-
{actions.length > 0 && (
|
|
172
|
-
<td align="right">
|
|
173
|
-
<div className="d-flex align-items-center justify-content-end">
|
|
174
|
-
{actions.map((action, index) => {
|
|
175
|
-
let title = action.label;
|
|
176
|
-
const display = action.shouldDisplay
|
|
177
|
-
? action.shouldDisplay(row)
|
|
178
|
-
: true;
|
|
179
|
-
if (!display) return null;
|
|
180
|
-
if (action.labelButton) {
|
|
181
|
-
title = action.labelButton
|
|
182
|
-
? action.labelButton(row)
|
|
183
|
-
: action.label;
|
|
184
|
-
}
|
|
185
|
-
return (
|
|
186
|
-
<>
|
|
187
|
-
{action.type === "button" && (
|
|
188
|
-
<Button
|
|
189
|
-
title={title}
|
|
190
|
-
key={`button-action-${action.id}-${index}`}
|
|
191
|
-
onClick={() => action.onClick(row)}
|
|
192
|
-
disabled={action.disabled}
|
|
193
|
-
className={`data-table-action button--tertiary mr-2 w-100 ${
|
|
194
|
-
action.classIcon ? action.classIcon : ""
|
|
195
|
-
}`}
|
|
196
|
-
/>
|
|
197
|
-
)}
|
|
198
|
-
{action.type === "icon" && (
|
|
199
|
-
<div
|
|
200
|
-
key={`icon-action-${action.id}-${index}`}
|
|
201
|
-
className={`mr-2 `}
|
|
202
|
-
onClick={() => action.onClick(row)}
|
|
203
|
-
>
|
|
204
|
-
<Icon
|
|
205
|
-
classIcon={action.classIcon ?? ""}
|
|
206
|
-
key={action.id}
|
|
207
|
-
/>
|
|
208
|
-
</div>
|
|
209
|
-
)}
|
|
210
|
-
</>
|
|
211
|
-
);
|
|
212
|
-
})}
|
|
213
|
-
</div>
|
|
214
|
-
</td>
|
|
215
|
-
)}
|
|
216
|
-
</tr>
|
|
217
|
-
))}
|
|
218
|
-
{!loading && data.length === 0 && (
|
|
219
|
-
<tr>
|
|
220
|
-
<td
|
|
221
|
-
align="center"
|
|
222
|
-
colSpan={columns.length + (actions.length > 0 ? 1 : 0)}
|
|
223
|
-
>
|
|
224
|
-
<div className="mt-3">
|
|
225
|
-
{props.emptyMessage || "Aucune donnée disponible"}
|
|
226
|
-
</div>
|
|
227
|
-
</td>
|
|
228
|
-
</tr>
|
|
229
|
-
)}
|
|
230
|
-
</tbody>
|
|
231
|
-
</table>
|
|
232
|
-
|
|
233
|
-
{children}
|
|
234
|
-
{hasMore && (
|
|
235
|
-
<div ref={loaderRef} className="infinite-scroll-loader">
|
|
236
|
-
<Loader display={true} />
|
|
237
|
-
</div>
|
|
238
|
-
)}
|
|
239
|
-
</div>
|
|
240
|
-
);
|
|
241
|
-
}
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { Button } from "../button/Button";
|
|
3
|
+
import { Icon } from "../icon/Icon";
|
|
4
|
+
import { Loader } from "../loader/Loader";
|
|
5
|
+
import { Select } from "../select/Select";
|
|
6
|
+
import "./dataTable.css";
|
|
7
|
+
import {
|
|
8
|
+
dataTableActionsInterface,
|
|
9
|
+
dataTableColumnsInterface,
|
|
10
|
+
} from "./dataTable.interface";
|
|
11
|
+
export type DataTableProps<T> = {
|
|
12
|
+
id: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
className?: string;
|
|
15
|
+
children?: JSX.Element;
|
|
16
|
+
element?: JSX.Element;
|
|
17
|
+
data: T[];
|
|
18
|
+
emptyMessage?: string;
|
|
19
|
+
actions?: dataTableActionsInterface<T>[];
|
|
20
|
+
columns: dataTableColumnsInterface<T>[];
|
|
21
|
+
loading?: boolean;
|
|
22
|
+
onRowClick?: (row: any) => void;
|
|
23
|
+
onColumnClick?: (column: any) => void;
|
|
24
|
+
onLoadMore?: () => void;
|
|
25
|
+
hasMore?: boolean; // pour savoir s'il reste des données à charger
|
|
26
|
+
};
|
|
27
|
+
export function DataTable<T>(props: DataTableProps<T>) {
|
|
28
|
+
const {
|
|
29
|
+
id,
|
|
30
|
+
name,
|
|
31
|
+
className,
|
|
32
|
+
children,
|
|
33
|
+
element,
|
|
34
|
+
data = [],
|
|
35
|
+
actions = [],
|
|
36
|
+
columns = [],
|
|
37
|
+
loading,
|
|
38
|
+
onRowClick,
|
|
39
|
+
onColumnClick,
|
|
40
|
+
onLoadMore,
|
|
41
|
+
hasMore
|
|
42
|
+
} = props;
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
const loaderRef = useRef<HTMLDivElement | null>(null);
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (!onLoadMore || !hasMore) return;
|
|
49
|
+
|
|
50
|
+
const observer = new IntersectionObserver(
|
|
51
|
+
(entries) => {
|
|
52
|
+
if (entries[0].isIntersecting) {
|
|
53
|
+
onLoadMore();
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
root: null,
|
|
58
|
+
rootMargin: "0px",
|
|
59
|
+
threshold: 1.0,
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
if (loaderRef.current) {
|
|
64
|
+
observer.observe(loaderRef.current);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return () => {
|
|
68
|
+
if (loaderRef.current) {
|
|
69
|
+
observer.unobserve(loaderRef.current);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}, [onLoadMore, hasMore]);
|
|
73
|
+
return (
|
|
74
|
+
<div>
|
|
75
|
+
{name && <h2 className="mb-2">{name}</h2>}
|
|
76
|
+
{element}
|
|
77
|
+
<table className={`data-table ${className ? className : ""}`} id={id}>
|
|
78
|
+
<thead>
|
|
79
|
+
<tr>
|
|
80
|
+
{columns.map((column, idx) => (
|
|
81
|
+
<>
|
|
82
|
+
<th
|
|
83
|
+
key={`colonne-${column.id}-${idx}`}
|
|
84
|
+
style={{
|
|
85
|
+
minWidth: column.minWidth,
|
|
86
|
+
maxWidth: column.maxWidth,
|
|
87
|
+
width: column.width,
|
|
88
|
+
textAlign: column.align || "left",
|
|
89
|
+
}}
|
|
90
|
+
onClick={() => onColumnClick?.(column)}
|
|
91
|
+
>
|
|
92
|
+
{column.label}
|
|
93
|
+
</th>
|
|
94
|
+
</>
|
|
95
|
+
))}
|
|
96
|
+
{actions.length > 0 && (
|
|
97
|
+
<th
|
|
98
|
+
style={{
|
|
99
|
+
width: "200px",
|
|
100
|
+
}}
|
|
101
|
+
align="right"
|
|
102
|
+
key={"actions"}
|
|
103
|
+
></th>
|
|
104
|
+
)}
|
|
105
|
+
</tr>
|
|
106
|
+
</thead>
|
|
107
|
+
<tbody>
|
|
108
|
+
{loading ? (
|
|
109
|
+
<tr>
|
|
110
|
+
<td
|
|
111
|
+
align="center"
|
|
112
|
+
colSpan={columns.length + (actions.length > 0 ? 1 : 0)}
|
|
113
|
+
>
|
|
114
|
+
<div className="mt-3">
|
|
115
|
+
<Loader display={loading} />
|
|
116
|
+
</div>
|
|
117
|
+
</td>
|
|
118
|
+
</tr>
|
|
119
|
+
) : (
|
|
120
|
+
<></>
|
|
121
|
+
)}
|
|
122
|
+
{!loading &&
|
|
123
|
+
data.map((row, rowIndex) => (
|
|
124
|
+
<tr key={rowIndex} onClick={() => onRowClick?.(row)}>
|
|
125
|
+
{columns.map((column, idx) => {
|
|
126
|
+
const value = (row as any)[column.id]; // On utilise [column.id] pour accéder aux bonnes propriétés
|
|
127
|
+
return (
|
|
128
|
+
<>
|
|
129
|
+
<td
|
|
130
|
+
style={{
|
|
131
|
+
minWidth: column.minWidth,
|
|
132
|
+
textAlign: column.align || "left",
|
|
133
|
+
maxWidth: column.maxWidth,
|
|
134
|
+
width: column.width,
|
|
135
|
+
}}
|
|
136
|
+
key={`row-${column.id}-${idx}`}
|
|
137
|
+
>
|
|
138
|
+
{column.editable ? (
|
|
139
|
+
column.type === "select" ? (
|
|
140
|
+
<Select
|
|
141
|
+
options={column.options ?? []}
|
|
142
|
+
value={value}
|
|
143
|
+
onChange={(e) => {
|
|
144
|
+
if (column.onEdit) {
|
|
145
|
+
column.onEdit(e, row);
|
|
146
|
+
}
|
|
147
|
+
}}
|
|
148
|
+
/>
|
|
149
|
+
) : (
|
|
150
|
+
<input
|
|
151
|
+
type={column.type}
|
|
152
|
+
value={value}
|
|
153
|
+
step="0.01"
|
|
154
|
+
style={{ textAlign: column.align || "left" }}
|
|
155
|
+
onChange={(e) => {
|
|
156
|
+
if (column.onEdit) {
|
|
157
|
+
column.onEdit(e.target.value, row);
|
|
158
|
+
}
|
|
159
|
+
}}
|
|
160
|
+
/>
|
|
161
|
+
)
|
|
162
|
+
) : column.format ? (
|
|
163
|
+
column.format(value)
|
|
164
|
+
) : (
|
|
165
|
+
value
|
|
166
|
+
)}
|
|
167
|
+
</td>
|
|
168
|
+
</>
|
|
169
|
+
);
|
|
170
|
+
})}
|
|
171
|
+
{actions.length > 0 && (
|
|
172
|
+
<td align="right">
|
|
173
|
+
<div className="d-flex align-items-center justify-content-end">
|
|
174
|
+
{actions.map((action, index) => {
|
|
175
|
+
let title = action.label;
|
|
176
|
+
const display = action.shouldDisplay
|
|
177
|
+
? action.shouldDisplay(row)
|
|
178
|
+
: true;
|
|
179
|
+
if (!display) return null;
|
|
180
|
+
if (action.labelButton) {
|
|
181
|
+
title = action.labelButton
|
|
182
|
+
? action.labelButton(row)
|
|
183
|
+
: action.label;
|
|
184
|
+
}
|
|
185
|
+
return (
|
|
186
|
+
<>
|
|
187
|
+
{action.type === "button" && (
|
|
188
|
+
<Button
|
|
189
|
+
title={title}
|
|
190
|
+
key={`button-action-${action.id}-${index}`}
|
|
191
|
+
onClick={() => action.onClick(row)}
|
|
192
|
+
disabled={action.disabled}
|
|
193
|
+
className={`data-table-action button--tertiary mr-2 w-100 ${
|
|
194
|
+
action.classIcon ? action.classIcon : ""
|
|
195
|
+
}`}
|
|
196
|
+
/>
|
|
197
|
+
)}
|
|
198
|
+
{action.type === "icon" && (
|
|
199
|
+
<div
|
|
200
|
+
key={`icon-action-${action.id}-${index}`}
|
|
201
|
+
className={`mr-2 `}
|
|
202
|
+
onClick={() => action.onClick(row)}
|
|
203
|
+
>
|
|
204
|
+
<Icon
|
|
205
|
+
classIcon={action.classIcon ?? ""}
|
|
206
|
+
key={action.id}
|
|
207
|
+
/>
|
|
208
|
+
</div>
|
|
209
|
+
)}
|
|
210
|
+
</>
|
|
211
|
+
);
|
|
212
|
+
})}
|
|
213
|
+
</div>
|
|
214
|
+
</td>
|
|
215
|
+
)}
|
|
216
|
+
</tr>
|
|
217
|
+
))}
|
|
218
|
+
{!loading && data.length === 0 && (
|
|
219
|
+
<tr>
|
|
220
|
+
<td
|
|
221
|
+
align="center"
|
|
222
|
+
colSpan={columns.length + (actions.length > 0 ? 1 : 0)}
|
|
223
|
+
>
|
|
224
|
+
<div className="mt-3">
|
|
225
|
+
{props.emptyMessage || "Aucune donnée disponible"}
|
|
226
|
+
</div>
|
|
227
|
+
</td>
|
|
228
|
+
</tr>
|
|
229
|
+
)}
|
|
230
|
+
</tbody>
|
|
231
|
+
</table>
|
|
232
|
+
|
|
233
|
+
{children}
|
|
234
|
+
{hasMore && (
|
|
235
|
+
<div ref={loaderRef} className="infinite-scroll-loader">
|
|
236
|
+
<Loader display={true} />
|
|
237
|
+
</div>
|
|
238
|
+
)}
|
|
239
|
+
</div>
|
|
240
|
+
);
|
|
241
|
+
}
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
2
|
-
import { DataTable } from "./DataTable";
|
|
3
|
-
import { dataTableActionsInterface } from "./dataTable.interface";
|
|
4
|
-
|
|
5
|
-
export const DataTableView = () => {
|
|
6
|
-
const dataTableColumns = useMemo(() => {
|
|
7
|
-
return [
|
|
8
|
-
{ id: "id", label: "ID", minWidth: 50, type: "number" },
|
|
9
|
-
{
|
|
10
|
-
id: "name",
|
|
11
|
-
label: "Name",
|
|
12
|
-
minWidth: 100,
|
|
13
|
-
editable: true,
|
|
14
|
-
type: "text",
|
|
15
|
-
},
|
|
16
|
-
{ id: "age", label: "Age", minWidth: 50, type: "number" },
|
|
17
|
-
];
|
|
18
|
-
}, []);
|
|
19
|
-
const data = useMemo(() => {
|
|
20
|
-
return [
|
|
21
|
-
{ id: 1, name: "John Doe", age: 28 },
|
|
22
|
-
{ id: 2, name: "Jane Smith", age: 34 },
|
|
23
|
-
{ id: 3, name: "Alice Johnson", age: 45 },
|
|
24
|
-
];
|
|
25
|
-
}, []);
|
|
26
|
-
const actions: dataTableActionsInterface<{
|
|
27
|
-
id: number;
|
|
28
|
-
name: string;
|
|
29
|
-
age: number;
|
|
30
|
-
}>[] = useMemo(() => {
|
|
31
|
-
return [
|
|
32
|
-
{
|
|
33
|
-
id: "edit",
|
|
34
|
-
label: "Edit",
|
|
35
|
-
type: "button",
|
|
36
|
-
onClick: (row: any) => {
|
|
37
|
-
console.log("Edit action clicked for row:", row);
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
id: "delete",
|
|
42
|
-
label: "Delete",
|
|
43
|
-
type: "button",
|
|
44
|
-
onClick: (row: any) => {
|
|
45
|
-
console.log("Delete action clicked for row:", row);
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
];
|
|
49
|
-
}, []);
|
|
50
|
-
return (
|
|
51
|
-
<DataTable
|
|
52
|
-
data={data}
|
|
53
|
-
actions={actions}
|
|
54
|
-
columns={dataTableColumns}
|
|
55
|
-
id="datatable-example"
|
|
56
|
-
name={"DataTable"}
|
|
57
|
-
/>
|
|
58
|
-
);
|
|
59
|
-
};
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { DataTable } from "./DataTable";
|
|
3
|
+
import { dataTableActionsInterface } from "./dataTable.interface";
|
|
4
|
+
|
|
5
|
+
export const DataTableView = () => {
|
|
6
|
+
const dataTableColumns = useMemo(() => {
|
|
7
|
+
return [
|
|
8
|
+
{ id: "id", label: "ID", minWidth: 50, type: "number" },
|
|
9
|
+
{
|
|
10
|
+
id: "name",
|
|
11
|
+
label: "Name",
|
|
12
|
+
minWidth: 100,
|
|
13
|
+
editable: true,
|
|
14
|
+
type: "text",
|
|
15
|
+
},
|
|
16
|
+
{ id: "age", label: "Age", minWidth: 50, type: "number" },
|
|
17
|
+
];
|
|
18
|
+
}, []);
|
|
19
|
+
const data = useMemo(() => {
|
|
20
|
+
return [
|
|
21
|
+
{ id: 1, name: "John Doe", age: 28 },
|
|
22
|
+
{ id: 2, name: "Jane Smith", age: 34 },
|
|
23
|
+
{ id: 3, name: "Alice Johnson", age: 45 },
|
|
24
|
+
];
|
|
25
|
+
}, []);
|
|
26
|
+
const actions: dataTableActionsInterface<{
|
|
27
|
+
id: number;
|
|
28
|
+
name: string;
|
|
29
|
+
age: number;
|
|
30
|
+
}>[] = useMemo(() => {
|
|
31
|
+
return [
|
|
32
|
+
{
|
|
33
|
+
id: "edit",
|
|
34
|
+
label: "Edit",
|
|
35
|
+
type: "button",
|
|
36
|
+
onClick: (row: any) => {
|
|
37
|
+
console.log("Edit action clicked for row:", row);
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: "delete",
|
|
42
|
+
label: "Delete",
|
|
43
|
+
type: "button",
|
|
44
|
+
onClick: (row: any) => {
|
|
45
|
+
console.log("Delete action clicked for row:", row);
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
}, []);
|
|
50
|
+
return (
|
|
51
|
+
<DataTable
|
|
52
|
+
data={data}
|
|
53
|
+
actions={actions}
|
|
54
|
+
columns={dataTableColumns}
|
|
55
|
+
id="datatable-example"
|
|
56
|
+
name={"DataTable"}
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
.data-table {
|
|
2
|
-
width: 100%;
|
|
3
|
-
border-spacing: 5px;
|
|
4
|
-
font-size: 14px;
|
|
5
|
-
color: #333;
|
|
6
|
-
|
|
7
|
-
thead {
|
|
8
|
-
margin-bottom: 1rem;
|
|
9
|
-
position : sticky;
|
|
10
|
-
top : 0;
|
|
11
|
-
background-color: #fff;
|
|
12
|
-
th {
|
|
13
|
-
color: #bdbaba;
|
|
14
|
-
min-width: 100px;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
1
|
+
.data-table {
|
|
2
|
+
width: 100%;
|
|
3
|
+
border-spacing: 5px;
|
|
4
|
+
font-size: 14px;
|
|
5
|
+
color: #333;
|
|
6
|
+
|
|
7
|
+
thead {
|
|
8
|
+
margin-bottom: 1rem;
|
|
9
|
+
position : sticky;
|
|
10
|
+
top : 0;
|
|
11
|
+
background-color: #fff;
|
|
12
|
+
th {
|
|
13
|
+
color: #bdbaba;
|
|
14
|
+
min-width: 100px;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|