@treely/strapi-slices 6.1.1 → 6.2.0
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 +19 -1
- 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 +19 -1
- package/dist/strapi-slices.esm.js.map +1 -1
- package/dist/utils/shuffleElements.d.ts +2 -0
- package/package.json +1 -1
- package/src/slices/TextCarousel/TextCarousel.stories.tsx +9 -0
- package/src/slices/TextCarousel/TextCarousel.tsx +9 -1
- 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) {
|
|
@@ -2579,6 +2590,13 @@ var TextCarousel = function TextCarousel(_ref) {
|
|
|
2579
2590
|
var canMoveLeft = React.useMemo(function () {
|
|
2580
2591
|
return sliderIndex !== 0;
|
|
2581
2592
|
}, [sliderIndex]);
|
|
2593
|
+
var shuffleSlides = React.useMemo(function () {
|
|
2594
|
+
return shuffleElements(slice.slides);
|
|
2595
|
+
}, [slice.slides]);
|
|
2596
|
+
var slides = slice.slides,
|
|
2597
|
+
_slice$isShuffled = slice.isShuffled,
|
|
2598
|
+
isShuffled = _slice$isShuffled === void 0 ? false : _slice$isShuffled;
|
|
2599
|
+
var displaySlides = isShuffled ? shuffleSlides : slides;
|
|
2582
2600
|
return React__default.default.createElement(boemly.DefaultSectionContainer, {
|
|
2583
2601
|
backgroundColor: primary50,
|
|
2584
2602
|
title: slice.title
|
|
@@ -2613,7 +2631,7 @@ var TextCarousel = function TextCarousel(_ref) {
|
|
|
2613
2631
|
duration: 0.3,
|
|
2614
2632
|
ease: 'easeInOut'
|
|
2615
2633
|
}
|
|
2616
|
-
},
|
|
2634
|
+
}, displaySlides.map(function (_ref2) {
|
|
2617
2635
|
var id = _ref2.id,
|
|
2618
2636
|
title = _ref2.title,
|
|
2619
2637
|
text = _ref2.text,
|