From 011446c719a90fe97c52bf662547ef0933a6575b Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Thu, 15 Feb 2024 12:13:06 +0100 Subject: [PATCH] Site Editor: Fix navigation on mobile web (#59014) Co-authored-by: youknowriad Co-authored-by: t-hamano Co-authored-by: ntsekouras Co-authored-by: jameskoster Co-authored-by: colorful-tones Co-authored-by: annezazu --- .../edit-site/src/components/layout/index.js | 77 +++++++++++-------- .../edit-site/src/components/layout/router.js | 33 +++++++- .../src/components/layout/style.scss | 7 ++ .../src/components/page-patterns/style.scss | 6 ++ .../sidebar-navigation-screen-pages/index.js | 16 ++-- .../edit-site/src/components/sidebar/index.js | 10 ++- 6 files changed, 108 insertions(+), 41 deletions(-) diff --git a/packages/edit-site/src/components/layout/index.js b/packages/edit-site/src/components/layout/index.js index 163d4fe6e938ff..65dfb71949a7f5 100644 --- a/packages/edit-site/src/components/layout/index.js +++ b/packages/edit-site/src/components/layout/index.js @@ -251,47 +251,64 @@ export default function Layout() { The NavigableRegion must always be rendered and not use `inert` otherwise `useNavigateRegions` will fail. */ } - - - { canvasMode === 'view' && ( - - - - ) } - - + { ( ! isMobileViewport || + ( isMobileViewport && ! areas.mobile ) ) && ( + + + { canvasMode === 'view' && ( + + + + ) } + + + ) } - { areas.content && canvasMode !== 'edit' && ( + { isMobileViewport && areas.mobile && (
- { areas.content } + { areas.mobile }
) } - { areas.preview && ( + { ! isMobileViewport && + areas.content && + canvasMode !== 'edit' && ( +
+ { areas.content } +
+ ) } + + { ! isMobileViewport && areas.preview && (
{ canvasResizer } { !! canvasSize.width && ( diff --git a/packages/edit-site/src/components/layout/router.js b/packages/edit-site/src/components/layout/router.js index aeb124bf76fe5f..02f7e7b25594ae 100644 --- a/packages/edit-site/src/components/layout/router.js +++ b/packages/edit-site/src/components/layout/router.js @@ -23,13 +23,21 @@ const { useLocation } = unlock( routerPrivateApis ); export default function useLayoutAreas() { const isSiteEditorLoading = useIsSiteEditorLoading(); const { params } = useLocation(); - const { postType, postId, path, layout, isCustom } = params ?? {}; + const { postType, postId, path, layout, isCustom, canvas } = params ?? {}; + + // Note: Since "sidebar" is not yet supported here, + // returning undefined from "mobile" means show the sidebar. + // Regular page if ( path === '/page' ) { return { areas: { content: undefined, preview: , + mobile: + canvas === 'edit' ? ( + + ) : undefined, }, widths: { content: undefined, @@ -63,6 +71,10 @@ export default function useLayoutAreas() { return { areas: { preview: , + mobile: + canvas === 'edit' ? ( + + ) : undefined, }, }; } @@ -79,6 +91,11 @@ export default function useLayoutAreas() { preview: isListLayout && ( ), + mobile: ( + + ), }, widths: { content: isListLayout ? 380 : undefined, @@ -98,6 +115,11 @@ export default function useLayoutAreas() { preview: isListLayout && ( ), + mobile: ( + + ), }, widths: { content: isListLayout ? 380 : undefined, @@ -110,12 +132,19 @@ export default function useLayoutAreas() { return { areas: { content: , + mobile: , }, }; } // Fallback shows the home page preview return { - areas: { preview: }, + areas: { + preview: , + mobile: + canvas === 'edit' ? ( + + ) : undefined, + }, }; } diff --git a/packages/edit-site/src/components/layout/style.scss b/packages/edit-site/src/components/layout/style.scss index 9be0b001ed9e25..ad33768989a81b 100644 --- a/packages/edit-site/src/components/layout/style.scss +++ b/packages/edit-site/src/components/layout/style.scss @@ -83,6 +83,12 @@ flex-direction: column; } +.edit-site-layout__mobile { + position: relative; + width: 100%; + z-index: z-index(".edit-site-layout__canvas-container"); +} + .edit-site-layout__canvas-container { position: relative; flex-grow: 1; @@ -147,6 +153,7 @@ } // This shouldn't be necessary (we should have a way to say that a skeletton is relative +.edit-site-layout__mobile .interface-interface-skeleton, .edit-site-layout__canvas .interface-interface-skeleton, .edit-site-template-pages-preview .interface-interface-skeleton { position: relative !important; diff --git a/packages/edit-site/src/components/page-patterns/style.scss b/packages/edit-site/src/components/page-patterns/style.scss index 0be55756d1609d..dd32818edd614b 100644 --- a/packages/edit-site/src/components/page-patterns/style.scss +++ b/packages/edit-site/src/components/page-patterns/style.scss @@ -225,6 +225,12 @@ * TODO: when this becomes stable, consolidate styles with the above. */ .edit-site-page-patterns-dataviews { + margin-top: 60px; + + @include break-medium { + margin-top: 0; + } + .page-patterns-preview-field { display: flex; flex-direction: column; diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js index 82fc6d0fa2412b..7641ac1fe97a0d 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js @@ -14,6 +14,7 @@ import { decodeEntities } from '@wordpress/html-entities'; import { privateApis as routerPrivateApis } from '@wordpress/router'; import { layout, page, home, verse, plus } from '@wordpress/icons'; import { useSelect } from '@wordpress/data'; +import { useViewportMatch } from '@wordpress/compose'; /** * Internal dependencies @@ -42,6 +43,7 @@ const PageItem = ( { postType = 'page', postId, ...props } ) => { }; export default function SidebarNavigationScreenPages() { + const isMobileViewport = useViewportMatch( 'medium', '<' ); const { records: pages, isResolving: isLoadingPages } = useEntityRecords( 'postType', 'page', @@ -220,12 +222,14 @@ export default function SidebarNavigationScreenPages() { ) ) } - - { __( 'Manage all pages' ) } - + { ! isMobileViewport && ( + + { __( 'Manage all pages' ) } + + ) } } /> diff --git a/packages/edit-site/src/components/sidebar/index.js b/packages/edit-site/src/components/sidebar/index.js index 84a89957b475d5..56107edc63c863 100644 --- a/packages/edit-site/src/components/sidebar/index.js +++ b/packages/edit-site/src/components/sidebar/index.js @@ -13,6 +13,7 @@ import { } from '@wordpress/components'; import { privateApis as routerPrivateApis } from '@wordpress/router'; import { __ } from '@wordpress/i18n'; +import { useViewportMatch } from '@wordpress/compose'; /** * Internal dependencies @@ -52,6 +53,7 @@ function SidebarScreenWrapper( { className, ...props } ) { function SidebarScreens() { useSyncPathWithURL(); + const isMobileViewport = useViewportMatch( 'medium', '<' ); return ( <> @@ -82,9 +84,11 @@ function SidebarScreens() { - - - + { ! isMobileViewport && ( + + + + ) }