Skip to content

Commit

Permalink
Improve passing of ToolsPanel header through slot props
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Sep 2, 2021
1 parent 730c02c commit b101ce6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 30 deletions.
2 changes: 2 additions & 0 deletions packages/block-editor/src/components/block-inspector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ const BlockInspectorSingleBlock = ( {
<InspectorControls.Slot
__experimentalGroup="dimensions"
bubblesVirtually={ false }
header={ __( 'Dimensions' ) }
label={ __( 'Dimensions options' ) }
/>
<div>
<AdvancedControls bubblesVirtually={ bubblesVirtually } />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import { useDispatch, useSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import { BLOCK_SUPPORT_GROUPS } from './constants';
import { store as blockEditorStore } from '../../store';
import { cleanEmptyObject } from '../../hooks/utils';

export default function BlockSupportToolsPanel( { group, children } ) {
export default function BlockSupportToolsPanel( { children, label, header } ) {
const { clientId, attributes } = useSelect( ( select ) => {
const { getBlockAttributes, getSelectedBlockClientId } = select(
blockEditorStore
Expand Down Expand Up @@ -47,8 +46,8 @@ export default function BlockSupportToolsPanel( { group, children } ) {

return (
<ToolsPanel
label={ BLOCK_SUPPORT_GROUPS[ group ]?.label }
header={ BLOCK_SUPPORT_GROUPS[ group ]?.header }
label={ label }
header={ header }
resetAll={ resetAll }
key={ clientId }
panelId={ clientId }
Expand Down

This file was deleted.

11 changes: 8 additions & 3 deletions packages/block-editor/src/components/inspector-controls/slot.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import warning from '@wordpress/warning';
/**
* Internal dependencies
*/
import { BLOCK_SUPPORT_GROUPS } from './constants';
import BlockSupportToolsPanel from './block-support-tools-panel';
import groups from './groups';

export default function InspectorControlsSlot( {
__experimentalGroup: group = 'default',
bubblesVirtually = true,
label,
header,
...props
} ) {
const Slot = groups[ group ]?.Slot;
Expand All @@ -28,9 +29,13 @@ export default function InspectorControlsSlot( {
return null;
}

if ( BLOCK_SUPPORT_GROUPS[ group ] ) {
if ( header ) {
return (
<BlockSupportToolsPanel group={ group }>
<BlockSupportToolsPanel
group={ group }
header={ header }
label={ label }
>
<Slot { ...props } bubblesVirtually={ bubblesVirtually } />
</BlockSupportToolsPanel>
);
Expand Down

0 comments on commit b101ce6

Please sign in to comment.