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

Command center: Add a button to open it from the site editor view mode #50425

Merged
merged 3 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion packages/edit-site/src/components/layout/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}

@include break-medium {
width: calc(#{$nav-sidebar-width} - #{$canvas-padding * 2});
width: calc(#{$nav-sidebar-width} - #{$canvas-padding});
}

.edit-site-layout.is-full-canvas & {
Expand Down
112 changes: 65 additions & 47 deletions packages/edit-site/src/components/site-hub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { store as blockEditorStore } from '@wordpress/block-editor';
import { store as coreStore } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';
import { forwardRef } from '@wordpress/element';
import { search } from '@wordpress/icons';
import { privateApis as commandsPrivateApis } from '@wordpress/commands';

/**
* Internal dependencies
Expand All @@ -27,6 +29,8 @@ import { store as editSiteStore } from '../../store';
import SiteIcon from '../site-icon';
import { unlock } from '../../private-apis';

const { store: commandsStore } = unlock( commandsPrivateApis );

const HUB_ANIMATION_DURATION = 0.3;

const SiteHub = forwardRef( ( props, ref ) => {
Expand All @@ -41,6 +45,7 @@ const SiteHub = forwardRef( ( props, ref ) => {
getSettings().__experimentalDashboardLink || 'index.php',
};
}, [] );
const { open: openCommandCenter } = useDispatch( commandsStore );

const disableMotion = useReducedMotion();
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
Expand Down Expand Up @@ -82,65 +87,78 @@ const SiteHub = forwardRef( ( props, ref ) => {
ease: 'easeOut',
} }
>
<HStack
justify="flex-start"
className="edit-site-site-hub__text-content"
spacing="0"
>
<motion.div
className="edit-site-site-hub__view-mode-toggle-container"
layout
transition={ {
type: 'tween',
duration: disableMotion ? 0 : HUB_ANIMATION_DURATION,
ease: 'easeOut',
} }
<HStack justify="space-between" alignment="center">
<HStack
justify="flex-start"
className="edit-site-site-hub__text-content"
spacing="0"
>
<Button
{ ...siteIconButtonProps }
className="edit-site-layout__view-mode-toggle"
<motion.div
className="edit-site-site-hub__view-mode-toggle-container"
layout
transition={ {
type: 'tween',
duration: disableMotion
? 0
: HUB_ANIMATION_DURATION,
ease: 'easeOut',
} }
>
<Button
{ ...siteIconButtonProps }
className="edit-site-layout__view-mode-toggle"
>
<motion.div
initial={ false }
animate={ {
scale: canvasMode === 'view' ? 0.5 : 1,
} }
whileHover={ {
scale: canvasMode === 'view' ? 0.5 : 0.96,
} }
transition={ {
type: 'tween',
duration: disableMotion
? 0
: HUB_ANIMATION_DURATION,
ease: 'easeOut',
} }
>
<SiteIcon className="edit-site-layout__view-mode-toggle-icon" />
</motion.div>
</Button>
</motion.div>

<AnimatePresence>
<motion.div
initial={ false }
layout={ canvasMode === 'edit' }
animate={ {
scale: canvasMode === 'view' ? 0.5 : 1,
opacity: canvasMode === 'view' ? 1 : 0,
} }
whileHover={ {
scale: canvasMode === 'view' ? 0.5 : 0.96,
exit={ {
opacity: 0,
} }
className="edit-site-site-hub__site-title"
transition={ {
type: 'tween',
duration: disableMotion
? 0
: HUB_ANIMATION_DURATION,
duration: disableMotion ? 0 : 0.2,
ease: 'easeOut',
delay: canvasMode === 'view' ? 0.1 : 0,
} }
>
<SiteIcon className="edit-site-layout__view-mode-toggle-icon" />
{ decodeEntities( siteTitle ) }
</motion.div>
</Button>
</motion.div>

<AnimatePresence>
<motion.div
layout={ canvasMode === 'edit' }
animate={ {
opacity: canvasMode === 'view' ? 1 : 0,
} }
exit={ {
opacity: 0,
} }
className="edit-site-site-hub__site-title"
transition={ {
type: 'tween',
duration: disableMotion ? 0 : 0.2,
ease: 'easeOut',
delay: canvasMode === 'view' ? 0.1 : 0,
} }
>
{ decodeEntities( siteTitle ) }
</motion.div>
</AnimatePresence>
</AnimatePresence>
</HStack>
{ window?.__experimentalEnableCommandCenter &&
canvasMode === 'view' && (
<Button
className="edit-site-site-hub_toggle-command-center"
icon={ search }
onClick={ () => openCommandCenter() }
label={ __( 'Open command center' ) }
/>
) }
</HStack>
</motion.div>
);
Expand Down
4 changes: 4 additions & 0 deletions packages/edit-site/src/components/site-hub/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@
.edit-site-site-hub__site-title {
margin-left: $grid-unit-05;
}

.edit-site-site-hub_toggle-command-center {
color: $white;
}