-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Inspector: Use the TabbedSidebar component #63184
base: trunk
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,3 +49,8 @@ | |
} | ||
} | ||
|
||
.block-editor__tabbed-sidebar { | ||
@include break-medium() { | ||
width: 350px; | ||
} | ||
} | ||
Comment on lines
+52
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This style also defines the inserter sidebar's width, so it feels like it's blurring the lines of the inserter and list view. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import { | ||
BlockInspector, | ||
store as blockEditorStore, | ||
privateApis as blockEditorPrivateApis, | ||
} from '@wordpress/block-editor'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { | ||
|
@@ -13,7 +14,7 @@ import { | |
useEffect, | ||
useRef, | ||
} from '@wordpress/element'; | ||
import { isRTL, __ } from '@wordpress/i18n'; | ||
import { isRTL, __, _x } from '@wordpress/i18n'; | ||
import { drawerLeft, drawerRight } from '@wordpress/icons'; | ||
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts'; | ||
import { privateApis as componentsPrivateApis } from '@wordpress/components'; | ||
|
@@ -28,7 +29,6 @@ import PluginSidebar from '../plugin-sidebar'; | |
import PostSummary from './post-summary'; | ||
import PostTaxonomiesPanel from '../post-taxonomies/panel'; | ||
import PostTransformPanel from '../post-transform-panel'; | ||
import SidebarHeader from './header'; | ||
scruffian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import TemplateContentPanel from '../template-content-panel'; | ||
import TemplatePartContentPanel from '../template-part-content-panel'; | ||
import useAutoSwitchEditorSidebars from '../provider/use-auto-switch-editor-sidebars'; | ||
|
@@ -42,6 +42,7 @@ import { | |
} from '../../store/constants'; | ||
|
||
const { Tabs } = unlock( componentsPrivateApis ); | ||
const { TabbedSidebar } = unlock( blockEditorPrivateApis ); | ||
|
||
const SIDEBAR_ACTIVE_BY_DEFAULT = Platform.select( { | ||
web: true, | ||
|
@@ -54,6 +55,7 @@ const SidebarContent = ( { | |
renderingMode, | ||
onActionPerformed, | ||
extraPanels, | ||
onSelect, | ||
} ) => { | ||
const tabListRef = useRef( null ); | ||
// Because `PluginSidebar` renders a `ComplementaryArea`, we | ||
|
@@ -88,14 +90,20 @@ const SidebarContent = ( { | |
} | ||
}, [ tabName ] ); | ||
|
||
const { documentLabel } = useSelect( ( select ) => { | ||
const { getPostTypeLabel } = select( editorStore ); | ||
|
||
return { | ||
// translators: Default label for the Document sidebar tab, not selected. | ||
documentLabel: getPostTypeLabel() || _x( 'Document', 'noun' ), | ||
}; | ||
}, [] ); | ||
|
||
const { disableComplementaryArea } = useDispatch( interfaceStore ); | ||
|
||
return ( | ||
<PluginSidebar | ||
identifier={ tabName } | ||
header={ | ||
<Tabs.Context.Provider value={ tabsContextValue }> | ||
<SidebarHeader ref={ tabListRef } /> | ||
</Tabs.Context.Provider> | ||
} | ||
closeLabel={ __( 'Close Settings' ) } | ||
// This classname is added so we can apply a corrective negative | ||
// margin to the panel. | ||
|
@@ -107,7 +115,45 @@ const SidebarContent = ( { | |
toggleShortcut={ keyboardShortcut } | ||
icon={ isRTL() ? drawerLeft : drawerRight } | ||
isActiveByDefault={ SIDEBAR_ACTIVE_BY_DEFAULT } | ||
hideHeader | ||
> | ||
<TabbedSidebar | ||
tabs={ [ | ||
{ | ||
name: sidebars.document, | ||
title: documentLabel, | ||
panel: ( | ||
<> | ||
<PostSummary | ||
onActionPerformed={ onActionPerformed } | ||
/> | ||
<PluginDocumentSettingPanel.Slot /> | ||
<TemplateContentPanel | ||
renderingMode={ renderingMode } | ||
/> | ||
<TemplatePartContentPanel /> | ||
<PostTransformPanel /> | ||
<PostTaxonomiesPanel /> | ||
<PatternOverridesPanel /> | ||
{ extraPanels } | ||
</> | ||
), | ||
}, | ||
{ | ||
name: sidebars.block, | ||
title: __( 'Block' ), | ||
panel: <BlockInspector />, | ||
}, | ||
] } | ||
onClose={ () => disableComplementaryArea( 'core' ) } | ||
onSelect={ onSelect } | ||
selectedTab={ tabName } | ||
defaultTabId={ sidebars.document } | ||
ref={ tabListRef } | ||
closeButtonLabel={ __( 'Close Settings' ) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous label included the shortcut was |
||
tabsContextValue={ tabsContextValue } | ||
/> | ||
|
||
<Tabs.Context.Provider value={ tabsContextValue }> | ||
<Tabs.TabPanel tabId={ sidebars.document } focusable={ false }> | ||
<PostSummary onActionPerformed={ onActionPerformed } /> | ||
|
@@ -142,6 +188,7 @@ const Sidebar = ( { extraPanels, onActionPerformed } ) => { | |
sidebars.document, | ||
].includes( sidebar ); | ||
let _tabName = sidebar; | ||
|
||
if ( ! _isEditorSidebarOpened ) { | ||
_tabName = !! select( | ||
blockEditorStore | ||
|
@@ -176,20 +223,16 @@ const Sidebar = ( { extraPanels, onActionPerformed } ) => { | |
); | ||
|
||
return ( | ||
<Tabs | ||
<SidebarContent | ||
tabName={ tabName } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the tab-related data here should get moved within the SidebarContent rather than passed as props. I think it was done here previously because the Tabs needed be wrapping the SidebarContent. Now that we have a different structure, I think we could move it within. |
||
keyboardShortcut={ keyboardShortcut } | ||
showSummary={ showSummary } | ||
renderingMode={ renderingMode } | ||
onActionPerformed={ onActionPerformed } | ||
extraPanels={ extraPanels } | ||
selectedTabId={ tabName } | ||
onSelect={ onTabSelect } | ||
selectOnMove={ false } | ||
> | ||
<SidebarContent | ||
tabName={ tabName } | ||
keyboardShortcut={ keyboardShortcut } | ||
showSummary={ showSummary } | ||
renderingMode={ renderingMode } | ||
onActionPerformed={ onActionPerformed } | ||
extraPanels={ extraPanels } | ||
/> | ||
</Tabs> | ||
/> | ||
); | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need this so that we can set a width for only the inserter a the list view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ends up compiling to
block-editor-tabbed-sidebar block-editor__tabbed-sidebar
which feels like a workaround. How about one of these options:block-editor-tabbed-sidebar--wide
block-editor-inserter__tabbed-inserter