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

Make SiteHub available for Pages, Patterns, and Templates in mobile viewports #63118

Merged
merged 2 commits into from
Jul 4, 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
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 }>
oandregal marked this conversation as resolved.
Show resolved Hide resolved
<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>
);
} )
);
Loading