From ad8819df5a01f59448a268f66420e9c26c406819 Mon Sep 17 00:00:00 2001 From: chad1008 <13856531+chad1008@users.noreply.github.com> Date: Wed, 1 Nov 2023 16:23:26 -0400 Subject: [PATCH 01/23] implement Tabs in editor settings sidebar --- .../sidebar/settings-header/index.js | 94 ++++++++++--------- .../sidebar/settings-sidebar/index.js | 82 ++++++++++------ 2 files changed, 103 insertions(+), 73 deletions(-) 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 ef32450e7209f..5c591753b0e91 100644 --- a/packages/edit-post/src/components/sidebar/settings-header/index.js +++ b/packages/edit-post/src/components/sidebar/settings-header/index.js @@ -1,7 +1,10 @@ /** * WordPress dependencies */ -import { Button } from '@wordpress/components'; +import { + Button, + privateApis as componentsPrivateApis, +} from '@wordpress/components'; import { __, _x, sprintf } from '@wordpress/i18n'; import { useDispatch, useSelect } from '@wordpress/data'; import { store as editorStore } from '@wordpress/editor'; @@ -10,6 +13,9 @@ import { store as editorStore } from '@wordpress/editor'; * Internal dependencies */ import { store as editPostStore } from '../../../store'; +import { unlock } from '../../../lock-unlock'; + +const { Tabs } = unlock( componentsPrivateApis ); const SettingsHeader = ( { sidebarName } ) => { const { openGeneralSidebar } = useDispatch( editPostStore ); @@ -27,66 +33,68 @@ const SettingsHeader = ( { sidebarName } ) => { }; }, [] ); - const [ documentAriaLabel, documentActiveClass ] = + const [ documentAriaLabel ] = sidebarName === 'edit-post/document' ? // translators: ARIA label for the Document sidebar tab, selected. %s: Document label. [ sprintf( __( '%s (selected)' ), documentLabel ), 'is-active' ] : [ documentLabel, '' ]; - const [ blockAriaLabel, blockActiveClass ] = + const [ blockAriaLabel ] = sidebarName === 'edit-post/block' ? // translators: ARIA label for the Block Settings Sidebar tab, selected. [ __( 'Block (selected)' ), 'is-active' ] : // translators: ARIA label for the Block Settings Sidebar tab, not selected. [ __( 'Block' ), '' ]; - const [ templateAriaLabel, templateActiveClass ] = + const [ templateAriaLabel ] = sidebarName === 'edit-post/document' ? [ __( 'Template (selected)' ), 'is-active' ] : [ __( 'Template' ), '' ]; - /* Use a list so screen readers will announce how many tabs there are. */ return ( - + > + { /* translators: Text label for the Block Settings Sidebar tab. */ } + { __( 'Block' ) } + + + ); }; diff --git a/packages/edit-post/src/components/sidebar/settings-sidebar/index.js b/packages/edit-post/src/components/sidebar/settings-sidebar/index.js index e566ea400c12b..bf236157d5145 100644 --- a/packages/edit-post/src/components/sidebar/settings-sidebar/index.js +++ b/packages/edit-post/src/components/sidebar/settings-sidebar/index.js @@ -6,7 +6,7 @@ import { store as blockEditorStore, } from '@wordpress/block-editor'; import { useSelect } from '@wordpress/data'; -import { Platform } from '@wordpress/element'; +import { Platform, useContext } from '@wordpress/element'; import { isRTL, __ } from '@wordpress/i18n'; import { drawerLeft, drawerRight } from '@wordpress/icons'; import { store as interfaceStore } from '@wordpress/interface'; @@ -29,6 +29,10 @@ import PluginDocumentSettingPanel from '../plugin-document-setting-panel'; import PluginSidebarEditPost from '../plugin-sidebar'; import TemplateSummary from '../template-summary'; import { store as editPostStore } from '../../../store'; +import { privateApis as componentsPrivateApis } from '@wordpress/components'; +import { unlock } from '../../../lock-unlock'; + +const { Tabs } = unlock( componentsPrivateApis ); const SIDEBAR_ACTIVE_BY_DEFAULT = Platform.select( { web: true, @@ -72,36 +76,54 @@ const SettingsSidebar = () => { [] ); + const Content = () => { + const tabsContextValue = useContext( Tabs.Context ); + + return ( + + + + } + closeLabel={ __( 'Close Settings' ) } + headerClassName="edit-post-sidebar__panel-tabs" + /* translators: button label text should, if possible, be under 16 characters. */ + title={ __( 'Settings' ) } + toggleShortcut={ keyboardShortcut } + icon={ isRTL() ? drawerLeft : drawerRight } + isActiveByDefault={ SIDEBAR_ACTIVE_BY_DEFAULT } + > + + + { ! isTemplateMode && ( + <> + + + + + + + + + + + ) } + { isTemplateMode && } + + + + + + + ); + }; + return ( - } - closeLabel={ __( 'Close Settings' ) } - headerClassName="edit-post-sidebar__panel-tabs" - /* translators: button label text should, if possible, be under 16 characters. */ - title={ __( 'Settings' ) } - toggleShortcut={ keyboardShortcut } - icon={ isRTL() ? drawerLeft : drawerRight } - isActiveByDefault={ SIDEBAR_ACTIVE_BY_DEFAULT } - > - { ! isTemplateMode && sidebarName === 'edit-post/document' && ( - <> - - - - - - - - - - - ) } - { isTemplateMode && sidebarName === 'edit-post/document' && ( - - ) } - { sidebarName === 'edit-post/block' && } - + + + ); }; From 4cb5c69e350820f473b73d631362475cfe6cba3e Mon Sep 17 00:00:00 2001 From: chad1008 <13856531+chad1008@users.noreply.github.com> Date: Wed, 1 Nov 2023 16:24:09 -0400 Subject: [PATCH 02/23] remove duplicated styles from editor sidebar --- .../sidebar/settings-header/style.scss | 74 ------------------- packages/edit-post/src/style.scss | 1 - 2 files changed, 75 deletions(-) delete mode 100644 packages/edit-post/src/components/sidebar/settings-header/style.scss diff --git a/packages/edit-post/src/components/sidebar/settings-header/style.scss b/packages/edit-post/src/components/sidebar/settings-header/style.scss deleted file mode 100644 index aaf7698cb6ddb..0000000000000 --- a/packages/edit-post/src/components/sidebar/settings-header/style.scss +++ /dev/null @@ -1,74 +0,0 @@ -// This tab style CSS is duplicated verbatim in -// /packages/components/src/tab-panel/style.scss -.components-button.edit-post-sidebar__panel-tab { - position: relative; - border-radius: 0; - height: $grid-unit-60; - background: transparent; - border: none; - box-shadow: none; - cursor: pointer; - padding: 3px $grid-unit-20; // Use padding to offset the is-active border, this benefits Windows High Contrast mode - margin-left: 0; - font-weight: 500; - - &:focus:not(:disabled) { - position: relative; - box-shadow: none; - outline: none; - } - - // Tab indicator - &::after { - content: ""; - position: absolute; - right: 0; - bottom: 0; - left: 0; - pointer-events: none; - - // Draw the indicator. - background: var(--wp-admin-theme-color); - height: calc(0 * var(--wp-admin-border-width-focus)); - border-radius: 0; - - // Animation - transition: all 0.1s linear; - @include reduce-motion("transition"); - } - - // Active. - &.is-active::after { - height: calc(1 * var(--wp-admin-border-width-focus)); - - // Windows high contrast mode. - outline: 2px solid transparent; - outline-offset: -1px; - } - - // Focus. - &::before { - content: ""; - position: absolute; - top: $grid-unit-15; - right: $grid-unit-15; - bottom: $grid-unit-15; - left: $grid-unit-15; - pointer-events: none; - - // Draw the indicator. - box-shadow: 0 0 0 0 transparent; - border-radius: $radius-block-ui; - - // Animation - transition: all 0.1s linear; - @include reduce-motion("transition"); - } - - &:focus-visible::before { - box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color); - - // Windows high contrast mode. - outline: 2px solid transparent; - } -} diff --git a/packages/edit-post/src/style.scss b/packages/edit-post/src/style.scss index 53219bc6a3736..88916bf70f76d 100644 --- a/packages/edit-post/src/style.scss +++ b/packages/edit-post/src/style.scss @@ -12,7 +12,6 @@ @import "./components/sidebar/post-format/style.scss"; @import "./components/sidebar/post-slug/style.scss"; @import "./components/sidebar/post-visibility/style.scss"; -@import "./components/sidebar/settings-header/style.scss"; @import "./components/sidebar/template-summary/style.scss"; @import "./components/text-editor/style.scss"; @import "./components/visual-editor/style.scss"; From ddd8d7f7adfccd07d9e244d431e35386c95c6119 Mon Sep 17 00:00:00 2001 From: chad1008 <13856531+chad1008@users.noreply.github.com> Date: Fri, 3 Nov 2023 11:03:10 -0400 Subject: [PATCH 03/23] incorporate initial feedback --- .../sidebar/settings-header/index.js | 25 ++++++++----------- .../sidebar/settings-sidebar/index.js | 3 +++ 2 files changed, 13 insertions(+), 15 deletions(-) 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 5c591753b0e91..beb4ba3884188 100644 --- a/packages/edit-post/src/components/sidebar/settings-header/index.js +++ b/packages/edit-post/src/components/sidebar/settings-header/index.js @@ -33,23 +33,23 @@ const SettingsHeader = ( { sidebarName } ) => { }; }, [] ); - const [ documentAriaLabel ] = + const documentAriaLabel = sidebarName === 'edit-post/document' ? // translators: ARIA label for the Document sidebar tab, selected. %s: Document label. - [ sprintf( __( '%s (selected)' ), documentLabel ), 'is-active' ] - : [ documentLabel, '' ]; + sprintf( __( '%s (selected)' ), documentLabel ) + : documentLabel; - const [ blockAriaLabel ] = + const blockAriaLabel = sidebarName === 'edit-post/block' ? // translators: ARIA label for the Block Settings Sidebar tab, selected. - [ __( 'Block (selected)' ), 'is-active' ] + __( 'Block (selected)' ) : // translators: ARIA label for the Block Settings Sidebar tab, not selected. - [ __( 'Block' ), '' ]; + __( 'Block' ); - const [ templateAriaLabel ] = + const templateAriaLabel = sidebarName === 'edit-post/document' - ? [ __( 'Template (selected)' ), 'is-active' ] - : [ __( 'Template' ), '' ]; + ? __( 'Template (selected)' ) + : __( 'Template' ); return ( <> @@ -60,14 +60,12 @@ const SettingsHeader = ( { sidebarName } ) => { isTemplateMode ? ( + /> } > { /* translators: Text label for the Block Settings Sidebar tab. */ } diff --git a/packages/edit-post/src/components/sidebar/settings-sidebar/index.js b/packages/edit-post/src/components/sidebar/settings-sidebar/index.js index bf236157d5145..473902a00ae70 100644 --- a/packages/edit-post/src/components/sidebar/settings-sidebar/index.js +++ b/packages/edit-post/src/components/sidebar/settings-sidebar/index.js @@ -77,6 +77,9 @@ const SettingsSidebar = () => { ); const Content = () => { + // Because `PluginSidebarEditPost` renders a `ComplementaryArea`, we + // need to forward the `Tabs` context so it can be passed through the + // underlying slot/fill. const tabsContextValue = useContext( Tabs.Context ); return ( From 4142f5ae83d141367769957ce6449ee4082363b6 Mon Sep 17 00:00:00 2001 From: chad1008 <13856531+chad1008@users.noreply.github.com> Date: Thu, 9 Nov 2023 16:57:15 -0500 Subject: [PATCH 04/23] pass props to Tabs directly --- .../sidebar/settings-header/index.js | 37 ++++++------------- 1 file changed, 11 insertions(+), 26 deletions(-) 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 beb4ba3884188..aa1143482e97d 100644 --- a/packages/edit-post/src/components/sidebar/settings-header/index.js +++ b/packages/edit-post/src/components/sidebar/settings-header/index.js @@ -1,10 +1,7 @@ /** * WordPress dependencies */ -import { - Button, - privateApis as componentsPrivateApis, -} from '@wordpress/components'; +import { privateApis as componentsPrivateApis } from '@wordpress/components'; import { __, _x, sprintf } from '@wordpress/i18n'; import { useDispatch, useSelect } from '@wordpress/data'; import { store as editorStore } from '@wordpress/editor'; @@ -56,34 +53,22 @@ const SettingsHeader = ( { sidebarName } ) => { - ) : ( -