@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.
@@ -1,4 +1,4 @@
1
- import React, { useState, useRef, useEffect, Fragment, createRef, createContext, useContext, useMemo, useCallback } from 'react';
1
+ import React, { useState, useRef, useMemo, useCallback, useEffect, Fragment, createRef, createContext, useContext } from 'react';
2
2
  import Head from 'next/head';
3
3
  import { Box, BoemlyModal, Flex, IconButton, useMediaQuery, DefaultSectionContainer, Wrapper, DefaultSectionHeader, Button, Gradient, Spacer, SimpleGrid, Heading, Text, useToken, Grid, GridItem, BoemlyList, PortfolioCard, RichText, BoemlyAccordion, HeroCard, Shape, QuoteCard, Center, ShapesCard, TextCardWithIcon, ContactArea, ProjectCard, Tag, Link as Link$1, DatePersonPair, BoemlyThemeProvider, Badge, useDisclosure, Container, AvatarWithName, Divider, LabelNumberPair, BoemlyFormControl, InputRightAddon, LabelTextPair } from 'boemly';
4
4
  import Image from 'next/image';
@@ -721,45 +721,50 @@ var FullScreenImage = function FullScreenImage(_ref) {
721
721
  var images = _ref.images,
722
722
  isOpen = _ref.isOpen,
723
723
  onClose = _ref.onClose,
724
- openIndex = _ref.openIndex;
725
- var _useState = useState(0),
726
- imageIndex = _useState[0],
727
- setImageIndex = _useState[1];
724
+ _ref$currentIndex = _ref.currentIndex,
725
+ currentIndex = _ref$currentIndex === void 0 ? 0 : _ref$currentIndex,
726
+ setCurrentIndex = _ref.setCurrentIndex;
728
727
  var containerRef = useRef(null);
729
728
  useLockBodyScroll(isOpen);
730
- var canMoveRight = imageIndex < images.length - 1;
731
- var canMoveLeft = imageIndex !== 0;
732
- var onRight = function onRight() {
733
- return setImageIndex(function (p) {
734
- return canMoveRight ? p + 1 : p;
729
+ var canMoveRight = useMemo(function () {
730
+ return currentIndex < images.length - 1;
731
+ }, [currentIndex, images.length]);
732
+ var canMoveLeft = useMemo(function () {
733
+ return currentIndex !== 0;
734
+ }, [currentIndex]);
735
+ var onRight = useCallback(function () {
736
+ return canMoveRight && setCurrentIndex && setCurrentIndex(function (c) {
737
+ return c + 1;
735
738
  });
736
- };
737
- var onLeft = function onLeft() {
738
- return setImageIndex(function (p) {
739
- return canMoveLeft ? p - 1 : p;
739
+ }, [canMoveRight]);
740
+ var onLeft = useCallback(function () {
741
+ return canMoveLeft && setCurrentIndex && setCurrentIndex(function (c) {
742
+ return c - 1;
740
743
  });
741
- };
744
+ }, [canMoveLeft]);
742
745
  useKey('ArrowRight', onRight, {}, [onRight]);
743
746
  useKey('ArrowLeft', onLeft, {}, [onLeft]);
744
747
  useEffect(function () {
745
- if (openIndex !== undefined) {
746
- setImageIndex(openIndex);
748
+ if (!!isOpen) {
749
+ setTimeout(function () {
750
+ var _containerRef$current;
751
+ containerRef == null || (_containerRef$current = containerRef.current) == null || _containerRef$current.scrollTo({
752
+ left: currentIndex * containerRef.current.clientWidth,
753
+ behavior: 'instant'
754
+ });
755
+ }, 10);
747
756
  }
748
- }, [openIndex]);
757
+ }, [isOpen]);
749
758
  useEffect(function () {
750
759
  if (containerRef.current) {
751
760
  containerRef.current.scrollTo({
752
- left: imageIndex * containerRef.current.clientWidth,
761
+ left: currentIndex * containerRef.current.clientWidth,
753
762
  behavior: 'smooth'
754
763
  });
755
764
  }
756
- }, [imageIndex, containerRef]);
757
- var onCloseLocal = function onCloseLocal() {
758
- setImageIndex(0);
759
- onClose();
760
- };
765
+ }, [currentIndex, containerRef]);
761
766
  return React.createElement(BoemlyModal, {
762
- onClose: onCloseLocal,
767
+ onClose: onClose,
763
768
  isOpen: isOpen,
764
769
  title: "",
765
770
  trigger: "",
@@ -3326,7 +3331,8 @@ var FullWidthImageSlider = function FullWidthImageSlider(_ref) {
3326
3331
  images: slice.images.map(function (image) {
3327
3332
  return image.img;
3328
3333
  }),
3329
- openIndex: sliderIndex,
3334
+ currentIndex: sliderIndex,
3335
+ setCurrentIndex: setSliderIndex,
3330
3336
  isOpen: isOpen,
3331
3337
  onClose: function onClose() {
3332
3338
  return setIsOpen(false);