kelt-ui-kit-react 2.0.3 → 2.0.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 +26 -0
- package/dist/addressSearch/AddressSearch.d.ts +20 -0
- package/dist/addressSearch/AddressSearch.view.d.ts +1 -0
- package/dist/badge/Badge.d.ts +1 -3
- package/dist/button/Button.d.ts +1 -1
- package/dist/button/button.interface.d.ts +2 -1
- package/dist/card/Card.d.ts +4 -1
- package/dist/dataTable/DataTable.d.ts +14 -17
- package/dist/dataTable/dataTable.interface.d.ts +19 -24
- package/dist/dataTable/dataTableActions/DataTableAction.d.ts +5 -3
- package/dist/dataTable/dataTableColumn/DataTableColumn.d.ts +7 -13
- package/dist/dataTable/dataTableLoading/DataTableLoading.d.ts +3 -1
- package/dist/dataTable/dataTableRow/DataTableRow.d.ts +6 -5
- package/dist/expands/Expands.d.ts +2 -0
- package/dist/expands/expand/expand.d.ts +4 -2
- package/dist/form/Form.d.ts +10 -2
- package/dist/form/form.enum.d.ts +3 -2
- package/dist/form/form.interface.d.ts +22 -3
- package/dist/form/input/Input.d.ts +0 -3
- package/dist/form/inputNumber/InputNumber.d.ts +2 -0
- package/dist/geocoding/GeocodingService.d.ts +13 -0
- package/dist/geocoding/geocoding.interface.d.ts +20 -0
- package/dist/grid/Grid.d.ts +5 -2
- package/dist/grid/col/Col.d.ts +3 -6
- package/dist/grid/col/colStyled/ColStyled.d.ts +8 -5
- package/dist/grid/grid.interface.d.ts +20 -5
- package/dist/grid/row/Row.d.ts +7 -0
- package/dist/header/Header.d.ts +1 -1
- package/dist/header/header.interface.d.ts +2 -1
- package/dist/icon/Icon.d.ts +1 -1
- package/dist/icon/icon.interface.d.ts +0 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +3582 -3484
- package/dist/menus/menu/Menu.d.ts +1 -0
- package/dist/select/Select.d.ts +2 -1
- package/dist/style.css +1 -1
- package/dist/tabs/Tabs.d.ts +1 -2
- package/dist/toaster/store/useToasterStore.d.ts +1 -0
- package/index.html +1 -2
- package/package.json +1 -1
- package/src/App.menu.tsx +8 -0
- package/src/addressSearch/AddressSearch.tsx +246 -0
- package/src/addressSearch/AddressSearch.view.tsx +52 -0
- package/src/addressSearch/addressSearch.css +133 -0
- package/src/badge/Badge.tsx +1 -9
- package/src/badge/badge.css +0 -4
- package/src/button/Button.tsx +3 -1
- package/src/button/button.css +2 -2
- package/src/button/button.interface.tsx +2 -1
- package/src/card/Card.tsx +37 -11
- package/src/card/card.css +7 -28
- package/src/card/cardAction/CardAction.tsx +4 -4
- package/src/damier/Damier.tsx +16 -7
- package/src/damier/damier.css +11 -4
- package/src/dataTable/DataTable.tsx +542 -685
- package/src/dataTable/DataTable.view.tsx +24 -48
- package/src/dataTable/dataTable.css +159 -134
- package/src/dataTable/dataTable.interface.ts +19 -25
- package/src/dataTable/dataTableActions/DataTableAction.tsx +25 -14
- package/src/dataTable/dataTableColumn/DataTableColumn.tsx +14 -64
- package/src/dataTable/dataTableLoading/DataTableLoading.tsx +15 -4
- package/src/dataTable/dataTableRow/DataTableRow.tsx +180 -64
- package/src/expands/Expands.tsx +20 -2
- package/src/expands/expand/expand.tsx +128 -5
- package/src/expands/expands.css +8 -3
- package/src/form/Form.tsx +294 -99
- package/src/form/Form.view.tsx +9 -1
- package/src/form/form.css +64 -1
- package/src/form/form.enum.ts +2 -1
- package/src/form/form.interface.tsx +31 -3
- package/src/form/input/Input.tsx +7 -61
- package/src/form/input/input.css +1 -19
- package/src/form/inputNumber/InputNumber.tsx +11 -6
- package/src/form/inputPrice/InputPrice.tsx +4 -2
- package/src/geocoding/GeocodingService.ts +89 -0
- package/src/geocoding/geocoding.interface.ts +25 -0
- package/src/grid/Grid.tsx +34 -21
- package/src/grid/col/Col.tsx +24 -15
- package/src/grid/col/col.css +3 -0
- package/src/grid/col/colStyled/ColStyled.tsx +59 -41
- package/src/grid/container/container.css +2 -2
- package/src/grid/grid.interface.tsx +25 -5
- package/src/grid/row/Row.tsx +49 -12
- package/src/grid/row/row.css +11 -3
- package/src/header/Header.tsx +4 -2
- package/src/header/header.css +17 -0
- package/src/header/header.interface.tsx +2 -1
- package/src/icon/Icon.tsx +2 -6
- package/src/icon/icon.interface.tsx +0 -1
- package/src/index.css +58 -12
- package/src/index.ts +12 -2
- package/src/menus/Menus.tsx +1 -0
- package/src/menus/menu/Menu.tsx +2 -1
- package/src/select/Select.tsx +5 -3
- package/src/sidebar/Sidebar.tsx +107 -5
- package/src/sidebar/sidebar.css +18 -1
- package/src/tabs/Tabs.tsx +1 -20
- package/src/tabs/tabs.css +9 -3
- package/src/toaster/Toaster.tsx +7 -2
- package/src/toaster/Toaster.view.tsx +1 -0
- package/src/toaster/store/useToasterStore.tsx +2 -0
- package/src/toaster/toaster.css +7 -2
- package/dist/_core/type/generiqueType.d.ts +0 -4
- package/dist/dataTable/dataTableColumn/dataTableColumnFilter/DataTableColumnFilter.d.ts +0 -10
- package/dist/dataTable/dataTableColumn/dataTableColumnFilter/dataTableColumnFilterDate/DataTableColumnFilterDate.d.ts +0 -9
- package/dist/dataTable/dataTableColumn/dataTableColumnFilter/dataTableColumnFilterDateRange/dataTableColumnFilterDateRange.d.ts +0 -9
- package/dist/dataTable/dataTableColumn/dataTableColumnFilter/dataTableColumnFilterEnum/DataTableColumnFilterEnum.d.ts +0 -13
- package/dist/dataTable/dataTableColumn/dataTableColumnFilter/dataTableColumnFilterString/DataTableColumnFilterString.d.ts +0 -9
- package/dist/dataTable/dataTableColumn/dataTableColumnSort/DataTableColumnSort.d.ts +0 -11
- package/dist/dataTable/dataTableFilters/DataTableFilters.d.ts +0 -7
- package/dist/dataTable/dataTableRow/dataTableRowOverlay/DataTableRowOverlay.d.ts +0 -12
- package/dist/dataTable/dataTableRow/dataTableRowValue/DataTableRowValue.d.ts +0 -11
- package/package/package.json +0 -56
- package/package/src/sidebar/Sidebar.tsx +0 -208
- package/package/src/sidebar/sidebar.css +0 -104
- package/src/_core/type/generiqueType.tsx +0 -4
- package/src/dataTable/dataTableColumn/dataTableColumnFilter/DataTableColumnFilter.tsx +0 -36
- package/src/dataTable/dataTableColumn/dataTableColumnFilter/dataTableColumnFilter.css +0 -0
- package/src/dataTable/dataTableColumn/dataTableColumnFilter/dataTableColumnFilterDate/DataTableColumnFilterDate.tsx +0 -39
- package/src/dataTable/dataTableColumn/dataTableColumnFilter/dataTableColumnFilterDateRange/dataTableColumnFilterDateRange.tsx +0 -80
- package/src/dataTable/dataTableColumn/dataTableColumnFilter/dataTableColumnFilterEnum/DataTableColumnFilterEnum.tsx +0 -89
- package/src/dataTable/dataTableColumn/dataTableColumnFilter/dataTableColumnFilterString/DataTableColumnFilterString.tsx +0 -37
- package/src/dataTable/dataTableColumn/dataTableColumnSort/DataTableColumnSort.tsx +0 -42
- package/src/dataTable/dataTableFilters/DataTableFilters.tsx +0 -91
- package/src/dataTable/dataTableFilters/dataTableFilters.css +0 -16
- package/src/dataTable/dataTableRow/dataTableRowOverlay/DataTableRowOverlay.tsx +0 -80
- package/src/dataTable/dataTableRow/dataTableRowValue/DataTableRowValue.tsx +0 -123
|
@@ -1,92 +1,208 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { DataTableRowValue } from "./dataTableRowValue/DataTableRowValue";
|
|
1
|
+
import { Icon } from "../..";
|
|
2
|
+
import { Select } from "../../select/Select";
|
|
3
|
+
import { dataTableColumnsInterface } from "../dataTable.interface";
|
|
5
4
|
|
|
6
5
|
type DataTableRowProps = {
|
|
7
|
-
column:
|
|
6
|
+
column: dataTableColumnsInterface<any>;
|
|
8
7
|
idx: number;
|
|
8
|
+
rowIndex: number;
|
|
9
9
|
row: any;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
container?: "cell" | "card";
|
|
11
|
+
onEnterNextColumn?: (columnIndex: number, rowIndex: number) => void;
|
|
12
12
|
};
|
|
13
13
|
export const DataTableRow = ({
|
|
14
14
|
column,
|
|
15
15
|
idx,
|
|
16
|
+
rowIndex,
|
|
16
17
|
row,
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
container = "cell",
|
|
19
|
+
onEnterNextColumn,
|
|
19
20
|
}: DataTableRowProps) => {
|
|
20
21
|
const value = (row as any)[column.id]; // On utilise [column.id] pour accéder aux bonnes propriétés
|
|
21
22
|
const style = column.onRowStyle ? column.onRowStyle(row) : {};
|
|
22
23
|
const isDisabled = column.onDisable?.(row) ?? false;
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
|
|
25
|
+
const hasStepButtons = Boolean(
|
|
26
|
+
typeof column.showStepButtons === "function"
|
|
27
|
+
? column.showStepButtons(row)
|
|
28
|
+
: (column.showStepButtons ??
|
|
29
|
+
(typeof column.stepControls === "function"
|
|
30
|
+
? column.stepControls(row)
|
|
31
|
+
: (column.stepControls ??
|
|
32
|
+
(typeof column.withStepControls === "function"
|
|
33
|
+
? column.withStepControls(row)
|
|
34
|
+
: column.withStepControls)))),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const handleStep = (direction: "plus" | "minus", e: React.MouseEvent) => {
|
|
38
|
+
e.stopPropagation();
|
|
39
|
+
if (isDisabled) return;
|
|
40
|
+
const currentNum = Number(value) || 0;
|
|
41
|
+
const step = column.step ?? 1;
|
|
42
|
+
let newNum = direction === "plus" ? currentNum + step : currentNum - step;
|
|
43
|
+
if (column.min !== undefined && newNum < column.min) {
|
|
44
|
+
newNum = column.min;
|
|
45
|
+
}
|
|
46
|
+
if (column.max !== undefined && newNum > column.max) {
|
|
47
|
+
newNum = column.max;
|
|
29
48
|
}
|
|
30
|
-
|
|
31
|
-
if (column.
|
|
32
|
-
|
|
33
|
-
column.handleClickCell(e, row);
|
|
34
|
-
}
|
|
35
|
-
e.stopPropagation();
|
|
36
|
-
setOpenClickCell((prev) => !prev);
|
|
49
|
+
newNum = Math.round(newNum * 1000) / 1000;
|
|
50
|
+
if (column.onEdit) {
|
|
51
|
+
column.onEdit(newNum, row);
|
|
37
52
|
}
|
|
38
53
|
};
|
|
54
|
+
|
|
55
|
+
const Container = container === "card" ? "div" : "td";
|
|
56
|
+
|
|
39
57
|
return (
|
|
40
|
-
<
|
|
41
|
-
|
|
58
|
+
<Container
|
|
59
|
+
className={`${isDisabled ? "disabled" : ""}`}
|
|
60
|
+
data-column-index={idx}
|
|
61
|
+
data-row-index={rowIndex}
|
|
42
62
|
style={{
|
|
43
63
|
minWidth: column.minWidth,
|
|
44
|
-
textAlign: column.
|
|
64
|
+
textAlign: column.align || "left",
|
|
45
65
|
maxWidth: column.maxWidth,
|
|
46
66
|
width: column.width,
|
|
47
|
-
...(!isDisabled &&
|
|
48
|
-
(column.openClickCell || column.renderClickCellComponent)
|
|
49
|
-
? { cursor: "pointer" }
|
|
50
|
-
: {}),
|
|
51
|
-
...(isSticky
|
|
52
|
-
? {
|
|
53
|
-
position: "sticky",
|
|
54
|
-
left: stickyLeft,
|
|
55
|
-
zIndex: 2,
|
|
56
|
-
backgroundColor: "#fff",
|
|
57
|
-
}
|
|
58
|
-
: {}),
|
|
59
67
|
...style,
|
|
60
68
|
}}
|
|
61
|
-
onClick={onClickRenderCell}
|
|
62
69
|
key={`row-${column.id}-${idx}`}
|
|
63
|
-
className={isSticky ? "data-table-sticky-cell" : ""}
|
|
64
70
|
>
|
|
65
|
-
{column.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
column={column}
|
|
73
|
-
value={value}
|
|
74
|
-
row={row}
|
|
75
|
-
/>
|
|
76
|
-
)}
|
|
77
|
-
{openClickCell &&
|
|
78
|
-
!isDisabled &&
|
|
79
|
-
column.displayOverlay &&
|
|
80
|
-
refRow.current && (
|
|
81
|
-
<DataTableRowOverlay
|
|
82
|
-
refRow={refRow}
|
|
83
|
-
column={column}
|
|
84
|
-
row={row}
|
|
85
|
-
value={value}
|
|
86
|
-
onEditColumnByOverlay={onEditColumnByOverlay}
|
|
87
|
-
onClose={() => setOpenClickCell(false)}
|
|
71
|
+
{column.type === "image" ? (
|
|
72
|
+
value ? (
|
|
73
|
+
<img
|
|
74
|
+
src={column.imageSrc ? column.imageSrc(row) : ""}
|
|
75
|
+
alt={column.imageAlt ? column.imageAlt(row) : ""}
|
|
76
|
+
style={column.imageStyle}
|
|
88
77
|
/>
|
|
89
|
-
)
|
|
90
|
-
|
|
78
|
+
) : (
|
|
79
|
+
<Icon classIcon="bi-image" />
|
|
80
|
+
)
|
|
81
|
+
) : column.editable ? (
|
|
82
|
+
column.type === "select" ? (
|
|
83
|
+
<div onClick={(e) => e.stopPropagation()}>
|
|
84
|
+
<Select
|
|
85
|
+
style={{
|
|
86
|
+
minWidth: column.minWidth,
|
|
87
|
+
maxWidth: column.maxWidth,
|
|
88
|
+
width: column.width,
|
|
89
|
+
}}
|
|
90
|
+
options={column.options ?? []}
|
|
91
|
+
value={value}
|
|
92
|
+
onChange={(e) => {
|
|
93
|
+
if (column.onEdit) {
|
|
94
|
+
column.onEdit(e, row);
|
|
95
|
+
}
|
|
96
|
+
}}
|
|
97
|
+
/>
|
|
98
|
+
</div>
|
|
99
|
+
) : (
|
|
100
|
+
hasStepButtons ? (
|
|
101
|
+
<div
|
|
102
|
+
className="data-table-input-number-wrapper"
|
|
103
|
+
style={{
|
|
104
|
+
display: "inline-flex",
|
|
105
|
+
alignItems: "center",
|
|
106
|
+
gap: "4px",
|
|
107
|
+
justifyContent:
|
|
108
|
+
column.align === "right"
|
|
109
|
+
? "flex-end"
|
|
110
|
+
: column.align === "center"
|
|
111
|
+
? "center"
|
|
112
|
+
: "flex-start",
|
|
113
|
+
}}
|
|
114
|
+
onClick={(e) => e.stopPropagation()}
|
|
115
|
+
>
|
|
116
|
+
<button
|
|
117
|
+
type="button"
|
|
118
|
+
className="data-table-step-btn data-table-step-btn--minus"
|
|
119
|
+
disabled={
|
|
120
|
+
isDisabled ||
|
|
121
|
+
(column.min !== undefined && Number(value) <= column.min)
|
|
122
|
+
}
|
|
123
|
+
onClick={(e) => handleStep("minus", e)}
|
|
124
|
+
>
|
|
125
|
+
<Icon classIcon="bi-dash-lg" />
|
|
126
|
+
</button>
|
|
127
|
+
<input
|
|
128
|
+
type={column.type}
|
|
129
|
+
value={value}
|
|
130
|
+
step={column.step ?? "0.01"}
|
|
131
|
+
min={column.min}
|
|
132
|
+
max={column.max}
|
|
133
|
+
disabled={isDisabled}
|
|
134
|
+
style={{
|
|
135
|
+
textAlign: column.align || "center",
|
|
136
|
+
minWidth: column.minWidth,
|
|
137
|
+
maxWidth: column.maxWidth,
|
|
138
|
+
width: column.width,
|
|
139
|
+
}}
|
|
140
|
+
onClick={(e) => e.stopPropagation()}
|
|
141
|
+
onKeyDown={(e) => {
|
|
142
|
+
if (e.key === "Enter") {
|
|
143
|
+
if (column.onEnter) {
|
|
144
|
+
column.onEnter(e.currentTarget.value, row);
|
|
145
|
+
}
|
|
146
|
+
if (column.enterToNextColumn) {
|
|
147
|
+
e.preventDefault();
|
|
148
|
+
onEnterNextColumn?.(idx, rowIndex);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}}
|
|
152
|
+
onChange={(e) => {
|
|
153
|
+
if (column.onEdit) {
|
|
154
|
+
column.onEdit(e.target.value, row);
|
|
155
|
+
}
|
|
156
|
+
}}
|
|
157
|
+
/>
|
|
158
|
+
<button
|
|
159
|
+
type="button"
|
|
160
|
+
className="data-table-step-btn data-table-step-btn--plus"
|
|
161
|
+
disabled={
|
|
162
|
+
isDisabled ||
|
|
163
|
+
(column.max !== undefined && Number(value) >= column.max)
|
|
164
|
+
}
|
|
165
|
+
onClick={(e) => handleStep("plus", e)}
|
|
166
|
+
>
|
|
167
|
+
<Icon classIcon="bi-plus-lg" />
|
|
168
|
+
</button>
|
|
169
|
+
</div>
|
|
170
|
+
) : (
|
|
171
|
+
<input
|
|
172
|
+
type={column.type}
|
|
173
|
+
value={value}
|
|
174
|
+
step="0.01"
|
|
175
|
+
style={{
|
|
176
|
+
textAlign: column.align || "left",
|
|
177
|
+
minWidth: column.minWidth,
|
|
178
|
+
maxWidth: column.maxWidth,
|
|
179
|
+
width: column.width,
|
|
180
|
+
}}
|
|
181
|
+
onClick={(e) => e.stopPropagation()}
|
|
182
|
+
onKeyDown={(e) => {
|
|
183
|
+
if (e.key === "Enter") {
|
|
184
|
+
if (column.onEnter) {
|
|
185
|
+
column.onEnter(e.currentTarget.value, row);
|
|
186
|
+
}
|
|
187
|
+
if (column.enterToNextColumn) {
|
|
188
|
+
e.preventDefault();
|
|
189
|
+
onEnterNextColumn?.(idx, rowIndex);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}}
|
|
193
|
+
onChange={(e) => {
|
|
194
|
+
if (column.onEdit) {
|
|
195
|
+
column.onEdit(e.target.value, row);
|
|
196
|
+
}
|
|
197
|
+
}}
|
|
198
|
+
/>
|
|
199
|
+
)
|
|
200
|
+
)
|
|
201
|
+
) : column.format ? (
|
|
202
|
+
column.format(value)
|
|
203
|
+
) : (
|
|
204
|
+
value
|
|
205
|
+
)}
|
|
206
|
+
</Container>
|
|
91
207
|
);
|
|
92
208
|
};
|
package/src/expands/Expands.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
1
2
|
import { Expand } from "./expand/expand";
|
|
2
3
|
import { ExpandInterface } from "./expand/expand.interface";
|
|
3
4
|
import "./expands.css";
|
|
@@ -8,9 +9,24 @@ type ExpandProps = {
|
|
|
8
9
|
onChange?: (item: ExpandInterface) => void;
|
|
9
10
|
currentItem?: ExpandInterface;
|
|
10
11
|
showArrow?: boolean;
|
|
12
|
+
catchfocusCapture?: boolean;
|
|
13
|
+
catchFocusCaptureId?: number;
|
|
11
14
|
};
|
|
12
15
|
|
|
13
16
|
export const Expands = (props: ExpandProps) => {
|
|
17
|
+
const [currentExpand, setCurrentExpand] = useState<ExpandInterface>();
|
|
18
|
+
const onChangeExpand = useCallback(
|
|
19
|
+
(item: ExpandInterface) => {
|
|
20
|
+
if (props.onChange) {
|
|
21
|
+
props.onChange(item);
|
|
22
|
+
}
|
|
23
|
+
setCurrentExpand(item);
|
|
24
|
+
},
|
|
25
|
+
[setCurrentExpand, props.onChange]
|
|
26
|
+
);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
setCurrentExpand(props.currentItem);
|
|
29
|
+
}, [props.currentItem, setCurrentExpand, document.activeElement]);
|
|
14
30
|
return (
|
|
15
31
|
<div className={`expands ${props.className || ""}`}>
|
|
16
32
|
{props.items.map((item: ExpandInterface) => (
|
|
@@ -18,8 +34,10 @@ export const Expands = (props: ExpandProps) => {
|
|
|
18
34
|
key={item.id}
|
|
19
35
|
item={item}
|
|
20
36
|
showArrow={props.showArrow}
|
|
21
|
-
onChange={
|
|
22
|
-
currentExpand={
|
|
37
|
+
onChange={onChangeExpand}
|
|
38
|
+
currentExpand={currentExpand}
|
|
39
|
+
catchfocusCapture={props.catchfocusCapture}
|
|
40
|
+
catchFocusCaptureId={props.catchFocusCaptureId}
|
|
23
41
|
/>
|
|
24
42
|
))}
|
|
25
43
|
</div>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback } from "react";
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
2
|
import { Icon } from "../../icon/Icon";
|
|
3
3
|
import { ExpandInterface } from "./expand.interface";
|
|
4
4
|
|
|
@@ -7,22 +7,143 @@ export type ExpandProps = {
|
|
|
7
7
|
item: ExpandInterface;
|
|
8
8
|
className?: string;
|
|
9
9
|
showArrow?: boolean;
|
|
10
|
-
|
|
10
|
+
catchfocusCapture?: boolean
|
|
11
|
+
catchFocusCaptureId?: number;
|
|
12
|
+
onChange: (item: ExpandInterface) => void;
|
|
11
13
|
};
|
|
12
14
|
export const Expand = ({
|
|
13
15
|
currentExpand,
|
|
14
16
|
item,
|
|
15
17
|
className,
|
|
16
18
|
showArrow = true,
|
|
19
|
+
catchfocusCapture = false,
|
|
20
|
+
catchFocusCaptureId,
|
|
17
21
|
onChange,
|
|
18
22
|
}: ExpandProps): JSX.Element => {
|
|
19
|
-
const active =
|
|
20
|
-
|
|
23
|
+
const [active, setActive] = useState<boolean>(false);
|
|
24
|
+
const expandRef = useRef<HTMLDivElement>(null);
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (item && currentExpand) {
|
|
28
|
+
if (currentExpand.id === item.id) {
|
|
29
|
+
if (!active) {
|
|
30
|
+
setActive(true);
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
setActive(false);
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
setActive(false);
|
|
37
|
+
}
|
|
38
|
+
}, [currentExpand, setActive, item, active]);
|
|
39
|
+
|
|
40
|
+
const scrollToHeader = useCallback(() => {
|
|
41
|
+
const expandElement = expandRef.current;
|
|
42
|
+
if (!expandElement) return;
|
|
43
|
+
|
|
44
|
+
let scrollParent: HTMLElement | null = expandElement.parentElement;
|
|
45
|
+
while (scrollParent) {
|
|
46
|
+
const style = window.getComputedStyle(scrollParent);
|
|
47
|
+
const isScrollable =
|
|
48
|
+
/(auto|scroll)/.test(style.overflow + style.overflowY) &&
|
|
49
|
+
scrollParent.scrollHeight > scrollParent.clientHeight;
|
|
50
|
+
|
|
51
|
+
if (isScrollable) {
|
|
52
|
+
const parentRect = scrollParent.getBoundingClientRect();
|
|
53
|
+
const targetRect = expandElement.getBoundingClientRect();
|
|
54
|
+
const offsetTop =
|
|
55
|
+
targetRect.top - parentRect.top + scrollParent.scrollTop;
|
|
56
|
+
|
|
57
|
+
scrollParent.scrollTo({
|
|
58
|
+
top: offsetTop,
|
|
59
|
+
behavior: "smooth",
|
|
60
|
+
});
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
scrollParent = scrollParent.parentElement;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const header =
|
|
67
|
+
expandElement.querySelector<HTMLElement>(".expand-header") ||
|
|
68
|
+
expandElement;
|
|
69
|
+
header.scrollIntoView({ behavior: "smooth", block: "start" });
|
|
70
|
+
}, []);
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (!catchfocusCapture || catchFocusCaptureId && catchFocusCaptureId !== currentExpand?.id) return;
|
|
74
|
+
if (active) {
|
|
75
|
+
const timer1 = setTimeout(() => {
|
|
76
|
+
scrollToHeader();
|
|
77
|
+
}, 100);
|
|
78
|
+
const timer2 = setTimeout(() => {
|
|
79
|
+
scrollToHeader();
|
|
80
|
+
}, 350);
|
|
81
|
+
return () => {
|
|
82
|
+
clearTimeout(timer1);
|
|
83
|
+
clearTimeout(timer2);
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}, [active, scrollToHeader, catchfocusCapture, catchFocusCaptureId]);
|
|
87
|
+
|
|
88
|
+
const handleFocusCapture = useCallback(
|
|
89
|
+
(e: React.FocusEvent<HTMLDivElement>) => {
|
|
90
|
+
if (!catchfocusCapture || catchFocusCaptureId && catchFocusCaptureId !== currentExpand?.id) return;
|
|
91
|
+
const target = e.target as HTMLElement;
|
|
92
|
+
if (
|
|
93
|
+
active &&
|
|
94
|
+
(target.tagName === "INPUT" ||
|
|
95
|
+
target.tagName === "TEXTAREA" ||
|
|
96
|
+
target.tagName === "SELECT")
|
|
97
|
+
) {
|
|
98
|
+
const expandElement = expandRef.current;
|
|
99
|
+
if (!expandElement) return;
|
|
100
|
+
|
|
101
|
+
const performScroll = () => {
|
|
102
|
+
let scrollParent: HTMLElement | null = expandElement.parentElement;
|
|
103
|
+
while (scrollParent) {
|
|
104
|
+
const style = window.getComputedStyle(scrollParent);
|
|
105
|
+
const isScrollable =
|
|
106
|
+
/(auto|scroll)/.test(style.overflow + style.overflowY) &&
|
|
107
|
+
scrollParent.scrollHeight > scrollParent.clientHeight;
|
|
108
|
+
|
|
109
|
+
if (isScrollable) {
|
|
110
|
+
const parentRect = scrollParent.getBoundingClientRect();
|
|
111
|
+
const headerRect = expandElement.getBoundingClientRect();
|
|
112
|
+
const headerOffsetTop =
|
|
113
|
+
headerRect.top - parentRect.top + scrollParent.scrollTop;
|
|
114
|
+
|
|
115
|
+
// Si on a déjà scrollé vers ou au-delà du header, on ne remonte JAMAIS au header
|
|
116
|
+
if (scrollParent.scrollTop >= headerOffsetTop - 10) {
|
|
117
|
+
const targetRect = target.getBoundingClientRect();
|
|
118
|
+
if (targetRect.bottom > parentRect.bottom) {
|
|
119
|
+
target.scrollIntoView({ behavior: "smooth", block: "nearest" });
|
|
120
|
+
}
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Si on n'a pas encore scrollé jusqu'au header, on y va
|
|
125
|
+
scrollParent.scrollTo({
|
|
126
|
+
top: headerOffsetTop,
|
|
127
|
+
behavior: "smooth",
|
|
128
|
+
});
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
scrollParent = scrollParent.parentElement;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
performScroll();
|
|
136
|
+
// Répéter après l'ouverture du clavier virtuel (spécifique tablettes / mobiles Android)
|
|
137
|
+
setTimeout(performScroll, 300);
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
[active, catchfocusCapture, catchFocusCaptureId],
|
|
141
|
+
);
|
|
142
|
+
|
|
21
143
|
const handleChange = useCallback(
|
|
22
144
|
(e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
|
|
23
145
|
e.stopPropagation();
|
|
24
146
|
if (onChange) {
|
|
25
|
-
console.log("expand", item);
|
|
26
147
|
onChange(item);
|
|
27
148
|
}
|
|
28
149
|
},
|
|
@@ -30,7 +151,9 @@ export const Expand = ({
|
|
|
30
151
|
);
|
|
31
152
|
return (
|
|
32
153
|
<div
|
|
154
|
+
ref={expandRef}
|
|
33
155
|
onClick={handleChange}
|
|
156
|
+
onFocusCapture={handleFocusCapture}
|
|
34
157
|
className={`expand ${active ? "expand--active" : ""} ${className ?? ""}`}
|
|
35
158
|
>
|
|
36
159
|
<div className={`expand-header`}>
|
package/src/expands/expands.css
CHANGED
|
@@ -39,10 +39,12 @@
|
|
|
39
39
|
height: 300px;
|
|
40
40
|
flex: 1;
|
|
41
41
|
min-height: 200px;
|
|
42
|
+
|
|
42
43
|
.expand-header {
|
|
43
|
-
background-color:
|
|
44
|
+
background-color: color-mix(in srgb, var(--primary-color), white 5%);
|
|
44
45
|
color: #fff;
|
|
45
46
|
}
|
|
47
|
+
|
|
46
48
|
.expand-header-custom {
|
|
47
49
|
.expand-header--children {
|
|
48
50
|
display: flex;
|
|
@@ -65,6 +67,7 @@
|
|
|
65
67
|
padding: 15px;
|
|
66
68
|
color: #333;
|
|
67
69
|
background-color: #fff;
|
|
70
|
+
|
|
68
71
|
&.expand-header-custom {
|
|
69
72
|
margin-bottom: 1rem;
|
|
70
73
|
}
|
|
@@ -77,13 +80,15 @@
|
|
|
77
80
|
.expand-header-title-left {
|
|
78
81
|
margin-right: 0.5rem;
|
|
79
82
|
text-transform: uppercase;
|
|
80
|
-
font-size:
|
|
83
|
+
font-size: 18px;
|
|
81
84
|
font-weight: 500;
|
|
82
85
|
}
|
|
83
86
|
}
|
|
87
|
+
|
|
84
88
|
& .expand-footer {
|
|
85
89
|
padding: 15px;
|
|
86
90
|
}
|
|
91
|
+
|
|
87
92
|
& .expand-body {
|
|
88
93
|
display: none;
|
|
89
94
|
flex: 1;
|
|
@@ -94,4 +99,4 @@
|
|
|
94
99
|
flex-direction: column;
|
|
95
100
|
}
|
|
96
101
|
}
|
|
97
|
-
}
|
|
102
|
+
}
|