From 4ab6f3b3f13bfa1e1bd0c81bfd128e7f49c651ca Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Thu, 15 Apr 2021 14:12:59 +0100 Subject: [PATCH] Replace the document tab with a template tab in template mode (#30860) --- .../sidebar/settings-header/index.js | 59 +++++++++++------ .../sidebar/settings-sidebar/index.js | 63 +++++++++++-------- .../sidebar/template-summary/index.js | 41 ++++++++++++ .../sidebar/template-summary/style.scss | 4 ++ packages/edit-post/src/style.scss | 1 + 5 files changed, 124 insertions(+), 44 deletions(-) create mode 100644 packages/edit-post/src/components/sidebar/template-summary/index.js create mode 100644 packages/edit-post/src/components/sidebar/template-summary/style.scss diff --git a/packages/edit-post/src/components/sidebar/settings-header/index.js b/packages/edit-post/src/components/sidebar/settings-header/index.js index b614ec0ebaf102..3f5a03ad901345 100644 --- a/packages/edit-post/src/components/sidebar/settings-header/index.js +++ b/packages/edit-post/src/components/sidebar/settings-header/index.js @@ -16,18 +16,20 @@ const SettingsHeader = ( { sidebarName } ) => { openGeneralSidebar( 'edit-post/document' ); const openBlockSettings = () => openGeneralSidebar( 'edit-post/block' ); - const documentLabel = useSelect( ( select ) => { + const { documentLabel, isTemplateMode } = useSelect( ( select ) => { const currentPostType = select( 'core/editor' ).getCurrentPostType(); const postType = select( 'core' ).getPostType( currentPostType ); - return ( - // Disable reason: Post type labels object is shaped like this. - // eslint-disable-next-line camelcase - postType?.labels?.singular_name ?? - // translators: Default label for the Document sidebar tab, not selected. - __( 'Document' ) - ); - } ); + return { + documentLabel: + // Disable reason: Post type labels object is shaped like this. + // eslint-disable-next-line camelcase + postType?.labels?.singular_name ?? + // translators: Default label for the Document sidebar tab, not selected. + __( 'Document' ), + isTemplateMode: select( editPostStore ).isEditingTemplate(), + }; + }, [] ); const [ documentAriaLabel, documentActiveClass ] = sidebarName === 'edit-post/document' @@ -42,19 +44,38 @@ const SettingsHeader = ( { sidebarName } ) => { : // translators: ARIA label for the Block Settings Sidebar tab, not selected. [ __( 'Block' ), '' ]; + const [ templateAriaLabel, templateActiveClass ] = + sidebarName === 'edit-post/document' + ? [ __( 'Template (selected)' ), 'is-active' ] + : [ __( 'Template' ), '' ]; + /* Use a list so screen readers will announce how many tabs there are. */ return (