mirror of
https://github.com/WenPai-org/wpmind.git
synced 2025-08-03 11:11:27 +08:00
added transition for modal to smooth change to fullscreen
This commit is contained in:
parent
2616bf0af7
commit
f97fb9fdf6
2 changed files with 44 additions and 4 deletions
|
@ -6,7 +6,7 @@ import './style.scss';
|
||||||
/**
|
/**
|
||||||
* WordPress dependencies
|
* WordPress dependencies
|
||||||
*/
|
*/
|
||||||
import { createRoot } from '@wordpress/element';
|
import { createRoot, useEffect, useState, useRef } from '@wordpress/element';
|
||||||
import { Modal } from '@wordpress/components';
|
import { Modal } from '@wordpress/components';
|
||||||
import { useSelect, useDispatch } from '@wordpress/data';
|
import { useSelect, useDispatch } from '@wordpress/data';
|
||||||
import domReady from '@wordpress/dom-ready';
|
import domReady from '@wordpress/dom-ready';
|
||||||
|
@ -20,7 +20,6 @@ import LoadingLine from './components/loading-line';
|
||||||
import Content from './components/content';
|
import Content from './components/content';
|
||||||
import Footer from './components/footer';
|
import Footer from './components/footer';
|
||||||
import NotConnectedScreen from './components/not-connected-screen';
|
import NotConnectedScreen from './components/not-connected-screen';
|
||||||
import hasNonEmptySelectedBlocks from '../../utils/has-non-empty-selected-blocks';
|
|
||||||
|
|
||||||
const POPUP_CONTAINER_CLASS = 'mind-popup-container';
|
const POPUP_CONTAINER_CLASS = 'mind-popup-container';
|
||||||
|
|
||||||
|
@ -28,6 +27,10 @@ export default function Popup() {
|
||||||
const { setHighlightBlocks } = useDispatch('mind/blocks');
|
const { setHighlightBlocks } = useDispatch('mind/blocks');
|
||||||
const { close, reset } = useDispatch('mind/popup');
|
const { close, reset } = useDispatch('mind/popup');
|
||||||
|
|
||||||
|
const [isFullscreen, setIsFullscreen] = useState(false);
|
||||||
|
const [fullScreenTransitionStyles, setFullScreenTransitionStyles] =
|
||||||
|
useState(null);
|
||||||
|
|
||||||
const { connected, isOpen, insertionPlace, loading, response } = useSelect(
|
const { connected, isOpen, insertionPlace, loading, response } = useSelect(
|
||||||
(select) => {
|
(select) => {
|
||||||
const { isConnected } = select('mind');
|
const { isConnected } = select('mind');
|
||||||
|
@ -58,6 +61,39 @@ export default function Popup() {
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// Change modal size with transition.
|
||||||
|
const modalRef = useRef();
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isOpen || !modalRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const allowTransition =
|
||||||
|
// Set fullscreen true.
|
||||||
|
((loading || response?.length) &&
|
||||||
|
!isFullscreen &&
|
||||||
|
!fullScreenTransitionStyles) ||
|
||||||
|
// Set fullscreen false.
|
||||||
|
(!(loading || response?.length) &&
|
||||||
|
isFullscreen &&
|
||||||
|
!fullScreenTransitionStyles);
|
||||||
|
|
||||||
|
if (!allowTransition) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { height } = modalRef.current.children[0].getBoundingClientRect();
|
||||||
|
|
||||||
|
setFullScreenTransitionStyles({
|
||||||
|
height: `${height}px`,
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
setFullScreenTransitionStyles(null);
|
||||||
|
setIsFullscreen(!isFullscreen);
|
||||||
|
}, 10);
|
||||||
|
}, [isFullscreen, loading, response, isOpen, fullScreenTransitionStyles]);
|
||||||
|
|
||||||
const { insertBlocks: wpInsertBlocks, replaceBlocks } =
|
const { insertBlocks: wpInsertBlocks, replaceBlocks } =
|
||||||
useDispatch('core/block-editor');
|
useDispatch('core/block-editor');
|
||||||
|
|
||||||
|
@ -96,6 +132,7 @@ export default function Popup() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
|
ref={modalRef}
|
||||||
title={false}
|
title={false}
|
||||||
className={clsx(
|
className={clsx(
|
||||||
'mind-popup',
|
'mind-popup',
|
||||||
|
@ -106,7 +143,8 @@ export default function Popup() {
|
||||||
reset();
|
reset();
|
||||||
close();
|
close();
|
||||||
}}
|
}}
|
||||||
isFullScreen={loading || response?.length}
|
isFullScreen={isFullscreen}
|
||||||
|
style={fullScreenTransitionStyles}
|
||||||
__experimentalHideHeader
|
__experimentalHideHeader
|
||||||
>
|
>
|
||||||
{connected ? (
|
{connected ? (
|
||||||
|
|
|
@ -5,10 +5,12 @@ $padding: 10px;
|
||||||
position: relative;
|
position: relative;
|
||||||
top: 15%;
|
top: 15%;
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
width: 550px;
|
width: 650px;
|
||||||
max-height: clamp(0px, 440px, 75vh);
|
max-height: clamp(0px, 440px, 75vh);
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
color: #000;
|
color: #000;
|
||||||
|
will-change: width, height, top;
|
||||||
|
transition: 0.3s width ease-in-out, 0.3s height ease-in-out, 0.3s top ease-in-out;
|
||||||
|
|
||||||
&.is-full-screen {
|
&.is-full-screen {
|
||||||
top: 40px;
|
top: 40px;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue