kelt-ui-kit-react 0.7.4 → 0.7.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/dist/dataTable/DataTable.d.ts +16 -0
- package/dist/dataTable/DataTable.view.d.ts +1 -0
- package/dist/dataTable/dataTable.interface.d.ts +24 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +784 -696
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/App.menu.tsx +8 -0
- package/src/dataTable/DataTable.tsx +135 -0
- package/src/dataTable/DataTable.view.tsx +55 -0
- package/src/dataTable/dataTable.css +12 -0
- package/src/dataTable/dataTable.interface.ts +24 -0
- package/src/index.ts +1 -0
package/package.json
CHANGED
package/src/App.menu.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import { ButtonView } from "./button/Button.view";
|
|
|
5
5
|
import { CardView } from "./card/Card.view";
|
|
6
6
|
import { CarouselView } from "./carousel/Carousel.view";
|
|
7
7
|
import { DamierView } from "./damier/Damier.view";
|
|
8
|
+
import { DataTableView } from "./dataTable/DataTable.view";
|
|
8
9
|
import { ExpandsView } from "./expands/Expands.view";
|
|
9
10
|
import { FilArianeView } from "./filAriane/FilAriane.view";
|
|
10
11
|
import { FormView } from "./form/Form.view";
|
|
@@ -170,6 +171,13 @@ export const MenuList: MenuProps[] = [
|
|
|
170
171
|
children: <NavLink to="/badge">Badge</NavLink>,
|
|
171
172
|
element: <BadgeView />,
|
|
172
173
|
},
|
|
174
|
+
{
|
|
175
|
+
id: 21,
|
|
176
|
+
name: "Data table",
|
|
177
|
+
link: "/data-table",
|
|
178
|
+
children: <NavLink to="/data-table">Data table</NavLink>,
|
|
179
|
+
element: <DataTableView />,
|
|
180
|
+
},
|
|
173
181
|
];
|
|
174
182
|
|
|
175
183
|
export const AppMenu = (): JSX.Element => {
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Button } from "../button/Button";
|
|
2
|
+
import { Icon } from "../icon/Icon";
|
|
3
|
+
import { Loader } from "../loader/Loader";
|
|
4
|
+
import "./dataTable.css";
|
|
5
|
+
import {
|
|
6
|
+
dataTableActionsInterface,
|
|
7
|
+
dataTableColumnsInterface,
|
|
8
|
+
} from "./dataTable.interface";
|
|
9
|
+
export type DataTableProps<T> = {
|
|
10
|
+
id: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
className?: string;
|
|
13
|
+
children?: JSX.Element;
|
|
14
|
+
element?: JSX.Element;
|
|
15
|
+
data: T[];
|
|
16
|
+
actions?: dataTableActionsInterface[];
|
|
17
|
+
columns: dataTableColumnsInterface[];
|
|
18
|
+
loading?: boolean;
|
|
19
|
+
onRowClick?: (row: any) => void;
|
|
20
|
+
onColumnClick?: (column: any) => void;
|
|
21
|
+
};
|
|
22
|
+
export function DataTable<T>(props: DataTableProps<T>) {
|
|
23
|
+
const {
|
|
24
|
+
id,
|
|
25
|
+
name,
|
|
26
|
+
className,
|
|
27
|
+
children,
|
|
28
|
+
element,
|
|
29
|
+
data = [],
|
|
30
|
+
actions = [],
|
|
31
|
+
columns = [],
|
|
32
|
+
loading,
|
|
33
|
+
onRowClick,
|
|
34
|
+
onColumnClick,
|
|
35
|
+
} = props;
|
|
36
|
+
|
|
37
|
+
if (loading) {
|
|
38
|
+
return <Loader display={loading} />;
|
|
39
|
+
}
|
|
40
|
+
return (
|
|
41
|
+
<div>
|
|
42
|
+
{name && <h2 className="mb-2">{name}</h2>}
|
|
43
|
+
{element}
|
|
44
|
+
<table className={`data-table ${className ? className : ""}`} id={id}>
|
|
45
|
+
<thead>
|
|
46
|
+
<tr>
|
|
47
|
+
{columns.map((column) => (
|
|
48
|
+
<>
|
|
49
|
+
<th
|
|
50
|
+
key={column.id}
|
|
51
|
+
style={{
|
|
52
|
+
minWidth: column.minWidth,
|
|
53
|
+
textAlign: column.align || "left",
|
|
54
|
+
}}
|
|
55
|
+
onClick={() => onColumnClick?.(column)}
|
|
56
|
+
>
|
|
57
|
+
{column.label}
|
|
58
|
+
</th>
|
|
59
|
+
</>
|
|
60
|
+
))}
|
|
61
|
+
{actions.length > 0 && <th key={"actions"}></th>}
|
|
62
|
+
</tr>
|
|
63
|
+
</thead>
|
|
64
|
+
<tbody>
|
|
65
|
+
{data.map((row, rowIndex) => (
|
|
66
|
+
<tr key={rowIndex} onClick={() => onRowClick?.(row)}>
|
|
67
|
+
{columns.map((column) => {
|
|
68
|
+
const value = (row as any)[column.id]; // On utilise [column.id] pour accéder aux bonnes propriétés
|
|
69
|
+
return (
|
|
70
|
+
<>
|
|
71
|
+
<td
|
|
72
|
+
key={column.id}
|
|
73
|
+
style={{ textAlign: column.align || "left" }}
|
|
74
|
+
>
|
|
75
|
+
{column.editable ? (
|
|
76
|
+
<input
|
|
77
|
+
type={column.type}
|
|
78
|
+
value={value}
|
|
79
|
+
step="0.01"
|
|
80
|
+
onChange={(e) => {
|
|
81
|
+
if (column.onEdit) {
|
|
82
|
+
column.onEdit(e.target.value);
|
|
83
|
+
}
|
|
84
|
+
}}
|
|
85
|
+
/>
|
|
86
|
+
) : column.format ? (
|
|
87
|
+
column.format(value)
|
|
88
|
+
) : (
|
|
89
|
+
value
|
|
90
|
+
)}
|
|
91
|
+
</td>
|
|
92
|
+
</>
|
|
93
|
+
);
|
|
94
|
+
})}
|
|
95
|
+
{actions.length > 0 && (
|
|
96
|
+
<td>
|
|
97
|
+
<div className="d-flex align-items-center">
|
|
98
|
+
{actions.map((action) => (
|
|
99
|
+
<>
|
|
100
|
+
{action.type === "button" && (
|
|
101
|
+
<Button
|
|
102
|
+
title={action.label}
|
|
103
|
+
key={action.id}
|
|
104
|
+
onClick={() => action.onClick(row)}
|
|
105
|
+
disabled={action.disabled}
|
|
106
|
+
className={`data-table-action mr-2 ${
|
|
107
|
+
action.classIcon ? action.classIcon : ""
|
|
108
|
+
}`}
|
|
109
|
+
/>
|
|
110
|
+
)}
|
|
111
|
+
{action.type === "icon" && (
|
|
112
|
+
<div
|
|
113
|
+
className={`mr-2 `}
|
|
114
|
+
onClick={() => action.onClick(row)}
|
|
115
|
+
>
|
|
116
|
+
<Icon
|
|
117
|
+
classIcon={action.classIcon ?? ""}
|
|
118
|
+
key={action.id}
|
|
119
|
+
/>
|
|
120
|
+
</div>
|
|
121
|
+
)}
|
|
122
|
+
</>
|
|
123
|
+
))}
|
|
124
|
+
</div>
|
|
125
|
+
</td>
|
|
126
|
+
)}
|
|
127
|
+
</tr>
|
|
128
|
+
))}
|
|
129
|
+
</tbody>
|
|
130
|
+
</table>
|
|
131
|
+
|
|
132
|
+
{children}
|
|
133
|
+
</div>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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[] = useMemo(() => {
|
|
27
|
+
return [
|
|
28
|
+
{
|
|
29
|
+
id: "edit",
|
|
30
|
+
label: "Edit",
|
|
31
|
+
type: "button",
|
|
32
|
+
onClick: (row: any) => {
|
|
33
|
+
console.log("Edit action clicked for row:", row);
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: "delete",
|
|
38
|
+
label: "Delete",
|
|
39
|
+
type: "button",
|
|
40
|
+
onClick: (row: any) => {
|
|
41
|
+
console.log("Delete action clicked for row:", row);
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
}, []);
|
|
46
|
+
return (
|
|
47
|
+
<DataTable
|
|
48
|
+
data={data}
|
|
49
|
+
actions={actions}
|
|
50
|
+
columns={dataTableColumns}
|
|
51
|
+
id="datatable-example"
|
|
52
|
+
name={"DataTable"}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { HTMLInputTypeAttribute } from "react";
|
|
2
|
+
|
|
3
|
+
export interface dataTableColumnsInterface {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
minWidth?: number;
|
|
7
|
+
align?: "right" | "left" | "center";
|
|
8
|
+
format?: (value: any) => string;
|
|
9
|
+
sortable?: boolean;
|
|
10
|
+
filterable?: boolean;
|
|
11
|
+
filterValue?: string;
|
|
12
|
+
editable?: boolean;
|
|
13
|
+
onEdit?: (value: any) => void;
|
|
14
|
+
type: HTMLInputTypeAttribute;
|
|
15
|
+
}
|
|
16
|
+
export interface dataTableActionsInterface {
|
|
17
|
+
id: string;
|
|
18
|
+
label: string;
|
|
19
|
+
type: "button" | "link" | "icon";
|
|
20
|
+
classIcon?: string;
|
|
21
|
+
onClick: (row: any) => void;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
visible?: boolean;
|
|
24
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ export { ButtonActions } from "./button/buttonActions/ButtonActions";
|
|
|
8
8
|
export { Card } from "./card/Card";
|
|
9
9
|
export { Carousel } from "./carousel/Carousel";
|
|
10
10
|
export { Damier } from "./damier/Damier";
|
|
11
|
+
export { DataTable } from "./dataTable/DataTable";
|
|
11
12
|
export { Expands } from "./expands/Expands";
|
|
12
13
|
export { FilAriane } from "./filAriane/FilAriane";
|
|
13
14
|
export { DynamicForm } from "./form/Form";
|