mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
disabled keyboard while modal active
This commit is contained in:
parent
c49873a0e8
commit
ddbd51f534
2 changed files with 17 additions and 6 deletions
|
@ -1,11 +1,13 @@
|
||||||
import React, { FC, useCallback, useEffect, useState } from 'react';
|
import React, { FC, useCallback, useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
import { observer } from 'mobx-react-lite';
|
||||||
import SwiperCore, { Keyboard, Navigation, Pagination, SwiperOptions } from 'swiper';
|
import SwiperCore, { Keyboard, Navigation, Pagination, SwiperOptions } from 'swiper';
|
||||||
import { Swiper, SwiperSlide } from 'swiper/react';
|
import { Swiper, SwiperSlide } from 'swiper/react';
|
||||||
import SwiperClass from 'swiper/types/swiper-class';
|
import SwiperClass from 'swiper/types/swiper-class';
|
||||||
|
|
||||||
import { ImagePreloader } from '~/components/media/ImagePreloader';
|
import { ImagePreloader } from '~/components/media/ImagePreloader';
|
||||||
import { INodeComponentProps } from '~/constants/node';
|
import { INodeComponentProps } from '~/constants/node';
|
||||||
|
import { useModal } from '~/hooks/modal/useModal';
|
||||||
import { useImageModal } from '~/hooks/navigation/useImageModal';
|
import { useImageModal } from '~/hooks/navigation/useImageModal';
|
||||||
import { useNodeImages } from '~/hooks/node/useNodeImages';
|
import { useNodeImages } from '~/hooks/node/useNodeImages';
|
||||||
import { normalizeBrightColor } from '~/utils/color';
|
import { normalizeBrightColor } from '~/utils/color';
|
||||||
|
@ -22,9 +24,10 @@ const breakpoints: SwiperOptions['breakpoints'] = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const NodeImageSwiperBlock: FC<IProps> = ({ node }) => {
|
const NodeImageSwiperBlock: FC<IProps> = observer(({ node }) => {
|
||||||
const [controlledSwiper, setControlledSwiper] = useState<SwiperClass | undefined>(undefined);
|
const [controlledSwiper, setControlledSwiper] = useState<SwiperClass | undefined>(undefined);
|
||||||
const showPhotoSwiper = useImageModal();
|
const showPhotoSwiper = useImageModal();
|
||||||
|
const { isOpened: isModalActive } = useModal();
|
||||||
|
|
||||||
const images = useNodeImages(node);
|
const images = useNodeImages(node);
|
||||||
|
|
||||||
|
@ -71,6 +74,14 @@ const NodeImageSwiperBlock: FC<IProps> = ({ node }) => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isModalActive) {
|
||||||
|
controlledSwiper?.keyboard.disable();
|
||||||
|
} else {
|
||||||
|
controlledSwiper?.keyboard.enable();
|
||||||
|
}
|
||||||
|
}, [isModalActive]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.wrapper}>
|
<div className={styles.wrapper}>
|
||||||
<Swiper
|
<Swiper
|
||||||
|
@ -88,8 +99,8 @@ const NodeImageSwiperBlock: FC<IProps> = ({ node }) => {
|
||||||
watchOverflow
|
watchOverflow
|
||||||
updateOnImagesReady
|
updateOnImagesReady
|
||||||
keyboard={{
|
keyboard={{
|
||||||
enabled: true,
|
enabled: !isModalActive,
|
||||||
onlyInViewport: false,
|
onlyInViewport: true,
|
||||||
}}
|
}}
|
||||||
grabCursor
|
grabCursor
|
||||||
autoHeight
|
autoHeight
|
||||||
|
@ -110,6 +121,6 @@ const NodeImageSwiperBlock: FC<IProps> = ({ node }) => {
|
||||||
</Swiper>
|
</Swiper>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
});
|
||||||
|
|
||||||
export { NodeImageSwiperBlock };
|
export { NodeImageSwiperBlock };
|
||||||
|
|
|
@ -15,7 +15,7 @@ export type DialogContentProps = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useModal = () => {
|
export const useModal = () => {
|
||||||
const { setCurrent, hide } = useModalStore();
|
const { setCurrent, hide, current } = useModalStore();
|
||||||
|
|
||||||
const showModal = useCallback(
|
const showModal = useCallback(
|
||||||
<T extends Dialog>(dialog: T, props: DialogContentProps[T]) => {
|
<T extends Dialog>(dialog: T, props: DialogContentProps[T]) => {
|
||||||
|
@ -24,5 +24,5 @@ export const useModal = () => {
|
||||||
[setCurrent]
|
[setCurrent]
|
||||||
);
|
);
|
||||||
|
|
||||||
return { showModal, hideModal: hide };
|
return { showModal, hideModal: hide, current, isOpened: !!current };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue