@treely/strapi-slices 6.1.1 → 6.2.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/slices/TextCarousel/TextCarousel.d.ts +1 -0
- package/dist/slices/TextCarousel/TextCarousel.stories.d.ts +1 -0
- package/dist/strapi-slices.cjs.development.js +26 -4
- package/dist/strapi-slices.cjs.development.js.map +1 -1
- package/dist/strapi-slices.cjs.production.min.js +1 -1
- package/dist/strapi-slices.cjs.production.min.js.map +1 -1
- package/dist/strapi-slices.esm.js +26 -4
- package/dist/strapi-slices.esm.js.map +1 -1
- package/dist/utils/shuffleElements.d.ts +2 -0
- package/package.json +2 -2
- package/src/slices/TextCarousel/TextCarousel.stories.tsx +9 -0
- package/src/slices/TextCarousel/TextCarousel.tsx +13 -2
- package/src/utils/shuffleElements.test.ts +30 -0
- package/src/utils/shuffleElements.ts +10 -0
|
@@ -5,6 +5,7 @@ import StrapiTextCardWithIcon from '../../models/strapi/StrapiTextCardWithIcons'
|
|
|
5
5
|
interface TextCarouselSlice extends StrapiDefaultHeader {
|
|
6
6
|
slides: StrapiTextCardWithIcon[];
|
|
7
7
|
button?: StrapiLink;
|
|
8
|
+
isShuffled?: boolean;
|
|
8
9
|
}
|
|
9
10
|
export interface TextCarouselProps {
|
|
10
11
|
slice: TextCarouselSlice;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
declare const _default: import("@storybook/types").ComponentAnnotations<import("@storybook/react/dist/types-0fc72a6d").R, import("./TextCarousel").TextCarouselProps>;
|
|
2
2
|
export default _default;
|
|
3
3
|
export declare const Minimal: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0fc72a6d").R, import("./TextCarousel").TextCarouselProps>;
|
|
4
|
+
export declare const WithShuffledCards: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0fc72a6d").R, import("./TextCarousel").TextCarouselProps>;
|
|
4
5
|
export declare const WithTagline: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0fc72a6d").R, import("./TextCarousel").TextCarouselProps>;
|
|
5
6
|
export declare const WithTaglineAndText: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0fc72a6d").R, import("./TextCarousel").TextCarouselProps>;
|
|
6
7
|
export declare const WithButton: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0fc72a6d").R, import("./TextCarousel").TextCarouselProps>;
|
|
@@ -2541,6 +2541,17 @@ var ContextProvider = function ContextProvider(_ref) {
|
|
|
2541
2541
|
}, children));
|
|
2542
2542
|
};
|
|
2543
2543
|
|
|
2544
|
+
var shuffleElements = function shuffleElements(slides) {
|
|
2545
|
+
var slidesCopy = [].concat(slides); // Create a copy to avoid mutating the original array
|
|
2546
|
+
for (var i = slidesCopy.length - 1; i > 0; i--) {
|
|
2547
|
+
var j = Math.floor(Math.random() * (i + 1));
|
|
2548
|
+
var _ref = [slidesCopy[j], slidesCopy[i]];
|
|
2549
|
+
slidesCopy[i] = _ref[0];
|
|
2550
|
+
slidesCopy[j] = _ref[1];
|
|
2551
|
+
}
|
|
2552
|
+
return slidesCopy;
|
|
2553
|
+
};
|
|
2554
|
+
|
|
2544
2555
|
var ITEM_GAP$1 = 24;
|
|
2545
2556
|
var MAX_OFFSET_RIGHT$1 = 55;
|
|
2546
2557
|
var TextCarousel = function TextCarousel(_ref) {
|
|
@@ -2557,9 +2568,12 @@ var TextCarousel = function TextCarousel(_ref) {
|
|
|
2557
2568
|
windowWidth = _useWindowSize.width;
|
|
2558
2569
|
var _useRouter = router.useRouter(),
|
|
2559
2570
|
push = _useRouter.push;
|
|
2560
|
-
var _useState = React.useState(
|
|
2561
|
-
|
|
2562
|
-
|
|
2571
|
+
var _useState = React.useState(slice.slides),
|
|
2572
|
+
displaySlides = _useState[0],
|
|
2573
|
+
setDisplaySlides = _useState[1];
|
|
2574
|
+
var _useState2 = React.useState(0),
|
|
2575
|
+
sliderIndex = _useState2[0],
|
|
2576
|
+
setSliderIndex = _useState2[1];
|
|
2563
2577
|
var numberOfItems = React.useMemo(function () {
|
|
2564
2578
|
return slice.slides.length;
|
|
2565
2579
|
}, [slice.slides.length]);
|
|
@@ -2579,6 +2593,14 @@ var TextCarousel = function TextCarousel(_ref) {
|
|
|
2579
2593
|
var canMoveLeft = React.useMemo(function () {
|
|
2580
2594
|
return sliderIndex !== 0;
|
|
2581
2595
|
}, [sliderIndex]);
|
|
2596
|
+
var slides = slice.slides,
|
|
2597
|
+
_slice$isShuffled = slice.isShuffled,
|
|
2598
|
+
isShuffled = _slice$isShuffled === void 0 ? false : _slice$isShuffled;
|
|
2599
|
+
React.useEffect(function () {
|
|
2600
|
+
if (isShuffled && typeof window === 'undefined') {
|
|
2601
|
+
setDisplaySlides(shuffleElements(slides));
|
|
2602
|
+
}
|
|
2603
|
+
}, [slides, isShuffled]);
|
|
2582
2604
|
return React__default.default.createElement(boemly.DefaultSectionContainer, {
|
|
2583
2605
|
backgroundColor: primary50,
|
|
2584
2606
|
title: slice.title
|
|
@@ -2613,7 +2635,7 @@ var TextCarousel = function TextCarousel(_ref) {
|
|
|
2613
2635
|
duration: 0.3,
|
|
2614
2636
|
ease: 'easeInOut'
|
|
2615
2637
|
}
|
|
2616
|
-
},
|
|
2638
|
+
}, displaySlides.map(function (_ref2) {
|
|
2617
2639
|
var id = _ref2.id,
|
|
2618
2640
|
title = _ref2.title,
|
|
2619
2641
|
text = _ref2.text,
|