@treely/strapi-slices 5.3.2 → 5.3.3

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.
@@ -4,6 +4,7 @@ export interface FullScreenImageProps {
4
4
  images: StrapiImage[];
5
5
  isOpen: boolean;
6
6
  onClose: () => void;
7
- openIndex?: number;
7
+ currentIndex?: number;
8
+ setCurrentIndex?: (callback: (c: number) => number) => void;
8
9
  }
9
- export declare const FullScreenImage: ({ images, isOpen, onClose, openIndex, }: FullScreenImageProps) => React.JSX.Element;
10
+ export declare const FullScreenImage: ({ images, isOpen, onClose, currentIndex, setCurrentIndex, }: FullScreenImageProps) => React.JSX.Element;
@@ -734,45 +734,50 @@ var FullScreenImage = function FullScreenImage(_ref) {
734
734
  var images = _ref.images,
735
735
  isOpen = _ref.isOpen,
736
736
  onClose = _ref.onClose,
737
- openIndex = _ref.openIndex;
738
- var _useState = React.useState(0),
739
- imageIndex = _useState[0],
740
- setImageIndex = _useState[1];
737
+ _ref$currentIndex = _ref.currentIndex,
738
+ currentIndex = _ref$currentIndex === void 0 ? 0 : _ref$currentIndex,
739
+ setCurrentIndex = _ref.setCurrentIndex;
741
740
  var containerRef = React.useRef(null);
742
741
  reactUse.useLockBodyScroll(isOpen);
743
- var canMoveRight = imageIndex < images.length - 1;
744
- var canMoveLeft = imageIndex !== 0;
745
- var onRight = function onRight() {
746
- return setImageIndex(function (p) {
747
- return canMoveRight ? p + 1 : p;
742
+ var canMoveRight = React.useMemo(function () {
743
+ return currentIndex < images.length - 1;
744
+ }, [currentIndex, images.length]);
745
+ var canMoveLeft = React.useMemo(function () {
746
+ return currentIndex !== 0;
747
+ }, [currentIndex]);
748
+ var onRight = React.useCallback(function () {
749
+ return canMoveRight && setCurrentIndex && setCurrentIndex(function (c) {
750
+ return c + 1;
748
751
  });
749
- };
750
- var onLeft = function onLeft() {
751
- return setImageIndex(function (p) {
752
- return canMoveLeft ? p - 1 : p;
752
+ }, [canMoveRight]);
753
+ var onLeft = React.useCallback(function () {
754
+ return canMoveLeft && setCurrentIndex && setCurrentIndex(function (c) {
755
+ return c - 1;
753
756
  });
754
- };
757
+ }, [canMoveLeft]);
755
758
  reactUse.useKey('ArrowRight', onRight, {}, [onRight]);
756
759
  reactUse.useKey('ArrowLeft', onLeft, {}, [onLeft]);
757
760
  React.useEffect(function () {
758
- if (openIndex !== undefined) {
759
- setImageIndex(openIndex);
761
+ if (!!isOpen) {
762
+ setTimeout(function () {
763
+ var _containerRef$current;
764
+ containerRef == null || (_containerRef$current = containerRef.current) == null || _containerRef$current.scrollTo({
765
+ left: currentIndex * containerRef.current.clientWidth,
766
+ behavior: 'instant'
767
+ });
768
+ }, 10);
760
769
  }
761
- }, [openIndex]);
770
+ }, [isOpen]);
762
771
  React.useEffect(function () {
763
772
  if (containerRef.current) {
764
773
  containerRef.current.scrollTo({
765
- left: imageIndex * containerRef.current.clientWidth,
774
+ left: currentIndex * containerRef.current.clientWidth,
766
775
  behavior: 'smooth'
767
776
  });
768
777
  }
769
- }, [imageIndex, containerRef]);
770
- var onCloseLocal = function onCloseLocal() {
771
- setImageIndex(0);
772
- onClose();
773
- };
778
+ }, [currentIndex, containerRef]);
774
779
  return React__default.default.createElement(boemly.BoemlyModal, {
775
- onClose: onCloseLocal,
780
+ onClose: onClose,
776
781
  isOpen: isOpen,
777
782
  title: "",
778
783
  trigger: "",
@@ -3339,7 +3344,8 @@ var FullWidthImageSlider = function FullWidthImageSlider(_ref) {
3339
3344
  images: slice.images.map(function (image) {
3340
3345
  return image.img;
3341
3346
  }),
3342
- openIndex: sliderIndex,
3347
+ currentIndex: sliderIndex,
3348
+ setCurrentIndex: setSliderIndex,
3343
3349
  isOpen: isOpen,
3344
3350
  onClose: function onClose() {
3345
3351
  return setIsOpen(false);