Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Site Editor: Clarify that the site icon is a back button using an animation #63986

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you add undefined here intentionally or by accident?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard to tell at this point 😬 I don't remember


// 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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something about this commit caused the icon to sit low in distraction free. Commenting here because removing the fixed position resolves it in my testing

Screen.Recording.2024-08-02.at.12.00.00.PM.mov

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix in #64261

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
Loading