zuii 1.7.13 → 1.7.14
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.
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useRef as
|
|
3
|
-
import { initSelect as
|
|
4
|
-
import { Icon as
|
|
5
|
-
const
|
|
1
|
+
import { jsxs as q, jsx as I } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as i, useEffect as l } from "react";
|
|
3
|
+
import { initSelect as z } from "../js/select.js";
|
|
4
|
+
import { Icon as $ } from "../../Icon/react/index.js";
|
|
5
|
+
const L = {
|
|
6
6
|
fr: {
|
|
7
7
|
placeholder: "Sélectionnez une option",
|
|
8
8
|
noResultsText: "Aucun résultat trouvé",
|
|
9
9
|
noChoicesText: "Aucun choix disponible",
|
|
10
10
|
uniqueItemText: "Seules les valeurs uniques peuvent être ajoutées",
|
|
11
11
|
customAddItemText: "Seules les valeurs correspondant à un critère spécifique peuvent être ajoutées",
|
|
12
|
-
addItemText: (
|
|
13
|
-
maxItemText: (
|
|
12
|
+
addItemText: (s) => `Appuyez sur Entrée pour ajouter **${s}**`,
|
|
13
|
+
maxItemText: (s) => `Seulement ${s} options peuvent être sélectionnées`
|
|
14
14
|
},
|
|
15
15
|
en: {
|
|
16
16
|
placeholder: "Select an option",
|
|
@@ -18,92 +18,92 @@ const q = {
|
|
|
18
18
|
noChoicesText: "No choices to choose from",
|
|
19
19
|
uniqueItemText: "Only unique values can be added",
|
|
20
20
|
customAddItemText: "Only values matching specific conditions can be added",
|
|
21
|
-
addItemText: (
|
|
22
|
-
maxItemText: (
|
|
21
|
+
addItemText: (s) => `Press Enter to add **${s}**`,
|
|
22
|
+
maxItemText: (s) => `Only ${s} options can be selected`
|
|
23
23
|
}
|
|
24
|
-
},
|
|
25
|
-
required:
|
|
26
|
-
options:
|
|
27
|
-
value:
|
|
24
|
+
}, B = ({
|
|
25
|
+
required: s = !1,
|
|
26
|
+
options: T,
|
|
27
|
+
value: n,
|
|
28
28
|
onChange: a,
|
|
29
|
-
multiple:
|
|
30
|
-
placeholder:
|
|
31
|
-
disabled:
|
|
32
|
-
searchable:
|
|
33
|
-
className:
|
|
29
|
+
multiple: u = !1,
|
|
30
|
+
placeholder: A = "Sélectionnez une option",
|
|
31
|
+
disabled: g = !1,
|
|
32
|
+
searchable: S = !0,
|
|
33
|
+
className: R = "",
|
|
34
34
|
name: N,
|
|
35
|
-
variant:
|
|
36
|
-
icon:
|
|
35
|
+
variant: b = "default",
|
|
36
|
+
icon: v,
|
|
37
37
|
lang: O
|
|
38
38
|
}) => {
|
|
39
|
-
const o =
|
|
40
|
-
|
|
39
|
+
const o = i(null), t = i(null), d = i(a), f = i(n), m = i(!1), E = O || (typeof document < "u" ? document.documentElement.lang : "fr") || "fr", p = L[E.startsWith("en") ? "en" : "fr"], h = A === "Sélectionnez une option" ? p.placeholder : A;
|
|
40
|
+
l(() => {
|
|
41
41
|
d.current = a;
|
|
42
|
-
}, [a]),
|
|
43
|
-
f.current =
|
|
44
|
-
}, [
|
|
45
|
-
const
|
|
46
|
-
return
|
|
42
|
+
}, [a]), l(() => {
|
|
43
|
+
f.current = n;
|
|
44
|
+
}, [n]);
|
|
45
|
+
const V = JSON.stringify(T);
|
|
46
|
+
return l(() => {
|
|
47
47
|
if (o.current) {
|
|
48
48
|
o.current.innerHTML = "";
|
|
49
|
-
const e =
|
|
50
|
-
value:
|
|
51
|
-
label:
|
|
52
|
-
selected: Array.isArray(e) ? e.includes(
|
|
49
|
+
const e = n ?? f.current, c = T.map((r) => ({
|
|
50
|
+
value: r.value,
|
|
51
|
+
label: r.text,
|
|
52
|
+
selected: Array.isArray(e) ? e.includes(r.value) : e === r.value,
|
|
53
53
|
customProperties: {
|
|
54
|
-
flag:
|
|
54
|
+
flag: r.flag
|
|
55
55
|
}
|
|
56
56
|
}));
|
|
57
|
-
|
|
57
|
+
u || c.unshift({
|
|
58
58
|
value: "",
|
|
59
|
-
label:
|
|
59
|
+
label: h,
|
|
60
60
|
selected: e === void 0 || e === "",
|
|
61
61
|
placeholder: !0
|
|
62
|
-
}),
|
|
62
|
+
}), t.current = z(o.current, {
|
|
63
63
|
choices: c,
|
|
64
|
-
removeItemButton:
|
|
65
|
-
placeholderValue:
|
|
66
|
-
searchEnabled:
|
|
64
|
+
removeItemButton: u,
|
|
65
|
+
placeholderValue: h,
|
|
66
|
+
searchEnabled: S,
|
|
67
67
|
silent: !0,
|
|
68
|
-
variant:
|
|
69
|
-
...
|
|
70
|
-
}, (
|
|
71
|
-
f.current =
|
|
68
|
+
variant: b,
|
|
69
|
+
...p
|
|
70
|
+
}, (r) => {
|
|
71
|
+
m.current || (f.current = r, d.current && d.current(r));
|
|
72
72
|
});
|
|
73
73
|
const x = o.current;
|
|
74
74
|
x.hidden = !1;
|
|
75
75
|
}
|
|
76
76
|
return () => {
|
|
77
|
-
|
|
77
|
+
t.current && (t.current.destroy(), t.current = null);
|
|
78
78
|
};
|
|
79
|
-
}, [
|
|
80
|
-
if (
|
|
81
|
-
const e =
|
|
82
|
-
|
|
79
|
+
}, [V, u, h, b, S, p]), l(() => {
|
|
80
|
+
if (t.current && n !== void 0) {
|
|
81
|
+
const e = t.current.getValue(!0), c = Array.isArray(n) ? n : n === null ? [] : [n], x = Array.isArray(e) ? e : [e], r = (j) => JSON.stringify(j.filter((y) => y != null && y !== "").map(String).sort());
|
|
82
|
+
r(c) !== r(x) && (m.current = !0, u && t.current.removeActiveItems(), c.length && t.current.setChoiceByValue(c), m.current = !1);
|
|
83
83
|
}
|
|
84
|
-
}, [
|
|
84
|
+
}, [n]), l(() => {
|
|
85
85
|
const e = o.current?.closest("fieldset");
|
|
86
86
|
if (e) {
|
|
87
87
|
const c = new MutationObserver(() => {
|
|
88
|
-
|
|
88
|
+
t && (e.disabled ? t.current.disable() : t.current.enable());
|
|
89
89
|
});
|
|
90
90
|
return c.observe(e, { attributes: !0 }), () => c.disconnect();
|
|
91
91
|
}
|
|
92
|
-
}, []), /* @__PURE__ */
|
|
93
|
-
|
|
94
|
-
/* @__PURE__ */
|
|
92
|
+
}, []), /* @__PURE__ */ q("div", { className: `form__input ${R}`.trim(), children: [
|
|
93
|
+
v && /* @__PURE__ */ I($, { name: v, size: "sm" }),
|
|
94
|
+
/* @__PURE__ */ I(
|
|
95
95
|
"select",
|
|
96
96
|
{
|
|
97
97
|
ref: o,
|
|
98
|
-
multiple:
|
|
99
|
-
disabled:
|
|
98
|
+
multiple: u,
|
|
99
|
+
disabled: g,
|
|
100
100
|
className: "select",
|
|
101
101
|
name: N,
|
|
102
|
-
required:
|
|
102
|
+
required: s
|
|
103
103
|
}
|
|
104
104
|
)
|
|
105
105
|
] });
|
|
106
106
|
};
|
|
107
107
|
export {
|
|
108
|
-
|
|
108
|
+
B as Select
|
|
109
109
|
};
|