Skip to content

Commit

Permalink
Make SiteHub available for Pages, Patterns, and Templates in mobile v…
Browse files Browse the repository at this point in the history
…iewports (WordPress#63118)

* Create a SiteHubMobile only available for Pages, Patterns, and Templates

* Fix spacing issues

Co-authored-by: oandregal <[email protected]>
Co-authored-by: MaggieCabrera <[email protected]>
Co-authored-by: andrewserong <[email protected]>
Co-authored-by: jameskoster <[email protected]>
Co-authored-by: ramonjd <[email protected]>
Co-authored-by: aaronrobertshaw <[email protected]>
Co-authored-by: annezazu <[email protected]>
Co-authored-by: youknowriad <[email protected]>
  • Loading branch information
9 people authored and carstingaxion committed Jul 18, 2024
1 parent 7db926b commit 76d2ea5
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 2 deletions.
12 changes: 11 additions & 1 deletion packages/edit-site/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { privateApis as coreCommandsPrivateApis } from '@wordpress/core-commands
*/
import ErrorBoundary from '../error-boundary';
import { store as editSiteStore } from '../../store';
import SiteHub from '../site-hub';
import { default as SiteHub, SiteHubMobile } from '../site-hub';
import ResizableFrame from '../resizable-frame';
import { unlock } from '../../lock-unlock';
import KeyboardShortcutsRegister from '../keyboard-shortcuts/register';
Expand Down Expand Up @@ -174,6 +174,16 @@ export default function Layout( { route } ) {

{ isMobileViewport && areas.mobile && (
<div className="edit-site-layout__mobile">
{ canvasMode !== 'edit' && (
<SidebarContent routeKey={ routeKey }>
<SiteHubMobile
ref={ toggleRef }
isTransparent={
isResizableFrameOversized
}
/>
</SidebarContent>
) }
{ areas.mobile }
</div>
) }
Expand Down
12 changes: 12 additions & 0 deletions packages/edit-site/src/components/layout/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@
position: relative;
width: 100%;
z-index: z-index(".edit-site-layout__canvas-container");

/*
* The SiteHubMobile component is displayed
* for pages that do not have a sidebar,
* yet it needs the Sidebar component for the React context.
*
* This removes the padding in this scenario.
* See https://github.com/WordPress/gutenberg/pull/63118
*/
.edit-site-sidebar__screen-wrapper {
padding: 0;
}
}

.edit-site-layout__canvas-container {
Expand Down
85 changes: 84 additions & 1 deletion packages/edit-site/src/components/site-hub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ import { Button, __experimentalHStack as HStack } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { store as coreStore } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';
import { memo, forwardRef } from '@wordpress/element';
import { memo, forwardRef, useContext } from '@wordpress/element';
import { search } from '@wordpress/icons';
import { store as commandsStore } from '@wordpress/commands';
import { displayShortcut } from '@wordpress/keycodes';
import { filterURLForDisplay } from '@wordpress/url';
import { privateApis as routerPrivateApis } from '@wordpress/router';

/**
* Internal dependencies
*/
import { store as editSiteStore } from '../../store';
import SiteIcon from '../site-icon';
import { unlock } from '../../lock-unlock';
const { useHistory } = unlock( routerPrivateApis );
import { SidebarNavigationContext } from '../sidebar';

const SiteHub = memo(
forwardRef( ( { isTransparent }, ref ) => {
Expand Down Expand Up @@ -103,3 +106,83 @@ const SiteHub = memo(
);

export default SiteHub;

export const SiteHubMobile = memo(
forwardRef( ( { isTransparent }, ref ) => {
const history = useHistory();
const { navigate } = useContext( SidebarNavigationContext );

const { homeUrl, siteTitle } = useSelect( ( select ) => {
const {
getSite,
getUnstableBase, // Site index.
} = select( coreStore );
const _site = getSite();
return {
homeUrl: getUnstableBase()?.home,
siteTitle:
! _site?.title && !! _site?.url
? filterURLForDisplay( _site?.url )
: _site?.title,
};
}, [] );
const { open: openCommandCenter } = useDispatch( commandsStore );

return (
<div className="edit-site-site-hub">
<HStack justify="flex-start" spacing="0">
<div
className={ clsx(
'edit-site-site-hub__view-mode-toggle-container',
{
'has-transparent-background': isTransparent,
}
) }
>
<Button
ref={ ref }
label={ __( 'Go to Site Editor' ) }
className="edit-site-layout__view-mode-toggle"
style={ {
transform: 'scale(0.5)',
borderRadius: 4,
} }
onClick={ () => {
history.push( {} );
navigate( 'back' );
} }
>
<SiteIcon className="edit-site-layout__view-mode-toggle-icon" />
</Button>
</div>

<HStack>
<div className="edit-site-site-hub__title">
<Button
variant="link"
href={ homeUrl }
target="_blank"
label={ __( 'View site (opens in a new tab)' ) }
>
{ decodeEntities( siteTitle ) }
</Button>
</div>
<HStack
spacing={ 0 }
expanded={ false }
className="edit-site-site-hub__actions"
>
<Button
className="edit-site-site-hub_toggle-command-center"
icon={ search }
onClick={ () => openCommandCenter() }
label={ __( 'Open command palette' ) }
shortcut={ displayShortcut.primary( 'k' ) }
/>
</HStack>
</HStack>
</HStack>
</div>
);
} )
);

0 comments on commit 76d2ea5

Please sign in to comment.