@scrippsproduct/networks-ui-library 1.0.18-dev.0 → 1.0.18-dev.1
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 +135 -167
- package/package.json +1 -1
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useRef as
|
|
3
|
-
import
|
|
4
|
-
import { CarouselSlide as
|
|
5
|
-
import { chunkArray as
|
|
6
|
-
import { c as
|
|
7
|
-
import { C as
|
|
8
|
-
import { C as
|
|
9
|
-
const
|
|
10
|
-
function
|
|
11
|
-
id:
|
|
12
|
-
slides:
|
|
13
|
-
options:
|
|
1
|
+
import { jsx as o, Fragment as X, jsxs as K } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as s, useState as P, useEffect as B, useCallback as d } from "react";
|
|
3
|
+
import Y from "./CarouselUtils.class.js";
|
|
4
|
+
import { CarouselSlide as Z } from "../CarouselSlide/CarouselSlide.js";
|
|
5
|
+
import { chunkArray as ee, classes as _ } from "../../utils/helpers.js";
|
|
6
|
+
import { c as a } from "../../Carousel.module-DOrBKQEQ.mjs";
|
|
7
|
+
import { C as re } from "../../chevron-left-DmvQntvu.mjs";
|
|
8
|
+
import { C as te } from "../../chevron-right-CaAz6ISN.mjs";
|
|
9
|
+
const b = window.matchMedia("(width <= 600px)"), z = window.matchMedia("(width <= 800px"), E = window.matchMedia("(width <= 1024px"), L = window.matchMedia("(width <= 1280px");
|
|
10
|
+
function de({
|
|
11
|
+
id: g,
|
|
12
|
+
slides: x,
|
|
13
|
+
options: I = {
|
|
14
14
|
paginationType: "dots",
|
|
15
15
|
showControls: !0,
|
|
16
16
|
controlArrowSize: 48,
|
|
@@ -31,189 +31,157 @@ function pe({
|
|
|
31
31
|
wrapAround: !0
|
|
32
32
|
}
|
|
33
33
|
}) {
|
|
34
|
-
console.log(`Carousel component with id: ${
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
...
|
|
40
|
-
showControls: !1,
|
|
41
|
-
showPagination: !1,
|
|
42
|
-
cellsPerSlide: 1,
|
|
43
|
-
cellsPosition: o.current.wrapAround ? "center" : "flex-start",
|
|
44
|
-
gutterSize: 10
|
|
45
|
-
}), e.current = {
|
|
46
|
-
...o.current,
|
|
34
|
+
console.log(`Carousel component with id: ${g} initialized`);
|
|
35
|
+
const p = s(`carousel-${g}`), R = s(null), i = s(null), $ = s(null), m = s(x), T = s(null), S = s(null), r = s(null), e = s(I), l = s(I), N = s("-50%"), [M, G] = P([]), [k, H] = P([]), [D, U] = P(0);
|
|
36
|
+
B(() => {
|
|
37
|
+
const t = () => {
|
|
38
|
+
b.matches ? e.current = {
|
|
39
|
+
...l.current,
|
|
47
40
|
showControls: !1,
|
|
48
41
|
showPagination: !1,
|
|
49
42
|
cellsPerSlide: 1,
|
|
50
|
-
cellsPosition:
|
|
43
|
+
cellsPosition: l.current.wrapAround ? "center" : "flex-start",
|
|
51
44
|
gutterSize: 10
|
|
52
|
-
}
|
|
53
|
-
...
|
|
45
|
+
} : z.matches ? l.current.cellsPerSlide !== 1 ? e.current = {
|
|
46
|
+
...l.current,
|
|
54
47
|
cellsPerSlide: 2,
|
|
55
48
|
showControls: !1,
|
|
56
49
|
gutterSize: 10
|
|
57
|
-
}
|
|
58
|
-
...
|
|
59
|
-
cellsPerSlide: 2,
|
|
60
|
-
showControls: !1,
|
|
61
|
-
gutterSize: 10
|
|
62
|
-
}) : (d({
|
|
63
|
-
...o.current,
|
|
50
|
+
} : e.current = {
|
|
51
|
+
...l.current,
|
|
64
52
|
showControls: !1,
|
|
65
53
|
gutterSize: 10
|
|
66
|
-
}
|
|
67
|
-
...
|
|
68
|
-
showControls: !1,
|
|
69
|
-
gutterSize: 10
|
|
70
|
-
}) : R.matches ? o.current.cellsPerSlide !== 1 && o.current.cellsPerSlide !== 2 ? (d({
|
|
71
|
-
...o.current,
|
|
72
|
-
cellsPerSlide: 3,
|
|
73
|
-
showControls: !1,
|
|
74
|
-
gutterSize: 10
|
|
75
|
-
}), e.current = {
|
|
76
|
-
...o.current,
|
|
54
|
+
} : E.matches ? l.current.cellsPerSlide !== 1 && l.current.cellsPerSlide !== 2 ? e.current = {
|
|
55
|
+
...l.current,
|
|
77
56
|
cellsPerSlide: 3,
|
|
78
57
|
showControls: !1,
|
|
79
58
|
gutterSize: 10
|
|
80
|
-
}
|
|
81
|
-
...
|
|
59
|
+
} : e.current = {
|
|
60
|
+
...l.current,
|
|
82
61
|
showControls: !1,
|
|
83
62
|
gutterSize: 10
|
|
84
|
-
}
|
|
85
|
-
...
|
|
86
|
-
showControls: !1,
|
|
87
|
-
gutterSize: 10
|
|
88
|
-
}) : I.matches ? o.current.showPagination ? (d({
|
|
89
|
-
...o.current,
|
|
63
|
+
} : L.matches ? l.current.showPagination ? e.current = {
|
|
64
|
+
...l.current,
|
|
90
65
|
showControls: !1
|
|
91
|
-
}
|
|
92
|
-
...
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}), e.current = {
|
|
97
|
-
...o.current
|
|
98
|
-
}) : (d({
|
|
99
|
-
...o.current
|
|
100
|
-
}), e.current = {
|
|
101
|
-
...o.current
|
|
102
|
-
});
|
|
66
|
+
} : e.current = {
|
|
67
|
+
...l.current
|
|
68
|
+
} : e.current = {
|
|
69
|
+
...l.current
|
|
70
|
+
};
|
|
103
71
|
};
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
72
|
+
t();
|
|
73
|
+
const n = () => {
|
|
74
|
+
U((u) => u + 1), t();
|
|
107
75
|
};
|
|
108
|
-
return
|
|
109
|
-
|
|
76
|
+
return b.addEventListener("change", n), z.addEventListener("change", n), E.addEventListener("change", n), L.addEventListener("change", n), () => {
|
|
77
|
+
b.removeEventListener("change", n), z.removeEventListener("change", n), E.removeEventListener("change", n), L.removeEventListener("change", n);
|
|
110
78
|
};
|
|
111
79
|
}, []);
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
let
|
|
116
|
-
for (let
|
|
117
|
-
|
|
118
|
-
for (let
|
|
119
|
-
|
|
120
|
-
props:
|
|
80
|
+
const O = d((t, n) => {
|
|
81
|
+
const u = ee(n, t);
|
|
82
|
+
H([...u]);
|
|
83
|
+
let h = [];
|
|
84
|
+
for (let c = 0; c <= u.length - 1; c++) {
|
|
85
|
+
h[c] = {}, h[c].ariaLabel = `${c + 1} of ${u.length}`, h[c].layout = u[c][0].layout, h[c].cells = [];
|
|
86
|
+
for (let w = 0; w <= u[c].length - 1; w++)
|
|
87
|
+
h[c].cells[w] = {
|
|
88
|
+
props: u[c][w].props
|
|
121
89
|
};
|
|
122
90
|
}
|
|
123
|
-
const
|
|
124
|
-
return
|
|
125
|
-
}, []),
|
|
91
|
+
const C = [...h], A = [...h], J = C.slice(-1), Q = C.slice(0);
|
|
92
|
+
return A.push(Q[0]), A.unshift(J[0]), e.current.wrapAround && t.length > n ? A : C;
|
|
93
|
+
}, []), f = d(() => {
|
|
126
94
|
e.current.autoplay && r.current.clearTimer();
|
|
127
|
-
}, []),
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
}, [
|
|
132
|
-
|
|
95
|
+
}, []), F = d((t) => {
|
|
96
|
+
f();
|
|
97
|
+
const n = t.key;
|
|
98
|
+
n === "ArrowLeft" ? (t.preventDefault(), r.current.determineScrollAction(-1)) : n === "ArrowRight" && (t.preventDefault(), r.current.determineScrollAction(1));
|
|
99
|
+
}, [f]), W = d(() => {
|
|
100
|
+
f(), i.current.addEventListener("scrollend", () => {
|
|
133
101
|
r.current.handleScrollEnd();
|
|
134
102
|
}, { once: !0 });
|
|
135
|
-
}, [
|
|
136
|
-
|
|
137
|
-
r.current.handleScrollEnd(),
|
|
103
|
+
}, [f]), v = d(() => {
|
|
104
|
+
f(), i.current.addEventListener("scrollend", () => {
|
|
105
|
+
r.current.handleScrollEnd(), i.current.addEventListener("scroll", v, { once: !0 });
|
|
138
106
|
}, { once: !0 });
|
|
139
|
-
}, [
|
|
107
|
+
}, [f]), q = () => {
|
|
140
108
|
r.current && e.current.autoplay && r.current.clearTimer();
|
|
141
|
-
},
|
|
109
|
+
}, y = d(() => {
|
|
142
110
|
//! make sure class is only instantiated once because of reacts
|
|
143
111
|
//! "strict" mode double do hocus pocus
|
|
144
|
-
var
|
|
145
|
-
r.current !== null &&
|
|
146
|
-
carouselEl:
|
|
147
|
-
scrollerEl:
|
|
148
|
-
paginationEl:
|
|
149
|
-
slides:
|
|
112
|
+
var t, n;
|
|
113
|
+
r.current !== null && D > 0 && ((n = (t = r.current).clearTimer) == null || n.call(t), r.current = null), r.current = new Y({
|
|
114
|
+
carouselEl: R.current,
|
|
115
|
+
scrollerEl: i.current,
|
|
116
|
+
paginationEl: $.current,
|
|
117
|
+
slides: m.current,
|
|
150
118
|
navBtnEls: {
|
|
151
|
-
next:
|
|
152
|
-
previous:
|
|
119
|
+
next: T.current,
|
|
120
|
+
previous: S.current
|
|
153
121
|
},
|
|
154
|
-
id:
|
|
122
|
+
id: p.current,
|
|
155
123
|
options: {
|
|
156
124
|
autoplay: e.current.autoplay,
|
|
157
|
-
wrapAround: e.current.wrapAround &&
|
|
125
|
+
wrapAround: e.current.wrapAround && m.current.length > e.current.cellsPerSlide,
|
|
158
126
|
showPagination: e.current.showPagination,
|
|
159
127
|
delay: e.current.autoplayDelay,
|
|
160
128
|
slideGutterSize: e.current.gutterSize,
|
|
161
129
|
slideAspectRatio: e.current.slideAspectRatio,
|
|
162
|
-
showControls: e.current.showControls &&
|
|
130
|
+
showControls: e.current.showControls && m.current.length > e.current.cellsPerSlide,
|
|
163
131
|
cellsPerSlide: e.current.cellsPerSlide
|
|
164
132
|
}
|
|
165
133
|
});
|
|
166
|
-
}, [
|
|
167
|
-
|
|
168
|
-
}, [
|
|
169
|
-
if (
|
|
170
|
-
let
|
|
171
|
-
|
|
134
|
+
}, [D]), V = d(() => {
|
|
135
|
+
i.current.addEventListener("scroll", v, { once: !0 });
|
|
136
|
+
}, [v]), j = d(() => {
|
|
137
|
+
if (G(O(m.current, e.current.cellsPerSlide)), m.current.length > e.current.cellsPerSlide) {
|
|
138
|
+
let t = setInterval(() => {
|
|
139
|
+
i.current !== null && (S.current !== null && e.current.showControls || !e.current.showControls) && (clearInterval(t), V(), y());
|
|
172
140
|
}, 100);
|
|
173
141
|
} else {
|
|
174
|
-
let
|
|
175
|
-
|
|
142
|
+
let t = setInterval(() => {
|
|
143
|
+
i.current !== null && (clearInterval(t), y());
|
|
176
144
|
}, 100);
|
|
177
145
|
}
|
|
178
|
-
}, [
|
|
179
|
-
return
|
|
180
|
-
if (
|
|
181
|
-
if (
|
|
182
|
-
let
|
|
183
|
-
|
|
146
|
+
}, [O, V, y]);
|
|
147
|
+
return B(() => {
|
|
148
|
+
if (e.current !== null) {
|
|
149
|
+
if (e.current.showControls) {
|
|
150
|
+
let t = 0;
|
|
151
|
+
e.current.showPagination && (t = t + 25), e.current.showScrollbar && (t = t + 6), N.current = `calc(-50% - ${t}px)`;
|
|
184
152
|
}
|
|
185
|
-
|
|
153
|
+
j();
|
|
186
154
|
}
|
|
187
155
|
return () => {
|
|
188
|
-
|
|
156
|
+
q();
|
|
189
157
|
};
|
|
190
|
-
}, [
|
|
158
|
+
}, [j, e]), /* @__PURE__ */ o(X, { children: e.current !== null && /* @__PURE__ */ K(
|
|
191
159
|
"div",
|
|
192
160
|
{
|
|
193
|
-
className:
|
|
194
|
-
id:
|
|
195
|
-
ref:
|
|
161
|
+
className: a.carousel,
|
|
162
|
+
id: p.current,
|
|
163
|
+
ref: R,
|
|
196
164
|
tabIndex: -1,
|
|
197
165
|
role: "region",
|
|
198
166
|
"aria-roledescription": "carousel",
|
|
199
|
-
"aria-label":
|
|
200
|
-
onKeyDown:
|
|
167
|
+
"aria-label": e.current.title,
|
|
168
|
+
onKeyDown: F,
|
|
201
169
|
style: {
|
|
202
|
-
"--_carousel-gutters":
|
|
203
|
-
"--_slide-aspect-ratio":
|
|
204
|
-
"--_cell-aspect-ratio":
|
|
205
|
-
"--_slide-cell-size": `${100 /
|
|
206
|
-
"--_cells-position":
|
|
207
|
-
"--_control-btns-offset-x": `${
|
|
208
|
-
"--_slide-gap": `${
|
|
209
|
-
"--_controls-transform":
|
|
170
|
+
"--_carousel-gutters": e.current.wrapAround ? `${e.current.gutterSize <= 25 ? e.current.gutterSize : 25}%` : `0 ${e.current.gutterSize <= 25 ? e.current.gutterSize : 25}%`,
|
|
171
|
+
"--_slide-aspect-ratio": e.current.slideAspectRatio,
|
|
172
|
+
"--_cell-aspect-ratio": e.current.cellAspectRatio,
|
|
173
|
+
"--_slide-cell-size": `${100 / e.current.cellsPerSlide}%`,
|
|
174
|
+
"--_cells-position": e.current.cellsPosition,
|
|
175
|
+
"--_control-btns-offset-x": `${e.current.controlButtonsOffset}rem`,
|
|
176
|
+
"--_slide-gap": `${e.current.slideGap}rem`,
|
|
177
|
+
"--_controls-transform": N.current
|
|
210
178
|
},
|
|
211
179
|
children: [
|
|
212
|
-
/* @__PURE__ */
|
|
180
|
+
/* @__PURE__ */ o(
|
|
213
181
|
"ol",
|
|
214
182
|
{
|
|
215
|
-
className:
|
|
216
|
-
ref:
|
|
183
|
+
className: a.carousel__scroller,
|
|
184
|
+
ref: i,
|
|
217
185
|
role: "group",
|
|
218
186
|
"aria-label": "Items Scroller",
|
|
219
187
|
"aria-live": "Polite",
|
|
@@ -224,29 +192,29 @@ function pe({
|
|
|
224
192
|
onMouseLeave: () => {
|
|
225
193
|
e.current.autoplay && r.current !== null && r.current.startTimer();
|
|
226
194
|
},
|
|
227
|
-
onTouchStart:
|
|
228
|
-
"data-scrollbar":
|
|
229
|
-
children:
|
|
230
|
-
|
|
195
|
+
onTouchStart: W,
|
|
196
|
+
"data-scrollbar": e.current.showScrollbar,
|
|
197
|
+
children: M.length > 0 && M.map((t, n) => /* @__PURE__ */ o(
|
|
198
|
+
Z,
|
|
231
199
|
{
|
|
232
|
-
slide:
|
|
233
|
-
index:
|
|
234
|
-
currentIndex:
|
|
235
|
-
variableHeight:
|
|
200
|
+
slide: t,
|
|
201
|
+
index: n,
|
|
202
|
+
currentIndex: e.current.wrapAround ? 1 : 0,
|
|
203
|
+
variableHeight: e.current.variableHeight
|
|
236
204
|
},
|
|
237
|
-
`carousel${
|
|
205
|
+
`carousel${g}-slide${n}`
|
|
238
206
|
))
|
|
239
207
|
}
|
|
240
208
|
),
|
|
241
|
-
|
|
242
|
-
/* @__PURE__ */
|
|
209
|
+
e.current.showControls && x.length > e.current.cellsPerSlide && /* @__PURE__ */ K("div", { className: a["carousel-controls"], children: [
|
|
210
|
+
/* @__PURE__ */ o(
|
|
243
211
|
"button",
|
|
244
212
|
{
|
|
245
213
|
type: "button",
|
|
246
|
-
ref:
|
|
214
|
+
ref: S,
|
|
247
215
|
title: "Previous Item",
|
|
248
|
-
className:
|
|
249
|
-
"aria-controls":
|
|
216
|
+
className: _([a["carousel-controls__btn"], a["carousel-controls__previous"], "carousel-controls__previous"]),
|
|
217
|
+
"aria-controls": p.current,
|
|
250
218
|
"aria-label": "Previous Item",
|
|
251
219
|
onClick: () => {
|
|
252
220
|
r.current.determineScrollAction(-1);
|
|
@@ -257,17 +225,17 @@ function pe({
|
|
|
257
225
|
onMouseLeave: () => {
|
|
258
226
|
e.current.autoplay && r.current !== null && r.current.startTimer();
|
|
259
227
|
},
|
|
260
|
-
children: /* @__PURE__ */
|
|
228
|
+
children: /* @__PURE__ */ o("i", { "aria-hidden": "true", children: /* @__PURE__ */ o(re, { width: e.current.controlArrowSize, height: e.current.controlArrowSize }) })
|
|
261
229
|
}
|
|
262
230
|
),
|
|
263
|
-
/* @__PURE__ */
|
|
231
|
+
/* @__PURE__ */ o(
|
|
264
232
|
"button",
|
|
265
233
|
{
|
|
266
234
|
type: "button",
|
|
267
|
-
ref:
|
|
235
|
+
ref: T,
|
|
268
236
|
title: "Next Item",
|
|
269
|
-
className:
|
|
270
|
-
"aria-controls":
|
|
237
|
+
className: _([a["carousel-controls__btn"], a["carousel-controls__next"], "carousel-controls__next"]),
|
|
238
|
+
"aria-controls": p.current,
|
|
271
239
|
"aria-label": "Next Item",
|
|
272
240
|
onClick: () => {
|
|
273
241
|
r.current.determineScrollAction(1);
|
|
@@ -278,27 +246,27 @@ function pe({
|
|
|
278
246
|
onMouseLeave: () => {
|
|
279
247
|
e.current.autoplay && r.current !== null && r.current.startTimer();
|
|
280
248
|
},
|
|
281
|
-
children: /* @__PURE__ */
|
|
249
|
+
children: /* @__PURE__ */ o("i", { "aria-hidden": "true", children: /* @__PURE__ */ o(te, { width: e.current.controlArrowSize, height: e.current.controlArrowSize }) })
|
|
282
250
|
}
|
|
283
251
|
)
|
|
284
252
|
] }),
|
|
285
|
-
|
|
253
|
+
e.current.showPagination && k.length > 1 && /* @__PURE__ */ o("div", { className: [a["carousel-nav"], "carousel-nav"].join(" "), children: /* @__PURE__ */ o("ol", { className: a["carousel-nav__list"], ref: $, children: k.map((t, n) => /* @__PURE__ */ o(
|
|
286
254
|
"li",
|
|
287
255
|
{
|
|
288
|
-
className:
|
|
289
|
-
"data-current":
|
|
256
|
+
className: _([a["carousel-nav__item"], "carousel-nav__item"]),
|
|
257
|
+
"data-current": n === 0 ? "true" : "false",
|
|
290
258
|
onClick: () => {
|
|
291
|
-
r.current.navigateToIndex(
|
|
259
|
+
r.current.navigateToIndex(n);
|
|
292
260
|
},
|
|
293
|
-
title: `Navigate to slide ${
|
|
261
|
+
title: `Navigate to slide ${n + 1}`
|
|
294
262
|
},
|
|
295
|
-
`carousel${
|
|
263
|
+
`carousel${p}-nav-${n}`
|
|
296
264
|
)) }) })
|
|
297
265
|
]
|
|
298
266
|
}
|
|
299
267
|
) });
|
|
300
268
|
}
|
|
301
269
|
export {
|
|
302
|
-
|
|
303
|
-
|
|
270
|
+
de as Carousel,
|
|
271
|
+
de as default
|
|
304
272
|
};
|
package/package.json
CHANGED