Skip to content

Commit e393252

Browse files
noisysocksSaxonF
authored andcommitted
DocumentActions: Animate between page and template mode (WordPress#51224)
* DocumentActions: Animate between page and template mode * Remove unnecessary setHasEditedTemplate() * refine toolbar animation --------- Co-authored-by: Saxon Fletcher <[email protected]>
1 parent 1135692 commit e393252

File tree

2 files changed

+75
-17
lines changed

2 files changed

+75
-17
lines changed

packages/edit-site/src/components/header-edit-mode/document-actions/index.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
} from '@wordpress/icons';
2323
import { useEntityRecord } from '@wordpress/core-data';
2424
import { displayShortcut } from '@wordpress/keycodes';
25+
import { useState, useEffect, useRef } from '@wordpress/element';
2526

2627
/**
2728
* Internal dependencies
@@ -51,6 +52,15 @@ function PageDocumentActions() {
5152

5253
const { setHasPageContentLock } = useDispatch( editSiteStore );
5354

55+
const [ hasEditedTemplate, setHasEditedTemplate ] = useState( false );
56+
const prevHasPageContentLock = useRef( false );
57+
useEffect( () => {
58+
if ( prevHasPageContentLock.current && ! hasPageContentLock ) {
59+
setHasEditedTemplate( true );
60+
}
61+
prevHasPageContentLock.current = hasPageContentLock;
62+
}, [ hasPageContentLock ] );
63+
5464
if ( ! hasResolved ) {
5565
return null;
5666
}
@@ -64,17 +74,23 @@ function PageDocumentActions() {
6474
}
6575

6676
return hasPageContentLock ? (
67-
<BaseDocumentActions isPage icon={ pageIcon }>
77+
<BaseDocumentActions
78+
className={ classnames( 'is-page', {
79+
'is-animated': hasEditedTemplate,
80+
} ) }
81+
icon={ pageIcon }
82+
>
6883
{ editedRecord.title }
6984
</BaseDocumentActions>
7085
) : (
7186
<TemplateDocumentActions
87+
className="is-animated"
7288
onBack={ () => setHasPageContentLock( true ) }
7389
/>
7490
);
7591
}
7692

77-
function TemplateDocumentActions( { onBack } ) {
93+
function TemplateDocumentActions( { className, onBack } ) {
7894
const { isLoaded, record, getTitle, icon } = useEditedEntityRecord();
7995

8096
if ( ! isLoaded ) {
@@ -95,7 +111,11 @@ function TemplateDocumentActions( { onBack } ) {
95111
: __( 'template' );
96112

97113
return (
98-
<BaseDocumentActions icon={ icon } onBack={ onBack }>
114+
<BaseDocumentActions
115+
className={ className }
116+
icon={ icon }
117+
onBack={ onBack }
118+
>
99119
<VisuallyHidden as="span">
100120
{ sprintf(
101121
/* translators: %s: the entity being edited, like "template"*/
@@ -108,10 +128,12 @@ function TemplateDocumentActions( { onBack } ) {
108128
);
109129
}
110130

111-
function BaseDocumentActions( { icon, children, onBack, isPage = false } ) {
131+
function BaseDocumentActions( { className, icon, children, onBack } ) {
112132
const { open: openCommandCenter } = useDispatch( commandsStore );
113133
return (
114-
<div className="edit-site-document-actions">
134+
<div
135+
className={ classnames( 'edit-site-document-actions', className ) }
136+
>
115137
{ onBack && (
116138
<Button
117139
className="edit-site-document-actions__back"
@@ -129,14 +151,9 @@ function BaseDocumentActions( { icon, children, onBack, isPage = false } ) {
129151
onClick={ () => openCommandCenter() }
130152
>
131153
<HStack
154+
className="edit-site-document-actions__title"
132155
spacing={ 1 }
133156
justify="center"
134-
className={ classnames(
135-
'edit-site-document-actions__title',
136-
{
137-
'is-page': isPage,
138-
}
139-
) }
140157
>
141158
<BlockIcon icon={ icon } />
142159
<Text size="body" as="h1">

packages/edit-site/src/components/header-edit-mode/document-actions/style.scss

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
background: $gray-100;
1111
border-radius: 4px;
1212
width: min(100%, 450px);
13+
overflow: hidden;
1314

1415
&:hover {
1516
color: currentColor;
@@ -30,24 +31,37 @@
3031
color: var(--wp-block-synced-color);
3132
overflow: hidden;
3233
grid-column: 2 / 3;
33-
&.is-page {
34-
color: $gray-800;
35-
h1 {
36-
color: $gray-800;
37-
}
38-
}
3934

4035
h1 {
4136
white-space: nowrap;
4237
overflow: hidden;
4338
text-overflow: ellipsis;
4439
color: var(--wp-block-synced-color);
4540
}
41+
42+
.edit-site-document-actions.is-page & {
43+
color: $gray-800;
44+
45+
h1 {
46+
color: $gray-800;
47+
}
48+
}
49+
50+
.edit-site-document-actions.is-animated & {
51+
animation: edit-site-document-actions__slide-in-left 0.3s;
52+
@include reduce-motion("animation");
53+
}
54+
55+
.edit-site-document-actions.is-animated.is-page & {
56+
animation: edit-site-document-actions__slide-in-right 0.3s;
57+
@include reduce-motion("animation");
58+
}
4659
}
4760

4861
.edit-site-document-actions__shortcut {
4962
color: $gray-700;
5063
text-align: right;
64+
5165
&:hover {
5266
color: $gray-700;
5367
}
@@ -59,4 +73,31 @@
5973
grid-column: 1 / 2;
6074
grid-row: 1;
6175
z-index: 1;
76+
77+
.edit-site-document-actions.is-animated & {
78+
animation: edit-site-document-actions__slide-in-left 0.3s;
79+
@include reduce-motion("animation");
80+
}
81+
}
82+
83+
@keyframes edit-site-document-actions__slide-in-right {
84+
from {
85+
transform: translateX(-15%);
86+
opacity: 0;
87+
}
88+
to {
89+
transform: translateX(0);
90+
opacity: 1;
91+
}
92+
}
93+
94+
@keyframes edit-site-document-actions__slide-in-left {
95+
from {
96+
transform: translateX(15%);
97+
opacity: 0;
98+
}
99+
to {
100+
transform: translateX(0);
101+
opacity: 1;
102+
}
62103
}

0 commit comments

Comments
 (0)