-
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 all 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. |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,19 +4,13 @@ | |
import { | ||
BlockInspector, | ||
store as blockEditorStore, | ||
privateApis as blockEditorPrivateApis, | ||
} from '@wordpress/block-editor'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { | ||
Platform, | ||
useCallback, | ||
useContext, | ||
useEffect, | ||
useRef, | ||
} from '@wordpress/element'; | ||
import { isRTL, __ } from '@wordpress/i18n'; | ||
import { Platform, useCallback, useEffect, useRef } from '@wordpress/element'; | ||
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'; | ||
import { store as interfaceStore } from '@wordpress/interface'; | ||
|
||
/** | ||
|
@@ -28,7 +22,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'; | ||
|
@@ -41,7 +34,7 @@ import { | |
TEMPLATE_POST_TYPE, | ||
} from '../../store/constants'; | ||
|
||
const { Tabs } = unlock( componentsPrivateApis ); | ||
const { TabbedSidebar } = unlock( blockEditorPrivateApis ); | ||
|
||
const SIDEBAR_ACTIVE_BY_DEFAULT = Platform.select( { | ||
web: true, | ||
|
@@ -54,12 +47,9 @@ const SidebarContent = ( { | |
renderingMode, | ||
onActionPerformed, | ||
extraPanels, | ||
onSelect, | ||
} ) => { | ||
const tabListRef = useRef( null ); | ||
// Because `PluginSidebar` 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 ); | ||
|
||
// This effect addresses a race condition caused by tabbing from the last | ||
// block in the editor into the settings sidebar. Without this effect, the | ||
|
@@ -88,14 +78,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,22 +103,43 @@ const SidebarContent = ( { | |
toggleShortcut={ keyboardShortcut } | ||
icon={ isRTL() ? drawerLeft : drawerRight } | ||
isActiveByDefault={ SIDEBAR_ACTIVE_BY_DEFAULT } | ||
header={ false } | ||
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. If 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 don't think we need the closeLabel here either. |
||
> | ||
<Tabs.Context.Provider value={ tabsContextValue }> | ||
<Tabs.TabPanel tabId={ sidebars.document } focusable={ false }> | ||
<PostSummary onActionPerformed={ onActionPerformed } /> | ||
<PluginDocumentSettingPanel.Slot /> | ||
<TemplateContentPanel renderingMode={ renderingMode } /> | ||
<TemplatePartContentPanel /> | ||
<PostTransformPanel /> | ||
<PostTaxonomiesPanel /> | ||
<PatternOverridesPanel /> | ||
{ extraPanels } | ||
</Tabs.TabPanel> | ||
<Tabs.TabPanel tabId={ sidebars.block } focusable={ false }> | ||
<BlockInspector /> | ||
</Tabs.TabPanel> | ||
</Tabs.Context.Provider> | ||
<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 |
||
/> | ||
</PluginSidebar> | ||
); | ||
}; | ||
|
@@ -142,6 +159,7 @@ const Sidebar = ( { extraPanels, onActionPerformed } ) => { | |
sidebars.document, | ||
].includes( sidebar ); | ||
let _tabName = sidebar; | ||
|
||
if ( ! _isEditorSidebarOpened ) { | ||
_tabName = !! select( | ||
blockEditorStore | ||
|
@@ -176,20 +194,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> | ||
/> | ||
); | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -295,47 +295,51 @@ function ComplementaryArea( { | |
scope={ scope } | ||
id={ identifier.replace( '/', ':' ) } | ||
> | ||
<ComplementaryAreaHeader | ||
className={ headerClassName } | ||
closeLabel={ closeLabel } | ||
onClose={ () => disableComplementaryArea( scope ) } | ||
smallScreenTitle={ smallScreenTitle } | ||
toggleButtonProps={ { | ||
label: closeLabel, | ||
size: 'small', | ||
shortcut: toggleShortcut, | ||
scope, | ||
identifier, | ||
} } | ||
> | ||
{ header || ( | ||
<> | ||
<h2 className="interface-complementary-area-header__title"> | ||
{ title } | ||
</h2> | ||
{ isPinnable && ( | ||
<Button | ||
className="interface-complementary-area__pin-unpin-item" | ||
icon={ isPinned ? starFilled : starEmpty } | ||
label={ | ||
isPinned | ||
? __( 'Unpin from toolbar' ) | ||
: __( 'Pin to toolbar' ) | ||
} | ||
onClick={ () => | ||
( isPinned ? unpinItem : pinItem )( | ||
scope, | ||
identifier | ||
) | ||
} | ||
isPressed={ isPinned } | ||
aria-expanded={ isPinned } | ||
size="compact" | ||
/> | ||
) } | ||
</> | ||
) } | ||
</ComplementaryAreaHeader> | ||
{ header !== false && ( | ||
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 is the only change here - if header is explicitly set to false then we don't output it. This might break other things. 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 don't see a better way to do this either. |
||
<ComplementaryAreaHeader | ||
className={ headerClassName } | ||
closeLabel={ closeLabel } | ||
onClose={ () => disableComplementaryArea( scope ) } | ||
smallScreenTitle={ smallScreenTitle } | ||
toggleButtonProps={ { | ||
label: closeLabel, | ||
size: 'small', | ||
shortcut: toggleShortcut, | ||
scope, | ||
identifier, | ||
} } | ||
> | ||
{ header || ( | ||
<> | ||
<h2 className="interface-complementary-area-header__title"> | ||
{ title } | ||
</h2> | ||
{ isPinnable && ( | ||
<Button | ||
className="interface-complementary-area__pin-unpin-item" | ||
icon={ | ||
isPinned ? starFilled : starEmpty | ||
} | ||
label={ | ||
isPinned | ||
? __( 'Unpin from toolbar' ) | ||
: __( 'Pin to toolbar' ) | ||
} | ||
onClick={ () => | ||
( isPinned ? unpinItem : pinItem )( | ||
scope, | ||
identifier | ||
) | ||
} | ||
isPressed={ isPinned } | ||
aria-expanded={ isPinned } | ||
size="compact" | ||
/> | ||
) } | ||
</> | ||
) } | ||
</ComplementaryAreaHeader> | ||
) } | ||
<Panel className={ panelClassName }>{ children }</Panel> | ||
</ComplementaryAreaFill> | ||
</> | ||
|
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