From c765adca6035e42575c714e926312be565b11c85 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Mon, 8 Apr 2024 11:20:00 +0100 Subject: [PATCH 01/10] Editor: Animate opening and closing editor right sidebar --- .../edit-post/src/components/layout/index.js | 31 +--- .../edit-site/src/components/editor/index.js | 2 - .../components/complementary-area/index.js | 156 +++++++++++------- .../components/interface-skeleton/index.js | 1 - .../components/interface-skeleton/style.scss | 6 +- 5 files changed, 106 insertions(+), 90 deletions(-) diff --git a/packages/edit-post/src/components/layout/index.js b/packages/edit-post/src/components/layout/index.js index 26fbc70f1403fe..6fc9ab570e5ac9 100644 --- a/packages/edit-post/src/components/layout/index.js +++ b/packages/edit-post/src/components/layout/index.js @@ -24,7 +24,7 @@ import { privateApis as blockEditorPrivateApis, store as blockEditorStore, } from '@wordpress/block-editor'; -import { Button, ScrollLock } from '@wordpress/components'; +import { ScrollLock } from '@wordpress/components'; import { useViewportMatch } from '@wordpress/compose'; import { PluginArea } from '@wordpress/plugins'; import { __, _x, sprintf } from '@wordpress/i18n'; @@ -139,8 +139,7 @@ function Layout( { initialPost } ) { const isWideViewport = useViewportMatch( 'large' ); const isLargeViewport = useViewportMatch( 'medium' ); - const { openGeneralSidebar, closeGeneralSidebar } = - useDispatch( editPostStore ); + const { closeGeneralSidebar } = useDispatch( editPostStore ); const { createErrorNotice } = useDispatch( noticesStore ); const { setIsInserterOpened } = useDispatch( editorStore ); const { @@ -206,11 +205,6 @@ function Layout( { initialPost } ) { const styles = useEditorStyles(); - const openSidebarPanel = () => - openGeneralSidebar( - hasBlockSelected ? 'edit-post/block' : 'edit-post/document' - ); - // Inserter and Sidebars are mutually exclusive useEffect( () => { if ( sidebarIsOpened && ! isHugeViewport ) { @@ -313,25 +307,8 @@ function Layout( { initialPost } ) { editorNotices={ } secondarySidebar={ secondarySidebar() } sidebar={ - ( ( isMobileViewport && sidebarIsOpened ) || - ( ! isMobileViewport && ! isDistractionFree ) ) && ( - <> - { ! isMobileViewport && ! sidebarIsOpened && ( -
- -
- ) } - - + ! isDistractionFree && ( + ) } notices={ } diff --git a/packages/edit-site/src/components/editor/index.js b/packages/edit-site/src/components/editor/index.js index f5fdd62ba7dc14..ba04333b985bde 100644 --- a/packages/edit-site/src/components/editor/index.js +++ b/packages/edit-site/src/components/editor/index.js @@ -297,9 +297,7 @@ export default function Editor( { isLoading, onClick } ) { ( shouldShowListView && ) ) } sidebar={ - ! isDistractionFree && isEditMode && - isRightSidebarOpen && ! isDistractionFree && ( ) diff --git a/packages/interface/src/components/complementary-area/index.js b/packages/interface/src/components/complementary-area/index.js index 3e2913b20b18b3..70e17cc484edcc 100644 --- a/packages/interface/src/components/complementary-area/index.js +++ b/packages/interface/src/components/complementary-area/index.js @@ -6,13 +6,21 @@ import classnames from 'classnames'; /** * WordPress dependencies */ -import { Button, Panel, Slot, Fill } from '@wordpress/components'; +import { + Button, + Panel, + Slot, + Fill, + __unstableMotion as motion, + __unstableAnimatePresence as AnimatePresence, +} from '@wordpress/components'; import { useDispatch, useSelect } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; import { check, starEmpty, starFilled } from '@wordpress/icons'; import { useEffect, useRef } from '@wordpress/element'; import { store as viewportStore } from '@wordpress/viewport'; import { store as preferencesStore } from '@wordpress/preferences'; +import { useReducedMotion, useViewportMatch } from '@wordpress/compose'; /** * Internal dependencies @@ -24,16 +32,53 @@ import withComplementaryAreaContext from '../complementary-area-context'; import PinnedItems from '../pinned-items'; import { store as interfaceStore } from '../../store'; +const ANIMATION_DURATION = 0.2; + function ComplementaryAreaSlot( { scope, ...props } ) { return ; } -function ComplementaryAreaFill( { scope, children, className, id } ) { +const SIDEBAR_WIDTH = 280; +const variants = { + open: { width: SIDEBAR_WIDTH }, + closed: { width: 0 }, + mobileOpen: { width: '100vw' }, +}; + +function ComplementaryAreaFill( { isActive, scope, children, className, id } ) { + const disableMotion = useReducedMotion(); + const isMobileViewport = useViewportMatch( 'medium', '<' ); + const defaultTransition = { + type: 'tween', + duration: disableMotion || isMobileViewport ? 0 : ANIMATION_DURATION, + ease: 'easeOut', + }; + return ( -
- { children } -
+ + { isActive && ( + +
+ { children } +
+
+ ) } +
); } @@ -204,59 +249,56 @@ function ComplementaryArea( { { title } ) } - { isActive && ( - + disableComplementaryArea( scope ) } + smallScreenTitle={ smallScreenTitle } + toggleButtonProps={ { + label: closeLabel, + shortcut: toggleShortcut, + scope, + identifier, + } } > - disableComplementaryArea( scope ) } - smallScreenTitle={ smallScreenTitle } - toggleButtonProps={ { - label: closeLabel, - shortcut: toggleShortcut, - scope, - identifier, - } } - > - { header || ( - <> -

- { title } -

- { isPinnable && ( -