From ff08eb94d5f0bfefa6ac33ba4d03862479277989 Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Mon, 5 Jun 2023 16:38:57 +1000 Subject: [PATCH 1/3] DocumentActions: Animate between page and template mode --- .../document-actions/index.js | 44 ++++++++++----- .../document-actions/style.scss | 53 ++++++++++++++++--- 2 files changed, 79 insertions(+), 18 deletions(-) diff --git a/packages/edit-site/src/components/header-edit-mode/document-actions/index.js b/packages/edit-site/src/components/header-edit-mode/document-actions/index.js index 5f14445ccefcd8..e04b59a55337b5 100644 --- a/packages/edit-site/src/components/header-edit-mode/document-actions/index.js +++ b/packages/edit-site/src/components/header-edit-mode/document-actions/index.js @@ -22,6 +22,7 @@ import { } from '@wordpress/icons'; import { useEntityRecord } from '@wordpress/core-data'; import { displayShortcut } from '@wordpress/keycodes'; +import { useState, useEffect, useRef } from '@wordpress/element'; /** * Internal dependencies @@ -51,6 +52,15 @@ function PageDocumentActions() { const { setHasPageContentLock } = useDispatch( editSiteStore ); + const [ hasEditedTemplate, setHasEditedTemplate ] = useState( false ); + const prevHasPageContentLock = useRef( false ); + useEffect( () => { + if ( prevHasPageContentLock.current && ! hasPageContentLock ) { + setHasEditedTemplate( true ); + } + prevHasPageContentLock.current = hasPageContentLock; + }, [ hasPageContentLock ] ); + if ( ! hasResolved ) { return null; } @@ -64,17 +74,26 @@ function PageDocumentActions() { } return hasPageContentLock ? ( - + { editedRecord.title } ) : ( setHasPageContentLock( true ) } + className="is-animated" + onBack={ () => { + setHasEditedTemplate( true ); + setHasPageContentLock( true ); + } } /> ); } -function TemplateDocumentActions( { onBack } ) { +function TemplateDocumentActions( { className, onBack } ) { const { isLoaded, record, getTitle, icon } = useEditedEntityRecord(); if ( ! isLoaded ) { @@ -95,7 +114,11 @@ function TemplateDocumentActions( { onBack } ) { : __( 'template' ); return ( - + { sprintf( /* translators: %s: the entity being edited, like "template"*/ @@ -108,10 +131,12 @@ function TemplateDocumentActions( { onBack } ) { ); } -function BaseDocumentActions( { icon, children, onBack, isPage = false } ) { +function BaseDocumentActions( { className, icon, children, onBack } ) { const { open: openCommandCenter } = useDispatch( commandsStore ); return ( -
+
{ onBack && (