allaw-ui 4.1.2 → 4.1.4

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.
Files changed (32) hide show
  1. package/dist/assets/allaw-font.eot +0 -0
  2. package/dist/assets/allaw-font.svg +3 -2
  3. package/dist/assets/allaw-font.ttf +0 -0
  4. package/dist/assets/allaw-font.woff +0 -0
  5. package/dist/components/atoms/inputs/SearchBar.css +28 -2
  6. package/dist/components/atoms/inputs/SearchBar.d.ts +1 -0
  7. package/dist/components/atoms/inputs/SearchBar.js +11 -3
  8. package/dist/components/atoms/inputs/SearchBar.stories.d.ts +8 -0
  9. package/dist/components/atoms/inputs/SearchBar.stories.js +14 -1
  10. package/dist/components/molecules/contactCard/contactCard.module.css +0 -1
  11. package/dist/components/molecules/proSwitch/AvatarBubble.d.ts +16 -0
  12. package/dist/components/molecules/proSwitch/AvatarBubble.js +72 -0
  13. package/dist/components/molecules/proSwitch/AvatarBubble.stories.d.ts +93 -0
  14. package/dist/components/molecules/proSwitch/AvatarBubble.stories.js +215 -0
  15. package/dist/components/molecules/proSwitch/AvatarToggleGroup.d.ts +21 -0
  16. package/dist/components/molecules/proSwitch/AvatarToggleGroup.js +150 -0
  17. package/dist/components/molecules/proSwitch/AvatarToggleGroup.stories.d.ts +75 -0
  18. package/dist/components/molecules/proSwitch/AvatarToggleGroup.stories.js +276 -0
  19. package/dist/components/molecules/proSwitch/ProSwitch.d.ts +16 -0
  20. package/dist/components/molecules/proSwitch/ProSwitch.js +86 -0
  21. package/dist/components/molecules/proSwitch/ProSwitch.stories.d.ts +9 -0
  22. package/dist/components/molecules/proSwitch/ProSwitch.stories.js +144 -0
  23. package/dist/components/molecules/proSwitch/ProSwitchModal.d.ts +21 -0
  24. package/dist/components/molecules/proSwitch/ProSwitchModal.js +285 -0
  25. package/dist/components/molecules/proSwitch/ProSwitchModal.stories.d.ts +60 -0
  26. package/dist/components/molecules/proSwitch/ProSwitchModal.stories.js +194 -0
  27. package/dist/components/molecules/proSwitch/avatarBubble.module.css +116 -0
  28. package/dist/components/molecules/proSwitch/avatarToggleGroup.module.css +183 -0
  29. package/dist/components/molecules/proSwitch/proSwitch.module.css +32 -0
  30. package/dist/components/molecules/proSwitch/proSwitchModal.module.css +370 -0
  31. package/dist/styles/icons.css +3 -0
  32. package/package.json +4 -1
