Skip to content

Commit

Permalink
Site: editor: Add view site link to site editor nav (#50420)
Browse files Browse the repository at this point in the history
  • Loading branch information
glendaviesnz authored May 28, 2023
1 parent d5f04b7 commit 4c60efe
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
23 changes: 20 additions & 3 deletions packages/edit-site/src/components/site-hub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ 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 { search, external } from '@wordpress/icons';
import { privateApis as commandsPrivateApis } from '@wordpress/commands';

/**
Expand All @@ -34,15 +34,20 @@ const { store: commandsStore } = unlock( commandsPrivateApis );
const HUB_ANIMATION_DURATION = 0.3;

const SiteHub = forwardRef( ( props, ref ) => {
const { canvasMode, dashboardLink } = useSelect( ( select ) => {
const { canvasMode, dashboardLink, homeUrl } = useSelect( ( select ) => {
const { getCanvasMode, getSettings } = unlock(
select( editSiteStore )
);

const {
getUnstableBase, // Site index.
} = select( coreStore );

return {
canvasMode: getCanvasMode(),
dashboardLink:
getSettings().__experimentalDashboardLink || 'index.php',
homeUrl: getUnstableBase()?.home,
};
}, [] );
const { open: openCommandCenter } = useDispatch( commandsStore );
Expand Down Expand Up @@ -87,7 +92,11 @@ const SiteHub = forwardRef( ( props, ref ) => {
ease: 'easeOut',
} }
>
<HStack justify="space-between" alignment="center">
<HStack
justify="space-between"
alignment="center"
className="edit-site-site-hub__container"
>
<HStack
justify="flex-start"
className="edit-site-site-hub__text-content"
Expand Down Expand Up @@ -149,6 +158,14 @@ const SiteHub = forwardRef( ( props, ref ) => {
{ decodeEntities( siteTitle ) }
</motion.div>
</AnimatePresence>
<Button
href={ homeUrl }
target="_blank"
label={ __( 'View site' ) }
aria-label={ __( 'View site (opens in a new tab)' ) }
icon={ external }
className="edit-site-site-hub__site-view-link"
/>
</HStack>
{ canvasMode === 'view' && (
<Button
Expand Down
26 changes: 26 additions & 0 deletions packages/edit-site/src/components/site-hub/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@
align-items: center;
justify-content: space-between;
gap: $grid-unit-10;

.edit-site-site-hub__container {
gap: 0;
}

.edit-site-site-hub__site-view-link {
flex-grow: 0;
@include break-mobile() {
opacity: 0;
transition: opacity 0.2s ease-in-out;
}
&:focus {
outline: none;
box-shadow: none;
opacity: 1;
}
svg {
fill: $white;
}
}
&:hover {
.edit-site-site-hub__site-view-link {
opacity: 1;
}
}
}

.edit-site-site-hub__post-type {
Expand All @@ -29,6 +54,7 @@

.edit-site-site-hub__site-title {
margin-left: $grid-unit-05;
flex-grow: 1;
}

.edit-site-site-hub_toggle-command-center {
Expand Down

0 comments on commit 4c60efe

Please sign in to comment.