@situaction/traq-ui-ste 1.2.13 → 1.2.16
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/X.es-BEJ-zMPl.mjs +146 -0
- package/dist/components/button/Button.js +36 -36
- package/dist/components/calendar/Calendar.js +210 -214
- package/dist/components/carousel/Carousel.d.ts +33 -0
- package/dist/components/carousel/Carousel.js +328 -0
- package/dist/components/drag-and-drop/DragAndDrop.d.ts +31 -0
- package/dist/components/drag-and-drop/DragAndDrop.js +143 -0
- package/dist/components/icon/Icon.js +23729 -46405
- package/dist/components/icon-button/IconButton.js +27 -27
- package/dist/components/input/Input.js +49 -49
- package/dist/components/list/list-controls/ListControls.js +9 -8
- package/dist/components/list/nested-list/NestedList.js +6 -5
- package/dist/components/list/nested-list/item/NestedListItem.js +3 -2
- package/dist/components/loading/Loading.d.ts +38 -0
- package/dist/components/loading/Loading.js +87 -0
- package/dist/components/menu/Menu.js +61 -63
- package/dist/components/panel/side-panel/SidePanel.js +18 -19
- package/dist/components/panel/side-panel-header/SidePanelHeader.js +3 -2
- package/dist/components/select/Select.js +68 -69
- package/dist/components/select-filter-input-tags/SelectFilterInputTags.js +11 -11
- package/dist/components/select-multi-items/SelectMultiItems.js +19 -18
- package/dist/components/switch/Switch.js +11 -10
- package/dist/components/tag/Tag.js +25 -25
- package/dist/components/theme/variables_dark.d.ts +11 -0
- package/dist/components/theme/variables_dark.js +12 -1
- package/dist/components/theme/variables_light.d.ts +11 -0
- package/dist/components/theme/variables_light.js +12 -1
- package/dist/components/toast/Toast.js +38 -38
- package/dist/main.d.ts +3 -0
- package/dist/main.js +33 -27
- package/dist/styles/Button.css +1 -1
- package/dist/styles/Carousel.css +1 -0
- package/dist/styles/DragAndDrop.css +1 -0
- package/dist/styles/IconButton.css +1 -1
- package/dist/styles/Input.css +1 -1
- package/dist/styles/Loading.css +1 -0
- package/dist/styles/Tag.css +1 -1
- package/dist/styles/Toast.css +1 -1
- package/package.json +1 -1
- package/dist/X-Bd1VjKAF.mjs +0 -190
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { default as React, CSSProperties, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export type CarouselAlign = "start" | "center";
|
|
4
|
+
export interface CarouselRef {
|
|
5
|
+
next: () => void;
|
|
6
|
+
prev: () => void;
|
|
7
|
+
goTo: (index: number, behavior?: ScrollBehavior) => void;
|
|
8
|
+
getIndex: () => number;
|
|
9
|
+
getLength: () => number;
|
|
10
|
+
}
|
|
11
|
+
export interface CarouselProps {
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
className?: string;
|
|
14
|
+
viewportClassName?: string;
|
|
15
|
+
slideClassName?: string;
|
|
16
|
+
style?: CSSProperties;
|
|
17
|
+
slideSize?: string;
|
|
18
|
+
gap?: number;
|
|
19
|
+
align?: CarouselAlign;
|
|
20
|
+
showArrows?: boolean;
|
|
21
|
+
dragEnabled?: boolean;
|
|
22
|
+
snapOnRelease?: boolean;
|
|
23
|
+
keyboardNavigation?: boolean;
|
|
24
|
+
step?: number;
|
|
25
|
+
initialIndex?: number;
|
|
26
|
+
/** Loop infini (boutons + drag + wheel/trackpad) */
|
|
27
|
+
loop?: boolean;
|
|
28
|
+
ariaLabel?: string;
|
|
29
|
+
iconLeft?: ReactNode;
|
|
30
|
+
iconRight?: ReactNode;
|
|
31
|
+
onIndexChange?: (index: number) => void;
|
|
32
|
+
}
|
|
33
|
+
export declare const Carousel: React.ForwardRefExoticComponent<CarouselProps & React.RefAttributes<CarouselRef>>;
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { jsxs as ae, jsx as I, Fragment as We } from "react/jsx-runtime";
|
|
2
|
+
import ze, { forwardRef as Ee, useMemo as ie, useRef as l, useState as q, useCallback as i, useImperativeHandle as Fe, useEffect as Y } from "react";
|
|
3
|
+
import '../../styles/Carousel.css';const Be = "_root_1kths_1", $e = "_viewport_1kths_6", qe = "_dragEnabled_1kths_22", je = "_dragging_1kths_27", Oe = "_slide_1kths_34", Xe = "_navButton_1kths_41", He = "_navPrev_1kths_63", Ve = "_navNext_1kths_67", d = {
|
|
4
|
+
root: Be,
|
|
5
|
+
viewport: $e,
|
|
6
|
+
dragEnabled: qe,
|
|
7
|
+
dragging: je,
|
|
8
|
+
slide: Oe,
|
|
9
|
+
navButton: Xe,
|
|
10
|
+
navPrev: He,
|
|
11
|
+
navNext: Ve
|
|
12
|
+
}, C = (...M) => M.filter(Boolean).join(" "), Ye = Ee(
|
|
13
|
+
({
|
|
14
|
+
children: M,
|
|
15
|
+
className: ue,
|
|
16
|
+
viewportClassName: le,
|
|
17
|
+
slideClassName: fe,
|
|
18
|
+
style: de,
|
|
19
|
+
slideSize: pe = "30%",
|
|
20
|
+
gap: ve = 12,
|
|
21
|
+
align: h = "center",
|
|
22
|
+
showArrows: me = !0,
|
|
23
|
+
dragEnabled: R = !0,
|
|
24
|
+
snapOnRelease: G = !0,
|
|
25
|
+
keyboardNavigation: he = !0,
|
|
26
|
+
step: we = 1,
|
|
27
|
+
initialIndex: J = 0,
|
|
28
|
+
loop: y = !1,
|
|
29
|
+
ariaLabel: Q = "Carousel",
|
|
30
|
+
iconLeft: ge,
|
|
31
|
+
iconRight: xe,
|
|
32
|
+
onIndexChange: A
|
|
33
|
+
}, _e) => {
|
|
34
|
+
const w = ie(() => ze.Children.toArray(M), [M]), s = w.length, c = y && s > 1, T = Math.max(1, Math.min(we, Math.max(1, s))), p = c ? s : 0, g = ie(() => {
|
|
35
|
+
if (!c)
|
|
36
|
+
return w.map((n, o) => ({
|
|
37
|
+
key: `real-${o}`,
|
|
38
|
+
node: n,
|
|
39
|
+
realIndex: o,
|
|
40
|
+
isClone: !1
|
|
41
|
+
}));
|
|
42
|
+
const e = w.map((n, o) => ({
|
|
43
|
+
key: `clone-head-${o}`,
|
|
44
|
+
node: n,
|
|
45
|
+
realIndex: o,
|
|
46
|
+
isClone: !0
|
|
47
|
+
})), t = w.map((n, o) => ({
|
|
48
|
+
key: `real-${o}`,
|
|
49
|
+
node: n,
|
|
50
|
+
realIndex: o,
|
|
51
|
+
isClone: !1
|
|
52
|
+
})), r = w.map((n, o) => ({
|
|
53
|
+
key: `clone-tail-${o}`,
|
|
54
|
+
node: n,
|
|
55
|
+
realIndex: o,
|
|
56
|
+
isClone: !0
|
|
57
|
+
}));
|
|
58
|
+
return [...e, ...t, ...r];
|
|
59
|
+
}, [c, w]), j = g.length, a = l(null), x = l([]), [Le, be] = q(0), N = l(0), [ke, Z] = q(!1), [Ie, ee] = q(!1), _ = l(!1), te = l(0), O = l(0), X = l(!1), H = l(!1), [Re, re] = q(!1), v = i(
|
|
60
|
+
(e) => {
|
|
61
|
+
N.current = e, be(e), A == null || A(e);
|
|
62
|
+
},
|
|
63
|
+
[A]
|
|
64
|
+
), ne = i((e) => {
|
|
65
|
+
const t = a.current;
|
|
66
|
+
t && (t.style.scrollSnapType = e ? "x mandatory" : "none", t.style.scrollBehavior = e ? "smooth" : "auto");
|
|
67
|
+
}, []), P = i(
|
|
68
|
+
(e, t) => h === "center" ? t.offsetLeft - (e.clientWidth - t.offsetWidth) / 2 : t.offsetLeft,
|
|
69
|
+
[h]
|
|
70
|
+
), L = i(
|
|
71
|
+
(e, t = "smooth") => {
|
|
72
|
+
const r = a.current, n = x.current[e];
|
|
73
|
+
if (!r || !n) return;
|
|
74
|
+
const o = P(r, n);
|
|
75
|
+
r.scrollTo({ left: o, behavior: t });
|
|
76
|
+
},
|
|
77
|
+
[P]
|
|
78
|
+
), D = i(
|
|
79
|
+
(e) => s === 0 ? 0 : y ? (e % s + s) % s : Math.max(0, Math.min(s - 1, e)),
|
|
80
|
+
[y, s]
|
|
81
|
+
), W = i(
|
|
82
|
+
(e) => c ? p + e : e,
|
|
83
|
+
[c, p]
|
|
84
|
+
), b = i(
|
|
85
|
+
(e, t = "smooth") => {
|
|
86
|
+
const r = D(e), n = W(r);
|
|
87
|
+
L(n, t), v(r);
|
|
88
|
+
},
|
|
89
|
+
[D, W, L, v]
|
|
90
|
+
), z = i(() => {
|
|
91
|
+
const e = a.current;
|
|
92
|
+
if (!e || j === 0) return 0;
|
|
93
|
+
const t = e.scrollLeft, r = h === "center" ? t + e.clientWidth / 2 : t;
|
|
94
|
+
let n = 0, o = Number.POSITIVE_INFINITY;
|
|
95
|
+
for (let f = 0; f < j; f++) {
|
|
96
|
+
const u = x.current[f];
|
|
97
|
+
if (!u) continue;
|
|
98
|
+
const m = h === "center" ? u.offsetLeft + u.offsetWidth / 2 : u.offsetLeft, $ = Math.abs(m - r);
|
|
99
|
+
$ < o && (o = $, n = f);
|
|
100
|
+
}
|
|
101
|
+
return n;
|
|
102
|
+
}, [h, j]), E = i(
|
|
103
|
+
(e) => c ? e < p ? e + s : e >= p + s ? e - s : e : e,
|
|
104
|
+
[c, p, s]
|
|
105
|
+
), oe = l({
|
|
106
|
+
middleStart: 0,
|
|
107
|
+
groupWidth: 0
|
|
108
|
+
}), k = i(() => {
|
|
109
|
+
if (!c) return;
|
|
110
|
+
const e = a.current;
|
|
111
|
+
if (!e) return;
|
|
112
|
+
const t = x.current[p], r = x.current[p + s];
|
|
113
|
+
if (!t || !r) return;
|
|
114
|
+
const n = P(e, t), o = P(e, r);
|
|
115
|
+
oe.current = {
|
|
116
|
+
middleStart: n,
|
|
117
|
+
groupWidth: o - n
|
|
118
|
+
};
|
|
119
|
+
}, [c, p, s, P]), V = l(!1), K = i(
|
|
120
|
+
(e) => {
|
|
121
|
+
if (!c) return;
|
|
122
|
+
const t = a.current;
|
|
123
|
+
if (!t) return;
|
|
124
|
+
const { middleStart: r, groupWidth: n } = oe.current;
|
|
125
|
+
if (n <= 0) return;
|
|
126
|
+
const o = r, f = r + n;
|
|
127
|
+
let u = t.scrollLeft, m = 0;
|
|
128
|
+
u < o ? m = Math.ceil((o - u) / n) * n : u > f && (m = -Math.ceil((u - f) / n) * n), m !== 0 && (V.current = !0, t.scrollLeft = u + m, e === "drag" && (O.current += m), V.current = !1);
|
|
129
|
+
},
|
|
130
|
+
[c]
|
|
131
|
+
), S = i(() => {
|
|
132
|
+
if (y) {
|
|
133
|
+
Z(s > 1), ee(s > 1);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const e = a.current;
|
|
137
|
+
if (!e) return;
|
|
138
|
+
const t = e.scrollWidth - e.clientWidth, r = 1;
|
|
139
|
+
Z(t > r && e.scrollLeft > r), ee(t > r && e.scrollLeft < t - r);
|
|
140
|
+
}, [y, s]), F = i(() => {
|
|
141
|
+
s <= 1 || b(N.current + T);
|
|
142
|
+
}, [b, s, T]), B = i(() => {
|
|
143
|
+
s <= 1 || b(N.current - T);
|
|
144
|
+
}, [b, s, T]), ye = i(() => {
|
|
145
|
+
var n;
|
|
146
|
+
if (!G) return;
|
|
147
|
+
const e = z(), t = E(e);
|
|
148
|
+
L(t, "smooth");
|
|
149
|
+
const r = ((n = g[t]) == null ? void 0 : n.realIndex) ?? 0;
|
|
150
|
+
v(r);
|
|
151
|
+
}, [
|
|
152
|
+
G,
|
|
153
|
+
z,
|
|
154
|
+
E,
|
|
155
|
+
L,
|
|
156
|
+
g,
|
|
157
|
+
v
|
|
158
|
+
]);
|
|
159
|
+
Fe(
|
|
160
|
+
_e,
|
|
161
|
+
() => ({
|
|
162
|
+
next: F,
|
|
163
|
+
prev: B,
|
|
164
|
+
goTo: b,
|
|
165
|
+
getIndex: () => N.current,
|
|
166
|
+
getLength: () => s
|
|
167
|
+
}),
|
|
168
|
+
[b, F, B, s]
|
|
169
|
+
), Y(() => {
|
|
170
|
+
if (s === 0) return;
|
|
171
|
+
const e = D(J), t = W(e), r = window.requestAnimationFrame(() => {
|
|
172
|
+
k(), L(t, "auto"), v(e), S();
|
|
173
|
+
});
|
|
174
|
+
return () => window.cancelAnimationFrame(r);
|
|
175
|
+
}, [
|
|
176
|
+
s,
|
|
177
|
+
J,
|
|
178
|
+
D,
|
|
179
|
+
W,
|
|
180
|
+
L,
|
|
181
|
+
v,
|
|
182
|
+
S,
|
|
183
|
+
k
|
|
184
|
+
]), Y(() => {
|
|
185
|
+
if (!c) return;
|
|
186
|
+
const e = a.current;
|
|
187
|
+
if (!e) return;
|
|
188
|
+
const t = typeof ResizeObserver < "u" ? new ResizeObserver(() => {
|
|
189
|
+
k();
|
|
190
|
+
}) : null;
|
|
191
|
+
t == null || t.observe(e), x.current.forEach((o) => o && (t == null ? void 0 : t.observe(o)));
|
|
192
|
+
const r = () => k();
|
|
193
|
+
window.addEventListener("resize", r);
|
|
194
|
+
const n = window.requestAnimationFrame(() => k());
|
|
195
|
+
return () => {
|
|
196
|
+
window.removeEventListener("resize", r), window.cancelAnimationFrame(n), t == null || t.disconnect();
|
|
197
|
+
};
|
|
198
|
+
}, [c, k]), Y(() => {
|
|
199
|
+
const e = a.current;
|
|
200
|
+
if (!e) return;
|
|
201
|
+
const t = { current: 0 }, r = () => {
|
|
202
|
+
V.current || (c && !_.current && K("scroll"), S(), !t.current && (t.current = window.requestAnimationFrame(() => {
|
|
203
|
+
var u;
|
|
204
|
+
t.current = 0;
|
|
205
|
+
const n = z(), o = E(n), f = ((u = g[o]) == null ? void 0 : u.realIndex) ?? 0;
|
|
206
|
+
f !== N.current && v(f);
|
|
207
|
+
})));
|
|
208
|
+
};
|
|
209
|
+
return e.addEventListener("scroll", r, { passive: !0 }), () => {
|
|
210
|
+
e.removeEventListener("scroll", r), t.current && window.cancelAnimationFrame(t.current);
|
|
211
|
+
};
|
|
212
|
+
}, [
|
|
213
|
+
c,
|
|
214
|
+
K,
|
|
215
|
+
S,
|
|
216
|
+
z,
|
|
217
|
+
E,
|
|
218
|
+
g,
|
|
219
|
+
v
|
|
220
|
+
]);
|
|
221
|
+
const Ne = (e) => e instanceof HTMLElement ? !!e.closest(
|
|
222
|
+
'button, a, input, textarea, select, option, [role="button"], [data-carousel-no-drag="true"]'
|
|
223
|
+
) : !1, U = l(null), se = l(0), Pe = (e) => {
|
|
224
|
+
var t, r, n, o;
|
|
225
|
+
R && a.current && (Ne(e.target) || e.pointerType === "mouse" && e.button !== 0 || (e.preventDefault(), ne(!1), _.current = !0, X.current = !1, te.current = e.clientX, O.current = a.current.scrollLeft, re(!0), (r = (t = a.current).focus) == null || r.call(t), (o = (n = a.current).setPointerCapture) == null || o.call(n, e.pointerId)));
|
|
226
|
+
}, Se = (e) => {
|
|
227
|
+
if (!R || !_.current || (e.preventDefault(), !a.current)) return;
|
|
228
|
+
const r = e.clientX - te.current;
|
|
229
|
+
Math.abs(r) > 4 && (X.current = !0);
|
|
230
|
+
const n = O.current - r;
|
|
231
|
+
se.current = n, U.current == null && (U.current = window.requestAnimationFrame(() => {
|
|
232
|
+
U.current = null;
|
|
233
|
+
const o = a.current;
|
|
234
|
+
o && (o.scrollLeft = se.current, c && K("drag"));
|
|
235
|
+
}));
|
|
236
|
+
}, ce = (e) => {
|
|
237
|
+
var r;
|
|
238
|
+
const t = a.current;
|
|
239
|
+
if (_.current = !1, re(!1), t && e != null)
|
|
240
|
+
try {
|
|
241
|
+
(r = t.releasePointerCapture) == null || r.call(t, e);
|
|
242
|
+
} catch {
|
|
243
|
+
}
|
|
244
|
+
X.current && (H.current = !0, window.setTimeout(() => {
|
|
245
|
+
H.current = !1;
|
|
246
|
+
}, 0)), ne(!0), ye(), S();
|
|
247
|
+
}, Ce = (e) => {
|
|
248
|
+
R && _.current && ce(e.pointerId);
|
|
249
|
+
}, Me = (e) => {
|
|
250
|
+
R && _.current && ce(e.pointerId);
|
|
251
|
+
}, Ae = (e) => {
|
|
252
|
+
H.current && (e.preventDefault(), e.stopPropagation());
|
|
253
|
+
}, Te = (e) => {
|
|
254
|
+
he && (e.key === "ArrowLeft" ? (e.preventDefault(), B()) : e.key === "ArrowRight" && (e.preventDefault(), F()));
|
|
255
|
+
}, De = {
|
|
256
|
+
...de ?? {},
|
|
257
|
+
"--carousel-gap": `${ve}px`,
|
|
258
|
+
"--carousel-slide-size": pe,
|
|
259
|
+
"--carousel-snap-align": h
|
|
260
|
+
};
|
|
261
|
+
return /* @__PURE__ */ ae("div", { className: C(d.root, ue), style: De, "aria-label": Q, children: [
|
|
262
|
+
me && s > 1 && /* @__PURE__ */ ae(We, { children: [
|
|
263
|
+
/* @__PURE__ */ I(
|
|
264
|
+
"button",
|
|
265
|
+
{
|
|
266
|
+
type: "button",
|
|
267
|
+
className: C(d.navButton, d.navPrev),
|
|
268
|
+
onClick: B,
|
|
269
|
+
disabled: !ke,
|
|
270
|
+
"aria-label": "Précédent",
|
|
271
|
+
children: ge ?? /* @__PURE__ */ I("span", { "aria-hidden": !0, children: "‹" })
|
|
272
|
+
}
|
|
273
|
+
),
|
|
274
|
+
/* @__PURE__ */ I(
|
|
275
|
+
"button",
|
|
276
|
+
{
|
|
277
|
+
type: "button",
|
|
278
|
+
className: C(d.navButton, d.navNext),
|
|
279
|
+
onClick: F,
|
|
280
|
+
disabled: !Ie,
|
|
281
|
+
"aria-label": "Suivant",
|
|
282
|
+
children: xe ?? /* @__PURE__ */ I("span", { "aria-hidden": !0, children: "›" })
|
|
283
|
+
}
|
|
284
|
+
)
|
|
285
|
+
] }),
|
|
286
|
+
/* @__PURE__ */ I(
|
|
287
|
+
"div",
|
|
288
|
+
{
|
|
289
|
+
ref: a,
|
|
290
|
+
className: C(
|
|
291
|
+
d.viewport,
|
|
292
|
+
R && d.dragEnabled,
|
|
293
|
+
Re && d.dragging,
|
|
294
|
+
le
|
|
295
|
+
),
|
|
296
|
+
tabIndex: 0,
|
|
297
|
+
role: "region",
|
|
298
|
+
"aria-roledescription": "carousel",
|
|
299
|
+
"aria-label": Q,
|
|
300
|
+
onKeyDown: Te,
|
|
301
|
+
onPointerDown: Pe,
|
|
302
|
+
onPointerMove: Se,
|
|
303
|
+
onPointerUp: Ce,
|
|
304
|
+
onPointerCancel: Me,
|
|
305
|
+
onClickCapture: Ae,
|
|
306
|
+
children: g.map((e, t) => /* @__PURE__ */ I(
|
|
307
|
+
"div",
|
|
308
|
+
{
|
|
309
|
+
ref: (r) => {
|
|
310
|
+
x.current[t] = r;
|
|
311
|
+
},
|
|
312
|
+
className: C(d.slide, fe),
|
|
313
|
+
"data-carousel-slide": !0,
|
|
314
|
+
"data-carousel-clone": e.isClone ? "true" : "false",
|
|
315
|
+
"aria-label": `Item ${e.realIndex + 1} sur ${s}`,
|
|
316
|
+
"aria-current": e.realIndex === Le,
|
|
317
|
+
children: e.node
|
|
318
|
+
},
|
|
319
|
+
e.key
|
|
320
|
+
))
|
|
321
|
+
}
|
|
322
|
+
)
|
|
323
|
+
] });
|
|
324
|
+
}
|
|
325
|
+
);
|
|
326
|
+
export {
|
|
327
|
+
Ye as Carousel
|
|
328
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export type DragAndDropErrorCode = "FILE_TOO_LARGE" | "FILE_TYPE_NOT_ALLOWED";
|
|
4
|
+
export type DragAndDropError = {
|
|
5
|
+
/** Stable code to translate on the consumer side (i18n) */
|
|
6
|
+
code: DragAndDropErrorCode;
|
|
7
|
+
/** Optional dynamic values to build a translated message */
|
|
8
|
+
meta?: {
|
|
9
|
+
maxSizeLabel?: string;
|
|
10
|
+
maxBytes?: number | null;
|
|
11
|
+
receivedBytes?: number;
|
|
12
|
+
accept?: string;
|
|
13
|
+
fileName?: string;
|
|
14
|
+
fileType?: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export interface DragAndDropProps {
|
|
18
|
+
/** Maximum allowed file size (display + validation). Example: "10 Mo", "500 Ko", "1 Go". */
|
|
19
|
+
sizeFile: string;
|
|
20
|
+
/** Accepted file types (input accept format). Example: "image/*,.pdf" or "application/pdf,.pdf". */
|
|
21
|
+
typeFile: string;
|
|
22
|
+
/** Content rendered inside the dropzone (icon, title, hint, etc.). */
|
|
23
|
+
children: ReactNode;
|
|
24
|
+
/** Called when a file is successfully selected/dropped and validated. */
|
|
25
|
+
onFile: (file: File) => void;
|
|
26
|
+
/** Optional fixed width for the dropzone container (CSS value). Example: "420px", "100%". */
|
|
27
|
+
width?: string;
|
|
28
|
+
/** Called when validation fails (size/type). Translate outside using error.code + error.meta. */
|
|
29
|
+
onError?: (error: DragAndDropError) => void;
|
|
30
|
+
}
|
|
31
|
+
export declare const DragAndDrop: ({ sizeFile, typeFile, children, onFile, onError, width }: DragAndDropProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { jsx as y, jsxs as k } from "react/jsx-runtime";
|
|
2
|
+
import { useId as x, useRef as O, useState as j, useMemo as w, useCallback as r } from "react";
|
|
3
|
+
import '../../styles/DragAndDrop.css';const C = "_dropzone_jj8g2_30", I = "_dropzoneActive_jj8g2_48", E = "_input_jj8g2_53", h = {
|
|
4
|
+
dropzone: C,
|
|
5
|
+
dropzoneActive: I,
|
|
6
|
+
input: E
|
|
7
|
+
}, P = (n) => {
|
|
8
|
+
const a = n.trim().replace(",", ".").match(/^(\d+(?:\.\d+)?)\s*([a-zA-Z]+)$/);
|
|
9
|
+
if (!a) return null;
|
|
10
|
+
const i = Number(a[1]), t = a[2].toLowerCase();
|
|
11
|
+
if (Number.isNaN(i)) return null;
|
|
12
|
+
const o = {
|
|
13
|
+
b: 1,
|
|
14
|
+
ko: 1024,
|
|
15
|
+
kb: 1e3,
|
|
16
|
+
mo: 1024 ** 2,
|
|
17
|
+
mb: 1e3 ** 2,
|
|
18
|
+
go: 1024 ** 3,
|
|
19
|
+
gb: 1e3 ** 3,
|
|
20
|
+
mib: 1024 ** 2,
|
|
21
|
+
gib: 1024 ** 3
|
|
22
|
+
};
|
|
23
|
+
return o[t] ? Math.round(i * o[t]) : null;
|
|
24
|
+
}, W = (n, u) => {
|
|
25
|
+
const a = u.split(",").map((o) => o.trim()).filter(Boolean);
|
|
26
|
+
if (a.length === 0) return !0;
|
|
27
|
+
const i = n.name.toLowerCase(), t = (n.type || "").toLowerCase();
|
|
28
|
+
return a.some((o) => {
|
|
29
|
+
const s = o.toLowerCase();
|
|
30
|
+
if (s.startsWith(".")) return i.endsWith(s);
|
|
31
|
+
if (s.endsWith("/*")) {
|
|
32
|
+
const d = s.slice(0, s.indexOf("/"));
|
|
33
|
+
return t.startsWith(d + "/");
|
|
34
|
+
}
|
|
35
|
+
return t === s;
|
|
36
|
+
});
|
|
37
|
+
}, S = ({
|
|
38
|
+
sizeFile: n,
|
|
39
|
+
typeFile: u,
|
|
40
|
+
children: a,
|
|
41
|
+
onFile: i,
|
|
42
|
+
onError: t,
|
|
43
|
+
width: o = "auto"
|
|
44
|
+
}) => {
|
|
45
|
+
const s = x(), d = O(null), [b, g] = j(!1), f = w(() => P(n), [n]), p = u ?? "", v = r(
|
|
46
|
+
(e) => {
|
|
47
|
+
t == null || t(e);
|
|
48
|
+
},
|
|
49
|
+
[t]
|
|
50
|
+
), D = r(() => {
|
|
51
|
+
var e;
|
|
52
|
+
(e = d.current) == null || e.click();
|
|
53
|
+
}, []), m = r(
|
|
54
|
+
(e) => {
|
|
55
|
+
if (f != null && e.size > f) {
|
|
56
|
+
v({
|
|
57
|
+
code: "FILE_TOO_LARGE",
|
|
58
|
+
meta: {
|
|
59
|
+
maxSizeLabel: n,
|
|
60
|
+
maxBytes: f,
|
|
61
|
+
receivedBytes: e.size,
|
|
62
|
+
fileName: e.name,
|
|
63
|
+
fileType: e.type
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (p.trim() && !W(e, p)) {
|
|
69
|
+
v({
|
|
70
|
+
code: "FILE_TYPE_NOT_ALLOWED",
|
|
71
|
+
meta: {
|
|
72
|
+
accept: p,
|
|
73
|
+
fileName: e.name,
|
|
74
|
+
fileType: e.type
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
i(e);
|
|
80
|
+
},
|
|
81
|
+
[v, f, i, p, n]
|
|
82
|
+
), _ = r(
|
|
83
|
+
(e) => {
|
|
84
|
+
var l;
|
|
85
|
+
e.preventDefault(), e.stopPropagation(), g(!1);
|
|
86
|
+
const c = (l = e.dataTransfer.files) == null ? void 0 : l[0];
|
|
87
|
+
c && m(c);
|
|
88
|
+
},
|
|
89
|
+
[m]
|
|
90
|
+
), L = r((e) => {
|
|
91
|
+
e.preventDefault(), e.stopPropagation(), e.dataTransfer.dropEffect = "copy";
|
|
92
|
+
}, []), T = r((e) => {
|
|
93
|
+
e.preventDefault(), e.stopPropagation(), g(!0);
|
|
94
|
+
}, []), z = r((e) => {
|
|
95
|
+
e.preventDefault(), e.stopPropagation();
|
|
96
|
+
const c = e.relatedTarget;
|
|
97
|
+
c && e.currentTarget.contains(c) || g(!1);
|
|
98
|
+
}, []), A = r(
|
|
99
|
+
(e) => {
|
|
100
|
+
(e.key === "Enter" || e.key === " ") && (e.preventDefault(), D());
|
|
101
|
+
},
|
|
102
|
+
[D]
|
|
103
|
+
), N = r(
|
|
104
|
+
(e) => {
|
|
105
|
+
var l;
|
|
106
|
+
const c = (l = e.target.files) == null ? void 0 : l[0];
|
|
107
|
+
c && (m(c), e.target.value = "");
|
|
108
|
+
},
|
|
109
|
+
[m]
|
|
110
|
+
);
|
|
111
|
+
return /* @__PURE__ */ y("div", { style: { width: o }, children: /* @__PURE__ */ k(
|
|
112
|
+
"div",
|
|
113
|
+
{
|
|
114
|
+
className: `${h.dropzone} ${b ? h.dropzoneActive : ""}`,
|
|
115
|
+
role: "button",
|
|
116
|
+
tabIndex: 0,
|
|
117
|
+
"aria-label": "Upload file",
|
|
118
|
+
onClick: D,
|
|
119
|
+
onKeyDown: A,
|
|
120
|
+
onDrop: _,
|
|
121
|
+
onDragOver: L,
|
|
122
|
+
onDragEnter: T,
|
|
123
|
+
onDragLeave: z,
|
|
124
|
+
children: [
|
|
125
|
+
a,
|
|
126
|
+
/* @__PURE__ */ y(
|
|
127
|
+
"input",
|
|
128
|
+
{
|
|
129
|
+
id: s,
|
|
130
|
+
ref: d,
|
|
131
|
+
className: h.input,
|
|
132
|
+
type: "file",
|
|
133
|
+
accept: p,
|
|
134
|
+
onChange: N
|
|
135
|
+
}
|
|
136
|
+
)
|
|
137
|
+
]
|
|
138
|
+
}
|
|
139
|
+
) });
|
|
140
|
+
};
|
|
141
|
+
export {
|
|
142
|
+
S as DragAndDrop
|
|
143
|
+
};
|