Skip to content

Commit

Permalink
Site Editor: Clarify that the site icon is a back button using an ani…
Browse files Browse the repository at this point in the history
…mation (#63986)

Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
Co-authored-by: richtabor <richtabor@git.wordpress.org>
Co-authored-by: mtias <matveb@git.wordpress.org>
  • Loading branch information
5 people authored Jul 31, 2024
1 parent 08e6960 commit cba05ca
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 24 deletions.
102 changes: 80 additions & 22 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import clsx from 'clsx';
* WordPress dependencies
*/
import { useDispatch, useSelect } from '@wordpress/data';
import { Button } from '@wordpress/components';
import { useInstanceId } from '@wordpress/compose';
import { Button, __unstableMotion as motion } from '@wordpress/components';
import { useInstanceId, useReducedMotion } from '@wordpress/compose';
import {
EditorKeyboardShortcutsRegister,
privateApis as editorPrivateApis,
Expand All @@ -22,6 +22,7 @@ import { store as noticesStore } from '@wordpress/notices';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { store as preferencesStore } from '@wordpress/preferences';
import { decodeEntities } from '@wordpress/html-entities';
import { Icon, chevronLeft } from '@wordpress/icons';

/**
* Internal dependencies
Expand Down Expand Up @@ -51,7 +52,32 @@ const { Editor, BackButton } = unlock( editorPrivateApis );
const { useHistory, useLocation } = unlock( routerPrivateApis );
const { BlockKeyboardShortcuts } = unlock( blockLibraryPrivateApis );

const toggleHomeIconVariants = {
edit: {
opacity: 0,
scale: 0.2,
},
hover: {
opacity: 1,
scale: 1,
clipPath: 'inset( 22% round 2px )',
},
};

const siteIconVariants = {
edit: {
clipPath: 'inset(0% round 0)',
},
hover: {
clipPath: 'inset( 22% round 2px )',
},
tap: {
clipPath: 'inset(0% round 0)',
},
};

export default function EditSiteEditor( { isPostsList = false } ) {
const disableMotion = useReducedMotion();
const { params } = useLocation();
const isLoading = useIsSiteEditorLoading();
const {
Expand All @@ -65,6 +91,7 @@ export default function EditSiteEditor( { isPostsList = false } ) {
showIconLabels,
editorCanvasView,
currentPostIsTrashed,
hasSiteIcon,
} = useSelect( ( select ) => {
const {
getEditorCanvasContainerView,
Expand All @@ -75,8 +102,9 @@ export default function EditSiteEditor( { isPostsList = false } ) {
getEditedPostId,
} = unlock( select( editSiteStore ) );
const { get } = select( preferencesStore );
const { getCurrentTheme } = select( coreDataStore );
const { getCurrentTheme, getEntityRecord } = select( coreDataStore );
const _context = getEditedPostContext();
const siteData = getEntityRecord( 'root', '__unstableBase', undefined );

// The currently selected entity to display.
// Typically template or template part in the site editor.
Expand All @@ -93,6 +121,7 @@ export default function EditSiteEditor( { isPostsList = false } ) {
currentPostIsTrashed:
select( editorStore ).getCurrentPostAttribute( 'status' ) ===
'trash',
hasSiteIcon: !! siteData?.site_icon_url,
};
}, [] );
useEditorTitle();
Expand Down Expand Up @@ -179,6 +208,9 @@ export default function EditSiteEditor( { isPostsList = false } ) {
getEditorCanvasContainerTitleAndIcon( editorCanvasView );

const isReady = ! isLoading;
const transition = {
duration: disableMotion ? 0 : 0.2,
};

return (
<>
Expand Down Expand Up @@ -217,26 +249,52 @@ export default function EditSiteEditor( { isPostsList = false } ) {
<BackButton>
{ ( { length } ) =>
length <= 1 && (
<Button
label={ __( 'Open Navigation' ) }
className="edit-site-layout__view-mode-toggle"
onClick={ () => {
setCanvasMode( 'view' );
// TODO: this is a temporary solution to navigate to the posts list if we are
// come here through `posts list` and are in focus mode editing a template, template part etc..
if (
isPostsList &&
params?.focusMode
) {
history.push( {
page: 'gutenberg-posts-dashboard',
postType: 'post',
} );
}
} }
<motion.div
className="edit-site-editor__view-mode-toggle"
transition={ transition }
animate="edit"
initial="edit"
whileHover="hover"
whileTap="tap"
>
<SiteIcon className="edit-site-layout__view-mode-toggle-icon" />
</Button>
<Button
label={ __( 'Open Navigation' ) }
showTooltip
tooltipPosition="middle right"
onClick={ () => {
setCanvasMode( 'view' );
// TODO: this is a temporary solution to navigate to the posts list if we are
// come here through `posts list` and are in focus mode editing a template, template part etc..
if (
isPostsList &&
params?.focusMode
) {
history.push( {
page: 'gutenberg-posts-dashboard',
postType: 'post',
} );
}
} }
>
<motion.div
variants={ siteIconVariants }
>
<SiteIcon className="edit-site-editor__view-mode-toggle-icon" />
</motion.div>
</Button>
<motion.div
className={ clsx(
'edit-site-editor__back-icon',
{
'has-site-icon':
hasSiteIcon,
}
) }
variants={ toggleHomeIconVariants }
>
<Icon icon={ chevronLeft } />
</motion.div>
</motion.div>
)
}
</BackButton>
Expand Down
59 changes: 58 additions & 1 deletion packages/edit-site/src/components/editor/style.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.edit-site-editor__editor-interface {
opacity: 1;
transition: opacity 0.1s ease-out;
@include reduce-motion("transition");
@include reduce-motion( "transition" );

&.is-loading {
opacity: 0;
Expand All @@ -17,3 +17,60 @@
display: flex;
justify-content: center;
}

.edit-site-editor__view-mode-toggle {
/* stylelint-disable -- Disable reason: View Transitions not supported properly by stylelint. */
view-transition-name: toggle;
/* stylelint-enable */
position: fixed;
top: 0;
left: 0;
height: $header-height;
width: $header-height;
z-index: 100;

.components-button {
color: $white;
height: 100%;
width: 100%;
border-radius: 0;
overflow: hidden;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
&:hover,
&:active {
color: $white;
}

&:focus {
box-shadow: none;
}
}

.edit-site-editor__view-mode-toggle-icon {
svg,
img {
background: $gray-900;
display: block;
}
}
}

.edit-site-editor__back-icon {
position: absolute;
top: 0;
left: 0;
width: 60px;
height: 60px;
display: flex;
align-items: center;
justify-content: center;
background-color: hsla(0, 0%, 80%);
pointer-events: none;

&.has-site-icon {
background-color: hsla(0, 0%, 100%, 0.6);
}
}
8 changes: 8 additions & 0 deletions packages/edit-site/src/components/layout/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@
html.canvas-mode-edit-transition::view-transition-group(toggle) {
animation-delay: 255ms;
}

@media (prefers-reduced-motion) {
::view-transition-group(*),
::view-transition-old(*),
::view-transition-new(*) {
animation: none !important;
}
}
/* stylelint-enable */

.edit-site-layout.is-full-canvas .edit-site-layout__sidebar-region .edit-site-layout__view-mode-toggle {
Expand Down
5 changes: 4 additions & 1 deletion packages/edit-site/src/components/site-icon/style.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
.edit-site-site-icon__icon {
fill: currentColor;
width: 100%;
height: 100%;

.edit-site-layout.is-full-canvas & {
// Make the WordPress icon not so big in full canvas.
padding: $grid-unit-15 * 0.5; // 6px.
padding: $grid-unit-15;
}
}

Expand All @@ -12,6 +14,7 @@
height: 100%;
object-fit: cover;
background: #333;
aspect-ratio: 1 / 1;

.edit-site-layout.is-full-canvas & {
border-radius: 0;
Expand Down

0 comments on commit cba05ca

Please sign in to comment.