@@ -0,0 +1,150 @@
1
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
+ if (ar || !(i in from)) {
4
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
+ ar[i] = from[i];
6
+ }
7
+ }
8
+ return to.concat(ar || Array.prototype.slice.call(from));
9
+ };
10
+ import React, { useState, useRef, useEffect, useCallback } from "react";
11
+ import AvatarBubble from "./AvatarBubble";
12
+ import styles from "./avatarToggleGroup.module.css";
13
+ var AvatarToggleGroup = function (_a) {
14
+ var pros = _a.pros, mode = _a.mode, selected = _a.selected, onSelect = _a.onSelect, maxVisible = _a.maxVisible, _b = _a.disabled, disabled = _b === void 0 ? false : _b, onOpenPortal = _a.onOpenPortal, _c = _a.className, className = _c === void 0 ? "" : _c;
15
+ var containerRef = useRef(null);
16
+ var _d = useState(maxVisible || 0), calculatedMaxVisible = _d[0], setCalculatedMaxVisible = _d[1];
17
+ var _e = useState(-1), focusedIndex = _e[0], setFocusedIndex = _e[1];
18
+ // Calcul dynamique de maxVisible
19
+ var calculateMaxVisible = useCallback(function () {
20
+ if (maxVisible !== undefined) {
21
+ setCalculatedMaxVisible(maxVisible);
22
+ return;
23
+ }
24
+ if (!containerRef.current || pros.length === 0) {
25
+ setCalculatedMaxVisible(0);
26
+ return;
27
+ }
28
+ var container = containerRef.current;
29
+ var containerWidth = container.clientWidth - 24; // Padding de 12px de chaque côté
30
+ var avatarDiameter = 42.5; // Taille par défaut
31
+ var overlap = avatarDiameter - 8; // Chevauchement de 8px
32
+ var threshold = 0.66 * avatarDiameter; // 66% de visibilité
33
+ var count = 0;
34
+ while (count < pros.length) {
35
+ var nextAvatarPosition = count * overlap;
36
+ var visibleWidth = containerWidth - nextAvatarPosition;
37
+ if (visibleWidth >= threshold) {
38
+ count++;
39
+ }
40
+ else {
41
+ break;
42
+ }
43
+ }
44
+ setCalculatedMaxVisible(Math.max(0, count));
45
+ }, [maxVisible, pros.length]);
46
+ // Recalculer lors du resize
47
+ useEffect(function () {
48
+ calculateMaxVisible();
49
+ var resizeObserver = new ResizeObserver(function () {
50
+ calculateMaxVisible();
51
+ });
52
+ if (containerRef.current) {
53
+ resizeObserver.observe(containerRef.current);
54
+ }
55
+ return function () {
56
+ resizeObserver.disconnect();
57
+ };
58
+ }, [calculateMaxVisible]);
59
+ // Gestion de la sélection
60
+ var handleAvatarClick = useCallback(function (pro) {
61
+ if (disabled)
62
+ return;
63
+ var newSelected;
64
+ if (mode === "single") {
65
+ // En mode single, on remplace la sélection
66
+ newSelected = [pro.proUserId];
67
+ }
68
+ else {
69
+ // En mode multiple, on toggle
70
+ var isCurrentlySelected = selected.includes(pro.proUserId);
71
+ if (isCurrentlySelected) {
72
+ newSelected = selected.filter(function (id) { return id !== pro.proUserId; });
73
+ }
74
+ else {
75
+ newSelected = __spreadArray(__spreadArray([], selected, true), [pro.proUserId], false);
76
+ }
77
+ }
78
+ // Appeler onSelect avec les objets complets
79
+ var selectedPros = pros.filter(function (pro) {
80
+ return newSelected.includes(pro.proUserId);
81
+ });
82
+ onSelect(selectedPros);
83
+ }, [mode, selected, pros, onSelect, disabled]);
84
+ // Gestion du clavier
85
+ var handleKeyDown = useCallback(function (event) {
86
+ if (disabled)
87
+ return;
88
+ switch (event.key) {
89
+ case "Enter":
90
+ case " ":
91
+ event.preventDefault();
92
+ if (onOpenPortal) {
93
+ onOpenPortal();
94
+ }
95
+ break;
96
+ case "ArrowLeft":
97
+ event.preventDefault();
98
+ setFocusedIndex(function (prev) { return Math.max(-1, prev - 1); });
99
+ break;
100
+ case "ArrowRight":
101
+ event.preventDefault();
102
+ setFocusedIndex(function (prev) {
103
+ return Math.min(calculatedMaxVisible - 1, prev + 1);
104
+ });
105
+ break;
106
+ case "Tab":
107
+ // Laisser le comportement par défaut pour la navigation
108
+ break;
109
+ }
110
+ }, [disabled, onOpenPortal, calculatedMaxVisible]);
111
+ // Navigation clavier globale
112
+ useEffect(function () {
113
+ var handleGlobalKeyDown = function (event) {
114
+ if (disabled)
115
+ return;
116
+ if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
117
+ var container = containerRef.current;
118
+ if (container && container.contains(document.activeElement)) {
119
+ event.preventDefault();
120
+ setFocusedIndex(function (prev) {
121
+ if (event.key === "ArrowLeft") {
122
+ return Math.max(-1, prev - 1);
123
+ }
124
+ else {
125
+ return Math.min(calculatedMaxVisible - 1, prev + 1);
126
+ }
127
+ });
128
+ }
129
+ }
130
+ };
131
+ document.addEventListener("keydown", handleGlobalKeyDown);
132
+ return function () { return document.removeEventListener("keydown", handleGlobalKeyDown); };
133
+ }, [disabled, calculatedMaxVisible]);
134
+ var visiblePros = pros.slice(0, calculatedMaxVisible);
135
+ var hiddenCount = pros.length - calculatedMaxVisible;
136
+ var hasHiddenPros = hiddenCount > 0;
137
+ return (React.createElement("div", { ref: containerRef, className: "".concat(styles.proSwitch, " ").concat(className), role: "group", "aria-label": "S\u00E9lection de professionnels", "data-disabled": disabled },
138
+ React.createElement("div", { className: styles.avatarStack }, visiblePros.map(function (pro, index) {
139
+ var isSelected = selected.includes(pro.proUserId);
140
+ return (React.createElement("div", { key: pro.proUserId, className: styles.avatarWrapper, style: {
141
+ zIndex: isSelected ? 100 : visiblePros.length - index,
142
+ marginLeft: index === 0 ? 0 : -8,
143
+ } },
144
+ React.createElement(AvatarBubble, { firstName: pro.firstName, name: pro.name, src: pro.profilePictureLink, size: 42.5, isSelected: isSelected, disabled: disabled, onClick: function () { return handleAvatarClick(pro); }, alt: "".concat(pro.firstName, " ").concat(pro.name), className: focusedIndex === index ? styles.focused : "" })));
145
+ })),
146
+ hasHiddenPros && (React.createElement("button", { className: styles.moreButton, onClick: onOpenPortal, onKeyDown: handleKeyDown, disabled: disabled, "aria-label": "Voir ".concat(pros.length, " professionnels"), tabIndex: disabled ? -1 : 0 },
147
+ "+",
148
+ hiddenCount))));
149
+ };
150
+ export default AvatarToggleGroup;
@@ -0,0 +1,75 @@
1
+ declare namespace _default {
2
+ export let title: string;
3
+ export { AvatarToggleGroup as component };
4
+ export let tags: string[];
5
+ export namespace argTypes {
6
+ namespace pros {
7
+ let control: string;
8
+ let description: string;
9
+ }
10
+ namespace mode {
11
+ export namespace control_1 {
12
+ let type: string;
13
+ let options: string[];
14
+ }
15
+ export { control_1 as control };
16
+ let description_1: string;
17
+ export { description_1 as description };
18
+ }
19
+ namespace selected {
20
+ let control_2: string;
21
+ export { control_2 as control };
22
+ let description_2: string;
23
+ export { description_2 as description };
24
+ }
25
+ namespace maxVisible {
26
+ export namespace control_3 {
27
+ let type_1: string;
28
+ export { type_1 as type };
29
+ export let min: number;
30
+ export let max: number;
31
+ }
32
+ export { control_3 as control };
33
+ let description_3: string;
34
+ export { description_3 as description };
35
+ }
36
+ namespace disabled {
37
+ let control_4: string;
38
+ export { control_4 as control };
39
+ let description_4: string;
40
+ export { description_4 as description };
41
+ }
42
+ namespace onSelect {
43
+ export let action: string;
44
+ let description_5: string;
45
+ export { description_5 as description };
46
+ }
47
+ namespace onOpenPortal {
48
+ let action_1: string;
49
+ export { action_1 as action };
50
+ let description_6: string;
51
+ export { description_6 as description };
52
+ }
53
+ }
54
+ export namespace parameters {
55
+ namespace backgrounds {
56
+ let _default: string;
57
+ export { _default as default };
58
+ export let values: {
59
+ name: string;
60
+ value: string;
61
+ }[];
62
+ }
63
+ }
64
+ }
65
+ export default _default;
66
+ export const Default: any;
67
+ export const Multiple: any;
68
+ export const WithManyPros: any;
69
+ export const Disabled: any;
70
+ export const WithMaxVisible: any;
71
+ export const SingleWithInitials: any;
72
+ export function ResponsiveTest(): React.JSX.Element;
73
+ export function InteractiveDemo(): React.JSX.Element;
74
+ import AvatarToggleGroup from "./AvatarToggleGroup";
75
+ import React from "react";
@@ -0,0 +1,276 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import React, { useState } from "react";
13
+ import { action } from "@storybook/addon-actions";
14
+ import AvatarToggleGroup from "./AvatarToggleGroup";
15
+ import "../../../styles/global.css";
16
+ export default {
17
+ title: "Components/Molecules/ProSwitch/AvatarToggleGroup",
18
+ component: AvatarToggleGroup,
19
+ tags: ["autodocs"],
20
+ argTypes: {
21
+ pros: {
22
+ control: "object",
23
+ description: "Liste des professionnels à afficher",
24
+ },
25
+ mode: {
26
+ control: {
27
+ type: "select",
28
+ options: ["single", "multiple"],
29
+ },
30
+ description: "Mode de sélection (single ou multiple)",
31
+ },
32
+ selected: {
33
+ control: "object",
34
+ description: "Liste des IDs des pros sélectionnés",
35
+ },
36
+ maxVisible: {
37
+ control: {
38
+ type: "number",
39
+ min: 1,
40
+ max: 10,
41
+ },
42
+ description: "Nombre maximum d'avatars visibles (optionnel)",
43
+ },
44
+ disabled: {
45
+ control: "boolean",
46
+ description: "État désactivé",
47
+ },
48
+ onSelect: {
49
+ action: "selected",
50
+ description: "Callback appelé lors de la sélection",
51
+ },
52
+ onOpenPortal: {
53
+ action: "portal opened",
54
+ description: "Callback appelé à l'ouverture de la modal",
55
+ },
56
+ },
57
+ parameters: {
58
+ backgrounds: {
59
+ default: "light",
60
+ values: [
61
+ { name: "light", value: "#ffffff" },
62
+ { name: "grey", value: "#728ea7" },
63
+ { name: "figma", value: "#404040" },
64
+ { name: "dark", value: "#171e25" },
65
+ ],
66
+ },
67
+ },
68
+ };
69
+ // Données de test
70
+ var samplePros = [
71
+ {
72
+ token: "t1",
73
+ proUserId: "1",
74
+ name: "Dupont",
75
+ firstName: "Jean",
76
+ profilePictureLink: "https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?w=150&h=150&fit=crop&crop=face",
77
+ profession: "AVOCAT",
78
+ },
79
+ {
80
+ token: "t2",
81
+ proUserId: "2",
82
+ name: "Martin",
83
+ firstName: "Marie",
84
+ profilePictureLink: "https://images.unsplash.com/photo-1494790108755-2616b612b786?w=150&h=150&fit=crop&crop=face",
85
+ profession: "NOTAIRE",
86
+ },
87
+ {
88
+ token: "t3",
89
+ proUserId: "3",
90
+ name: "Durand",
91
+ firstName: "Pierre",
92
+ profilePictureLink: "https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=150&h=150&fit=crop&crop=face",
93
+ profession: "AVOCAT",
94
+ },
95
+ {
96
+ token: "t4",
97
+ proUserId: "4",
98
+ name: "Bernard",
99
+ firstName: "Sophie",
100
+ profilePictureLink: "https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=150&h=150&fit=crop&crop=face",
101
+ profession: "COMMISSAIRE",
102
+ },
103
+ {
104
+ token: "t5",
105
+ proUserId: "5",
106
+ name: "Petit",
107
+ firstName: "Lucas",
108
+ profilePictureLink: "https://images.unsplash.com/photo-1500648767791-00dcc994a43e?w=150&h=150&fit=crop&crop=face",
109
+ profession: "AVOCAT",
110
+ },
111
+ {
112
+ token: "t6",
113
+ proUserId: "6",
114
+ name: "Rousseau",
115
+ firstName: "Emma",
116
+ profilePictureLink: "https://images.unsplash.com/photo-1502823403499-6ccfcf4fb453?w=150&h=150&fit=crop&crop=face",
117
+ profession: "NOTAIRE",
118
+ },
119
+ {
120
+ token: "t7",
121
+ proUserId: "7",
122
+ name: "Leroy",
123
+ firstName: "François",
124
+ profilePictureLink: "https://images.unsplash.com/photo-1506794778202-cad84cf45f1d?w=150&h=150&fit=crop&crop=face",
125
+ profession: "AVOCAT",
126
+ },
127
+ {
128
+ token: "t8",
129
+ proUserId: "8",
130
+ name: "Moreau",
131
+ firstName: "Alice",
132
+ profilePictureLink: "https://images.unsplash.com/photo-1544005313-94ddf0286df2?w=150&h=150&fit=crop&crop=face",
133
+ profession: "COMMISSAIRE",
134
+ },
135
+ ];
136
+ var Template = function (args) {
137
+ var _a = useState(args.selected || []), selected = _a[0], setSelected = _a[1];
138
+ var handleSelect = function (selectedPros) {
139
+ setSelected(selectedPros.map(function (pro) { return pro.proUserId; }));
140
+ action("onSelect")(selectedPros);
141
+ };
142
+ return (React.createElement("div", { style: { padding: "20px", maxWidth: "600px" } },
143
+ React.createElement(AvatarToggleGroup, __assign({}, args, { selected: selected, onSelect: handleSelect })),
144
+ React.createElement("div", { style: { marginTop: "20px", fontSize: "14px", color: "#666" } },
145
+ React.createElement("strong", null, "S\u00E9lection actuelle :"),
146
+ " ",
147
+ selected.join(", ") || "Aucune")));
148
+ };
149
+ export var Default = Template.bind({});
150
+ Default.args = {
151
+ pros: samplePros.slice(0, 3),
152
+ mode: "single",
153
+ selected: ["1"],
154
+ disabled: false,
155
+ };
156
+ export var Multiple = Template.bind({});
157
+ Multiple.args = {
158
+ pros: samplePros.slice(0, 4),
159
+ mode: "multiple",
160
+ selected: ["1", "3"],
161
+ disabled: false,
162
+ };
163
+ export var WithManyPros = Template.bind({});
164
+ WithManyPros.args = {
165
+ pros: samplePros,
166
+ mode: "multiple",
167
+ selected: ["1", "3", "5"],
168
+ disabled: false,
169
+ };
170
+ export var Disabled = Template.bind({});
171
+ Disabled.args = {
172
+ pros: samplePros.slice(0, 3),
173
+ mode: "single",
174
+ selected: ["1"],
175
+ disabled: true,
176
+ };
177
+ export var WithMaxVisible = Template.bind({});
178
+ WithMaxVisible.args = {
179
+ pros: samplePros,
180
+ mode: "multiple",
181
+ selected: ["1", "2"],
182
+ maxVisible: 3,
183
+ disabled: false,
184
+ };
185
+ export var SingleWithInitials = Template.bind({});
186
+ SingleWithInitials.args = {
187
+ pros: [
188
+ {
189
+ token: "t1",
190
+ proUserId: "1",
191
+ name: "Dupont",
192
+ firstName: "Jean",
193
+ profilePictureLink: "", // Pas d'image pour forcer les initiales
194
+ profession: "AVOCAT",
195
+ },
196
+ {
197
+ token: "t2",
198
+ proUserId: "2",
199
+ name: "Martin",
200
+ firstName: "Marie",
201
+ profilePictureLink: "",
202
+ profession: "NOTAIRE",
203
+ },
204
+ {
205
+ token: "t3",
206
+ proUserId: "3",
207
+ name: "Durand",
208
+ firstName: "Pierre",
209
+ profilePictureLink: "",
210
+ profession: "AVOCAT",
211
+ },
212
+ ],
213
+ mode: "single",
214
+ selected: ["1"],
215
+ disabled: false,
216
+ };
217
+ export var ResponsiveTest = function () {
218
+ var _a = useState(["1"]), selected = _a[0], setSelected = _a[1];
219
+ var handleSelect = function (selectedPros) {
220
+ setSelected(selectedPros.map(function (pro) { return pro.proUserId; }));
221
+ action("onSelect")(selectedPros);
222
+ };
223
+ return (React.createElement("div", { style: { padding: "20px" } },
224
+ React.createElement("h3", { style: { marginBottom: "20px" } }, "Test Responsive - Redimensionnez la fen\u00EAtre"),
225
+ React.createElement("div", { style: {
226
+ border: "1px solid #ccc",
227
+ padding: "20px",
228
+ marginBottom: "20px",
229
+ maxWidth: "100%",
230
+ overflow: "hidden",
231
+ } },
232
+ React.createElement(AvatarToggleGroup, { pros: samplePros, mode: "multiple", selected: selected, onSelect: handleSelect, onOpenPortal: function () { return action("Portal opened")(); } })),
233
+ React.createElement("div", { style: { fontSize: "14px", color: "#666" } },
234
+ React.createElement("strong", null, "S\u00E9lection :"),
235
+ " ",
236
+ selected.join(", ") || "Aucune")));
237
+ };
238
+ export var InteractiveDemo = function () {
239
+ var _a = useState("single"), mode = _a[0], setMode = _a[1];
240
+ var _b = useState(["1"]), selected = _b[0], setSelected = _b[1];
241
+ var _c = useState(false), disabled = _c[0], setDisabled = _c[1];
242
+ var handleSelect = function (selectedPros) {
243
+ setSelected(selectedPros.map(function (pro) { return pro.proUserId; }));
244
+ action("onSelect")(selectedPros);
245
+ };
246
+ return (React.createElement("div", { style: { padding: "20px" } },
247
+ React.createElement("div", { style: {
248
+ marginBottom: "20px",
249
+ display: "flex",
250
+ gap: "20px",
251
+ alignItems: "center",
252
+ } },
253
+ React.createElement("label", null,
254
+ React.createElement("input", { type: "radio", name: "mode", value: "single", checked: mode === "single", onChange: function (e) { return setMode(e.target.value); } }),
255
+ "Single"),
256
+ React.createElement("label", null,
257
+ React.createElement("input", { type: "radio", name: "mode", value: "multiple", checked: mode === "multiple", onChange: function (e) { return setMode(e.target.value); } }),
258
+ "Multiple"),
259
+ React.createElement("label", null,
260
+ React.createElement("input", { type: "checkbox", checked: disabled, onChange: function (e) { return setDisabled(e.target.checked); } }),
261
+ "Disabled")),
262
+ React.createElement("div", { style: {
263
+ border: "1px solid #ccc",
264
+ padding: "20px",
265
+ marginBottom: "20px",
266
+ } },
267
+ React.createElement(AvatarToggleGroup, { pros: samplePros.slice(0, 5), mode: mode, selected: selected, onSelect: handleSelect, disabled: disabled, onOpenPortal: function () { return action("Portal opened")(); } })),
268
+ React.createElement("div", { style: { fontSize: "14px", color: "#666" } },
269
+ React.createElement("strong", null, "Mode :"),
270
+ " ",
271
+ mode,
272
+ " | ",
273
+ React.createElement("strong", null, "S\u00E9lection :"),
274
+ " ",
275
+ selected.join(", ") || "Aucune")));
276
+ };
@@ -0,0 +1,16 @@
1
+ import React from "react";
2
+ import { Pro } from "./AvatarToggleGroup";
3
+ interface ProSwitchProps {
4
+ pros: Pro[];
5
+ selected: string[];
6
+ mode: "single" | "multiple";
7
+ disabled?: boolean;
8
+ maxVisible?: number;
9
+ onSelect?: (selected: Pro[]) => void;
10
+ onOrderChange?: (ordered: Pro[]) => void;
11
+ onOpenPortal?: () => void;
12
+ onClosePortal?: () => void;
13
+ className?: string;
14
+ }
15
+ declare const ProSwitch: React.FC<ProSwitchProps>;
16
+ export default ProSwitch;
@@ -0,0 +1,86 @@
1
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
+ if (ar || !(i in from)) {
4
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
+ ar[i] = from[i];
6
+ }
7
+ }
8
+ return to.concat(ar || Array.prototype.slice.call(from));
9
+ };
10
+ import React, { useEffect, useRef, useState, useCallback } from "react";
11
+ import AvatarToggleGroup from "./AvatarToggleGroup";
12
+ import ProSwitchModal from "./ProSwitchModal";
13
+ import styles from "./proSwitch.module.css";
14
+ var LOCALSTORAGE_KEY = "allaw.proSwitch.order";
15
+ var ProSwitch = function (_a) {
16
+ var _b = _a.pros, pros = _b === void 0 ? [] : _b, _c = _a.selected, selected = _c === void 0 ? [] : _c, mode = _a.mode, _d = _a.disabled, disabled = _d === void 0 ? false : _d, maxVisible = _a.maxVisible, onSelect = _a.onSelect, onOrderChange = _a.onOrderChange, onOpenPortal = _a.onOpenPortal, onClosePortal = _a.onClosePortal, _e = _a.className, className = _e === void 0 ? "" : _e;
17
+ var containerRef = useRef(null);
18
+ var _f = useState([]), order = _f[0], setOrder = _f[1];
19
+ var _g = useState(selected), selectedIds = _g[0], setSelectedIds = _g[1];
20
+ var _h = useState(false), modalOpen = _h[0], setModalOpen = _h[1];
21
+ // Initialisation de l'ordre depuis localStorage ou props
22
+ useEffect(function () {
23
+ var initialOrder = pros.map(function (p) { return p.proUserId; });
24
+ try {
25
+ var stored = localStorage.getItem(LOCALSTORAGE_KEY);
26
+ if (stored) {
27
+ var arr = JSON.parse(stored);
28
+ // Ne garder que les ids présents dans pros
29
+ initialOrder = arr.filter(function (id) { return pros.some(function (p) { return p.proUserId === id; }); });
30
+ // Ajouter les nouveaux ids non présents dans le storage
31
+ initialOrder = __spreadArray(__spreadArray([], initialOrder, true), pros
32
+ .map(function (p) { return p.proUserId; })
33
+ .filter(function (id) { return !initialOrder.includes(id); }), true);
34
+ }
35
+ }
36
+ catch (_a) {
37
+ // Fallback : ordre par défaut
38
+ }
39
+ setOrder(initialOrder);
40
+ }, [pros]);
41
+ // Sync selectedIds si props.selected change
42
+ useEffect(function () {
43
+ setSelectedIds(selected);
44
+ }, [selected]);
45
+ // Gestion de la sélection
46
+ var handleSelect = useCallback(function (selectedPros) {
47
+ setSelectedIds(selectedPros.map(function (p) { return p.proUserId; }));
48
+ if (onSelect)
49
+ onSelect(selectedPros);
50
+ }, [onSelect]);
51
+ // Gestion de l'ouverture de la modal
52
+ var handleOpenModal = useCallback(function () {
53
+ setModalOpen(true);
54
+ if (onOpenPortal)
55
+ onOpenPortal();
56
+ }, [onOpenPortal]);
57
+ // Gestion de la fermeture de la modal
58
+ var handleCloseModal = useCallback(function () {
59
+ setModalOpen(false);
60
+ if (onClosePortal)
61
+ onClosePortal();
62
+ }, [onClosePortal]);
63
+ // Gestion du réordonnancement
64
+ var handleOrderChange = useCallback(function (orderedPros) {
65
+ var newOrder = orderedPros.map(function (p) { return p.proUserId; });
66
+ setOrder(newOrder);
67
+ try {
68
+ localStorage.setItem(LOCALSTORAGE_KEY, JSON.stringify(newOrder));
69
+ }
70
+ catch (_a) { }
71
+ if (onOrderChange)
72
+ onOrderChange(orderedPros);
73
+ }, [onOrderChange]);
74
+ // Pros ordonnés
75
+ var orderedPros = order
76
+ .map(function (id) { return pros.find(function (p) { return p.proUserId === id; }); })
77
+ .filter(Boolean);
78
+ // Fallback si aucun pro
79
+ if (!pros || pros.length === 0) {
80
+ return (React.createElement("div", { className: styles.proSwitchEmpty }, "Aucun professionnel disponible"));
81
+ }
82
+ return (React.createElement("div", { className: "".concat(styles.proSwitchContainer, " ").concat(className), ref: containerRef },
83
+ React.createElement(AvatarToggleGroup, { pros: orderedPros, mode: mode, selected: selectedIds, onSelect: handleSelect, onOpenPortal: handleOpenModal, disabled: disabled, maxVisible: maxVisible, className: styles.avatarToggleGroup }),
84
+ modalOpen && (React.createElement(ProSwitchModal, { open: modalOpen, pros: orderedPros, selected: selectedIds, mode: mode, onClosePortal: handleCloseModal, onOpenPortal: onOpenPortal, onOrderChange: handleOrderChange, onSelect: handleSelect }))));
85
+ };
86
+ export default ProSwitch;
@@ -0,0 +1,9 @@
1
+ declare namespace _default {
2
+ export let title: string;
3
+ export { ProSwitch as component };
4
+ }
5
+ export default _default;
6
+ export function SingleSelect(): React.JSX.Element;
7
+ export function MultiSelectOverflow(): React.JSX.Element;
8
+ import ProSwitch from "./ProSwitch";
9
+ import React from "react";