@situaction/traq-ui-ste 1.2.17 → 1.2.18
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/components/carousel/Carousel.js +127 -125
- package/package.json +1 -1
|
@@ -1,108 +1,110 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import
|
|
3
|
-
import '../../styles/Carousel.css';const
|
|
4
|
-
root:
|
|
5
|
-
viewport:
|
|
6
|
-
dragEnabled:
|
|
7
|
-
dragging:
|
|
8
|
-
slide:
|
|
9
|
-
navButton:
|
|
10
|
-
navPrev:
|
|
11
|
-
navNext:
|
|
12
|
-
},
|
|
1
|
+
import { jsxs as ie, jsx as R, Fragment as We } from "react/jsx-runtime";
|
|
2
|
+
import ze, { forwardRef as Ee, useMemo as ue, useRef as l, useState as $, useEffect as j, useCallback as i, useImperativeHandle as Fe } from "react";
|
|
3
|
+
import '../../styles/Carousel.css';const Be = "_root_36mqp_6", $e = "_viewport_36mqp_11", je = "_dragEnabled_36mqp_27", Oe = "_dragging_36mqp_32", Xe = "_slide_36mqp_39", He = "_navButton_36mqp_46", Ve = "_navPrev_36mqp_63", Ke = "_navNext_36mqp_67", d = {
|
|
4
|
+
root: Be,
|
|
5
|
+
viewport: $e,
|
|
6
|
+
dragEnabled: je,
|
|
7
|
+
dragging: Oe,
|
|
8
|
+
slide: Xe,
|
|
9
|
+
navButton: He,
|
|
10
|
+
navPrev: Ve,
|
|
11
|
+
navNext: Ke
|
|
12
|
+
}, S = (...M) => M.filter(Boolean).join(" "), Ge = Ee(
|
|
13
13
|
({
|
|
14
14
|
children: M,
|
|
15
|
-
className:
|
|
16
|
-
viewportClassName:
|
|
17
|
-
slideClassName:
|
|
18
|
-
style:
|
|
19
|
-
slideSize:
|
|
20
|
-
gap:
|
|
21
|
-
align:
|
|
22
|
-
showArrows:
|
|
15
|
+
className: le,
|
|
16
|
+
viewportClassName: fe,
|
|
17
|
+
slideClassName: de,
|
|
18
|
+
style: pe,
|
|
19
|
+
slideSize: me = "30%",
|
|
20
|
+
gap: ve = 12,
|
|
21
|
+
align: g = "center",
|
|
22
|
+
showArrows: ge = !0,
|
|
23
23
|
dragEnabled: y = !0,
|
|
24
|
-
snapOnRelease:
|
|
24
|
+
snapOnRelease: J = !0,
|
|
25
25
|
keyboardNavigation: we = !0,
|
|
26
|
-
step:
|
|
27
|
-
initialIndex:
|
|
26
|
+
step: he = 1,
|
|
27
|
+
initialIndex: Q = 0,
|
|
28
28
|
loop: N = !1,
|
|
29
|
-
ariaLabel:
|
|
30
|
-
iconLeft:
|
|
31
|
-
iconRight:
|
|
32
|
-
onIndexChange:
|
|
29
|
+
ariaLabel: Z = "Carousel",
|
|
30
|
+
iconLeft: xe,
|
|
31
|
+
iconRight: Ie,
|
|
32
|
+
onIndexChange: O
|
|
33
33
|
}, _e) => {
|
|
34
|
-
const
|
|
34
|
+
const w = ue(() => ze.Children.toArray(M), [M]), s = w.length, c = N && s > 1, A = Math.max(1, Math.min(he, Math.max(1, s))), p = c ? s : 0, h = ue(() => {
|
|
35
35
|
if (!c)
|
|
36
|
-
return
|
|
36
|
+
return w.map((n, o) => ({
|
|
37
37
|
key: `real-${o}`,
|
|
38
38
|
node: n,
|
|
39
39
|
realIndex: o,
|
|
40
40
|
isClone: !1
|
|
41
41
|
}));
|
|
42
|
-
const e =
|
|
42
|
+
const e = w.map((n, o) => ({
|
|
43
43
|
key: `clone-head-${o}`,
|
|
44
44
|
node: n,
|
|
45
45
|
realIndex: o,
|
|
46
46
|
isClone: !0
|
|
47
|
-
})), t =
|
|
47
|
+
})), t = w.map((n, o) => ({
|
|
48
48
|
key: `real-${o}`,
|
|
49
49
|
node: n,
|
|
50
50
|
realIndex: o,
|
|
51
51
|
isClone: !1
|
|
52
|
-
})), r =
|
|
52
|
+
})), r = w.map((n, o) => ({
|
|
53
53
|
key: `clone-tail-${o}`,
|
|
54
54
|
node: n,
|
|
55
55
|
realIndex: o,
|
|
56
56
|
isClone: !0
|
|
57
57
|
}));
|
|
58
58
|
return [...e, ...t, ...r];
|
|
59
|
-
}, [c,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
}, [c, w]), X = h.length, a = l(null), x = l([]), [Le, be] = $(0), k = l(0), [Re, ee] = $(!1), [ye, te] = $(!1), I = l(!1), re = l(0), H = l(0), V = l(!1), K = l(!1), [Ne, ne] = $(!1), T = l(O);
|
|
60
|
+
j(() => {
|
|
61
|
+
T.current = O;
|
|
62
|
+
}, [O]);
|
|
63
|
+
const m = i((e) => {
|
|
64
|
+
var t;
|
|
65
|
+
k.current = e, be(e), (t = T.current) == null || t.call(T, e);
|
|
66
|
+
}, []), oe = i((e) => {
|
|
65
67
|
const t = a.current;
|
|
66
68
|
t && (t.style.scrollSnapType = e ? "x mandatory" : "none", t.style.scrollBehavior = e ? "smooth" : "auto");
|
|
67
|
-
}, []),
|
|
68
|
-
(e, t) =>
|
|
69
|
-
[
|
|
70
|
-
),
|
|
69
|
+
}, []), C = i(
|
|
70
|
+
(e, t) => g === "center" ? t.offsetLeft - (e.clientWidth - t.offsetWidth) / 2 : t.offsetLeft,
|
|
71
|
+
[g]
|
|
72
|
+
), _ = i(
|
|
71
73
|
(e, t = "smooth") => {
|
|
72
74
|
const r = a.current, n = x.current[e];
|
|
73
75
|
if (!r || !n) return;
|
|
74
|
-
const o =
|
|
76
|
+
const o = C(r, n);
|
|
75
77
|
r.scrollTo({ left: o, behavior: t });
|
|
76
78
|
},
|
|
77
|
-
[
|
|
79
|
+
[C]
|
|
78
80
|
), q = i(
|
|
79
81
|
(e) => s === 0 ? 0 : N ? (e % s + s) % s : Math.max(0, Math.min(s - 1, e)),
|
|
80
82
|
[N, s]
|
|
81
83
|
), D = i(
|
|
82
84
|
(e) => c ? p + e : e,
|
|
83
85
|
[c, p]
|
|
84
|
-
),
|
|
86
|
+
), L = i(
|
|
85
87
|
(e, t = "smooth") => {
|
|
86
88
|
const r = q(e), n = D(r);
|
|
87
|
-
|
|
89
|
+
_(n, t), m(r);
|
|
88
90
|
},
|
|
89
|
-
[q, D,
|
|
91
|
+
[q, D, _, m]
|
|
90
92
|
), W = i(() => {
|
|
91
93
|
const e = a.current;
|
|
92
|
-
if (!e ||
|
|
93
|
-
const t = e.scrollLeft, r =
|
|
94
|
+
if (!e || X === 0) return 0;
|
|
95
|
+
const t = e.scrollLeft, r = g === "center" ? t + e.clientWidth / 2 : t;
|
|
94
96
|
let n = 0, o = Number.POSITIVE_INFINITY;
|
|
95
|
-
for (let f = 0; f <
|
|
97
|
+
for (let f = 0; f < X; f++) {
|
|
96
98
|
const u = x.current[f];
|
|
97
99
|
if (!u) continue;
|
|
98
|
-
const v =
|
|
100
|
+
const v = g === "center" ? u.offsetLeft + u.offsetWidth / 2 : u.offsetLeft, B = Math.abs(v - r);
|
|
99
101
|
B < o && (o = B, n = f);
|
|
100
102
|
}
|
|
101
103
|
return n;
|
|
102
|
-
}, [
|
|
104
|
+
}, [g, X]), z = i(
|
|
103
105
|
(e) => c ? e < p ? e + s : e >= p + s ? e - s : e : e,
|
|
104
106
|
[c, p, s]
|
|
105
|
-
),
|
|
107
|
+
), se = l({
|
|
106
108
|
middleStart: 0,
|
|
107
109
|
groupWidth: 0
|
|
108
110
|
}), b = i(() => {
|
|
@@ -111,77 +113,77 @@ import '../../styles/Carousel.css';const Fe = "_root_36mqp_6", Be = "_viewport_3
|
|
|
111
113
|
if (!e) return;
|
|
112
114
|
const t = x.current[p], r = x.current[p + s];
|
|
113
115
|
if (!t || !r) return;
|
|
114
|
-
const n =
|
|
115
|
-
|
|
116
|
+
const n = C(e, t), o = C(e, r);
|
|
117
|
+
se.current = {
|
|
116
118
|
middleStart: n,
|
|
117
119
|
groupWidth: o - n
|
|
118
120
|
};
|
|
119
|
-
}, [c, p, s,
|
|
121
|
+
}, [c, p, s, C]), U = l(!1), Y = i(
|
|
120
122
|
(e) => {
|
|
121
123
|
if (!c) return;
|
|
122
124
|
const t = a.current;
|
|
123
125
|
if (!t) return;
|
|
124
|
-
const { middleStart: r, groupWidth: n } =
|
|
126
|
+
const { middleStart: r, groupWidth: n } = se.current;
|
|
125
127
|
if (n <= 0) return;
|
|
126
128
|
const o = r, f = r + n;
|
|
127
129
|
let u = t.scrollLeft, v = 0;
|
|
128
|
-
u < o ? v = Math.ceil((o - u) / n) * n : u > f && (v = -Math.ceil((u - f) / n) * n), v !== 0 && (
|
|
130
|
+
u < o ? v = Math.ceil((o - u) / n) * n : u > f && (v = -Math.ceil((u - f) / n) * n), v !== 0 && (U.current = !0, t.scrollLeft = u + v, e === "drag" && (H.current += v), U.current = !1);
|
|
129
131
|
},
|
|
130
132
|
[c]
|
|
131
|
-
),
|
|
133
|
+
), P = i(() => {
|
|
132
134
|
if (N) {
|
|
133
|
-
|
|
135
|
+
ee(s > 1), te(s > 1);
|
|
134
136
|
return;
|
|
135
137
|
}
|
|
136
138
|
const e = a.current;
|
|
137
139
|
if (!e) return;
|
|
138
140
|
const t = e.scrollWidth - e.clientWidth, r = 1;
|
|
139
|
-
|
|
141
|
+
ee(t > r && e.scrollLeft > r), te(t > r && e.scrollLeft < t - r);
|
|
140
142
|
}, [N, s]), E = i(() => {
|
|
141
|
-
s <= 1 ||
|
|
142
|
-
}, [
|
|
143
|
-
s <= 1 ||
|
|
144
|
-
}, [
|
|
143
|
+
s <= 1 || L(k.current + A);
|
|
144
|
+
}, [L, s, A]), F = i(() => {
|
|
145
|
+
s <= 1 || L(k.current - A);
|
|
146
|
+
}, [L, s, A]), ke = i(() => {
|
|
145
147
|
var n;
|
|
146
|
-
if (!
|
|
148
|
+
if (!J) return;
|
|
147
149
|
const e = W(), t = z(e);
|
|
148
|
-
|
|
150
|
+
_(t, "smooth");
|
|
149
151
|
const r = ((n = h[t]) == null ? void 0 : n.realIndex) ?? 0;
|
|
150
152
|
m(r);
|
|
151
153
|
}, [
|
|
152
|
-
|
|
154
|
+
J,
|
|
153
155
|
W,
|
|
154
156
|
z,
|
|
155
|
-
|
|
157
|
+
_,
|
|
156
158
|
h,
|
|
157
159
|
m
|
|
158
160
|
]);
|
|
159
|
-
|
|
161
|
+
Fe(
|
|
160
162
|
_e,
|
|
161
163
|
() => ({
|
|
162
164
|
next: E,
|
|
163
165
|
prev: F,
|
|
164
|
-
goTo:
|
|
166
|
+
goTo: L,
|
|
165
167
|
getIndex: () => k.current,
|
|
166
168
|
getLength: () => s
|
|
167
169
|
}),
|
|
168
|
-
[
|
|
169
|
-
),
|
|
170
|
+
[L, E, F, s]
|
|
171
|
+
), j(() => {
|
|
170
172
|
if (s === 0) return;
|
|
171
|
-
const e = q(
|
|
172
|
-
b(),
|
|
173
|
+
const e = q(Q), t = D(e), r = window.requestAnimationFrame(() => {
|
|
174
|
+
b(), _(t, "auto"), m(e), P();
|
|
173
175
|
});
|
|
174
176
|
return () => window.cancelAnimationFrame(r);
|
|
175
177
|
}, [
|
|
176
178
|
s,
|
|
177
|
-
|
|
179
|
+
Q,
|
|
178
180
|
q,
|
|
179
181
|
D,
|
|
180
|
-
|
|
182
|
+
_,
|
|
181
183
|
m,
|
|
182
|
-
|
|
184
|
+
P,
|
|
183
185
|
b
|
|
184
|
-
]),
|
|
186
|
+
]), j(() => {
|
|
185
187
|
if (!c) return;
|
|
186
188
|
const e = a.current;
|
|
187
189
|
if (!e) return;
|
|
@@ -195,11 +197,11 @@ import '../../styles/Carousel.css';const Fe = "_root_36mqp_6", Be = "_viewport_3
|
|
|
195
197
|
return () => {
|
|
196
198
|
window.removeEventListener("resize", r), window.cancelAnimationFrame(n), t == null || t.disconnect();
|
|
197
199
|
};
|
|
198
|
-
}, [c, b]),
|
|
200
|
+
}, [c, b]), j(() => {
|
|
199
201
|
const e = a.current;
|
|
200
202
|
if (!e) return;
|
|
201
203
|
const t = { current: 0 }, r = () => {
|
|
202
|
-
|
|
204
|
+
U.current || (c && !I.current && Y("scroll"), P(), !t.current && (t.current = window.requestAnimationFrame(() => {
|
|
203
205
|
var u;
|
|
204
206
|
t.current = 0;
|
|
205
207
|
const n = W(), o = z(n), f = ((u = h[o]) == null ? void 0 : u.realIndex) ?? 0;
|
|
@@ -211,73 +213,73 @@ import '../../styles/Carousel.css';const Fe = "_root_36mqp_6", Be = "_viewport_3
|
|
|
211
213
|
};
|
|
212
214
|
}, [
|
|
213
215
|
c,
|
|
214
|
-
|
|
215
|
-
|
|
216
|
+
Y,
|
|
217
|
+
P,
|
|
216
218
|
W,
|
|
217
219
|
z,
|
|
218
220
|
h,
|
|
219
221
|
m
|
|
220
222
|
]);
|
|
221
|
-
const
|
|
223
|
+
const Ce = (e) => e instanceof HTMLElement ? !!e.closest(
|
|
222
224
|
'button, a, input, textarea, select, option, [role="button"], [data-carousel-no-drag="true"]'
|
|
223
|
-
) : !1,
|
|
225
|
+
) : !1, G = l(null), ce = l(0), Pe = (e) => {
|
|
224
226
|
var t, r, n, o;
|
|
225
|
-
y && a.current && (
|
|
227
|
+
y && a.current && (Ce(e.target) || e.pointerType === "mouse" && e.button !== 0 || (e.preventDefault(), oe(!1), I.current = !0, V.current = !1, re.current = e.clientX, H.current = a.current.scrollLeft, ne(!0), (r = (t = a.current).focus) == null || r.call(t), (o = (n = a.current).setPointerCapture) == null || o.call(n, e.pointerId)));
|
|
226
228
|
}, Se = (e) => {
|
|
227
|
-
if (!y || !
|
|
228
|
-
const r = e.clientX -
|
|
229
|
-
Math.abs(r) > 4 && (
|
|
230
|
-
const n =
|
|
231
|
-
|
|
232
|
-
|
|
229
|
+
if (!y || !I.current || (e.preventDefault(), !a.current)) return;
|
|
230
|
+
const r = e.clientX - re.current;
|
|
231
|
+
Math.abs(r) > 4 && (V.current = !0);
|
|
232
|
+
const n = H.current - r;
|
|
233
|
+
ce.current = n, G.current == null && (G.current = window.requestAnimationFrame(() => {
|
|
234
|
+
G.current = null;
|
|
233
235
|
const o = a.current;
|
|
234
|
-
o && (o.scrollLeft =
|
|
236
|
+
o && (o.scrollLeft = ce.current, c && Y("drag"));
|
|
235
237
|
}));
|
|
236
|
-
},
|
|
238
|
+
}, ae = (e) => {
|
|
237
239
|
var r;
|
|
238
240
|
const t = a.current;
|
|
239
|
-
if (
|
|
241
|
+
if (I.current = !1, ne(!1), t && e != null)
|
|
240
242
|
try {
|
|
241
243
|
(r = t.releasePointerCapture) == null || r.call(t, e);
|
|
242
244
|
} catch {
|
|
243
245
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}, 0)),
|
|
247
|
-
}, Ce = (e) => {
|
|
248
|
-
y && _.current && ce(e.pointerId);
|
|
246
|
+
V.current && (K.current = !0, window.setTimeout(() => {
|
|
247
|
+
K.current = !1;
|
|
248
|
+
}, 0)), oe(!0), ke(), P();
|
|
249
249
|
}, Me = (e) => {
|
|
250
|
-
y &&
|
|
250
|
+
y && I.current && ae(e.pointerId);
|
|
251
251
|
}, Ae = (e) => {
|
|
252
|
-
|
|
252
|
+
y && I.current && ae(e.pointerId);
|
|
253
253
|
}, Te = (e) => {
|
|
254
|
+
K.current && (e.preventDefault(), e.stopPropagation());
|
|
255
|
+
}, qe = (e) => {
|
|
254
256
|
we && (e.key === "ArrowLeft" ? (e.preventDefault(), F()) : e.key === "ArrowRight" && (e.preventDefault(), E()));
|
|
255
|
-
},
|
|
256
|
-
...
|
|
257
|
-
"--carousel-gap": `${
|
|
258
|
-
"--carousel-slide-size":
|
|
259
|
-
"--carousel-snap-align":
|
|
257
|
+
}, De = {
|
|
258
|
+
...pe ?? {},
|
|
259
|
+
"--carousel-gap": `${ve}px`,
|
|
260
|
+
"--carousel-slide-size": me,
|
|
261
|
+
"--carousel-snap-align": g
|
|
260
262
|
};
|
|
261
|
-
return /* @__PURE__ */
|
|
262
|
-
|
|
263
|
-
|
|
263
|
+
return /* @__PURE__ */ ie("div", { className: S(d.root, le), style: De, "aria-label": Z, children: [
|
|
264
|
+
ge && s > 1 && /* @__PURE__ */ ie(We, { children: [
|
|
265
|
+
Re && /* @__PURE__ */ R(
|
|
264
266
|
"button",
|
|
265
267
|
{
|
|
266
268
|
type: "button",
|
|
267
|
-
className:
|
|
269
|
+
className: S(d.navButton, d.navPrev),
|
|
268
270
|
onClick: F,
|
|
269
271
|
"aria-label": "Précédent",
|
|
270
|
-
children:
|
|
272
|
+
children: xe ?? /* @__PURE__ */ R("span", { "aria-hidden": !0, children: "‹" })
|
|
271
273
|
}
|
|
272
274
|
),
|
|
273
|
-
|
|
275
|
+
ye && /* @__PURE__ */ R(
|
|
274
276
|
"button",
|
|
275
277
|
{
|
|
276
278
|
type: "button",
|
|
277
|
-
className:
|
|
279
|
+
className: S(d.navButton, d.navNext),
|
|
278
280
|
onClick: E,
|
|
279
281
|
"aria-label": "Suivant",
|
|
280
|
-
children:
|
|
282
|
+
children: Ie ?? /* @__PURE__ */ R("span", { "aria-hidden": !0, children: "›" })
|
|
281
283
|
}
|
|
282
284
|
)
|
|
283
285
|
] }),
|
|
@@ -285,29 +287,29 @@ import '../../styles/Carousel.css';const Fe = "_root_36mqp_6", Be = "_viewport_3
|
|
|
285
287
|
"div",
|
|
286
288
|
{
|
|
287
289
|
ref: a,
|
|
288
|
-
className:
|
|
290
|
+
className: S(
|
|
289
291
|
d.viewport,
|
|
290
292
|
y && d.dragEnabled,
|
|
291
|
-
|
|
292
|
-
|
|
293
|
+
Ne && d.dragging,
|
|
294
|
+
fe
|
|
293
295
|
),
|
|
294
296
|
tabIndex: 0,
|
|
295
297
|
role: "region",
|
|
296
298
|
"aria-roledescription": "carousel",
|
|
297
|
-
"aria-label":
|
|
298
|
-
onKeyDown:
|
|
299
|
+
"aria-label": Z,
|
|
300
|
+
onKeyDown: qe,
|
|
299
301
|
onPointerDown: Pe,
|
|
300
302
|
onPointerMove: Se,
|
|
301
|
-
onPointerUp:
|
|
302
|
-
onPointerCancel:
|
|
303
|
-
onClickCapture:
|
|
303
|
+
onPointerUp: Me,
|
|
304
|
+
onPointerCancel: Ae,
|
|
305
|
+
onClickCapture: Te,
|
|
304
306
|
children: h.map((e, t) => /* @__PURE__ */ R(
|
|
305
307
|
"div",
|
|
306
308
|
{
|
|
307
309
|
ref: (r) => {
|
|
308
310
|
x.current[t] = r;
|
|
309
311
|
},
|
|
310
|
-
className:
|
|
312
|
+
className: S(d.slide, de),
|
|
311
313
|
"data-carousel-slide": !0,
|
|
312
314
|
"data-carousel-clone": e.isClone ? "true" : "false",
|
|
313
315
|
"aria-label": `Item ${e.realIndex + 1} sur ${s}`,
|
|
@@ -322,5 +324,5 @@ import '../../styles/Carousel.css';const Fe = "_root_36mqp_6", Be = "_viewport_3
|
|
|
322
324
|
}
|
|
323
325
|
);
|
|
324
326
|
export {
|
|
325
|
-
|
|
327
|
+
Ge as Carousel
|
|
326
328
|
};
|