-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sidebar: Only render sidebar tabs possessing items to display (#45991)
- Loading branch information
1 parent
220e945
commit 511072b
Showing
7 changed files
with
95 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 0 additions & 44 deletions
44
packages/block-editor/src/components/inspector-controls-tabs/list-view-tab.js
This file was deleted.
Oops, something went wrong.
47 changes: 11 additions & 36 deletions
47
packages/block-editor/src/components/inspector-controls-tabs/settings-tab.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,18 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalUseSlotFills as useSlotFills } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import AdvancedControls from './advanced-controls-panel'; | ||
import InspectorControlsGroups from '../inspector-controls/groups'; | ||
import { | ||
default as InspectorControls, | ||
InspectorAdvancedControls, | ||
} from '../inspector-controls'; | ||
|
||
const SettingsTab = ( { hasSingleBlockSelection = false } ) => { | ||
const { default: defaultGroup } = InspectorControlsGroups; | ||
const settingsFills = [ | ||
...( useSlotFills( defaultGroup.Slot.__unstableName ) || [] ), | ||
...( useSlotFills( InspectorAdvancedControls.slotName ) || [] ), | ||
]; | ||
import { default as InspectorControls } from '../inspector-controls'; | ||
|
||
return ( | ||
<> | ||
<InspectorControls.Slot /> | ||
{ hasSingleBlockSelection && ( | ||
<div> | ||
<AdvancedControls /> | ||
</div> | ||
) } | ||
{ ! settingsFills.length && ( | ||
<span className="block-editor-block-inspector__no-block-tools"> | ||
{ hasSingleBlockSelection | ||
? __( 'This block has no settings.' ) | ||
: __( 'The selected blocks have no settings.' ) } | ||
</span> | ||
) } | ||
</> | ||
); | ||
}; | ||
const SettingsTab = ( { showAdvancedControls = false } ) => ( | ||
<> | ||
<InspectorControls.Slot /> | ||
{ showAdvancedControls && ( | ||
<div> | ||
<AdvancedControls /> | ||
</div> | ||
) } | ||
</> | ||
); | ||
|
||
export default SettingsTab; |
58 changes: 58 additions & 0 deletions
58
packages/block-editor/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalUseSlotFills as useSlotFills } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import InspectorControlsGroups from '../inspector-controls/groups'; | ||
import useIsListViewTabDisabled from './use-is-list-view-tab-disabled'; | ||
import { InspectorAdvancedControls } from '../inspector-controls'; | ||
import { TAB_LIST_VIEW, TAB_SETTINGS, TAB_APPEARANCE } from './utils'; | ||
|
||
export default function useInspectorControlsTabs( blockName ) { | ||
const tabs = []; | ||
const { | ||
border: borderGroup, | ||
color: colorGroup, | ||
default: defaultGroup, | ||
dimensions: dimensionsGroup, | ||
list: listGroup, | ||
typography: typographyGroup, | ||
} = InspectorControlsGroups; | ||
|
||
// List View Tab: If there are any fills for the list group add that tab. | ||
const listViewDisabled = useIsListViewTabDisabled( blockName ); | ||
const listFills = useSlotFills( listGroup.Slot.__unstableName ); | ||
|
||
if ( ! listViewDisabled && !! listFills && listFills.length ) { | ||
tabs.push( TAB_LIST_VIEW ); | ||
} | ||
|
||
// Appearance Tab: Add this tab if there are any fills for block supports | ||
// e.g. border, color, spacing, typography, etc. | ||
const appearanceFills = [ | ||
...( useSlotFills( borderGroup.Slot.__unstableName ) || [] ), | ||
...( useSlotFills( colorGroup.Slot.__unstableName ) || [] ), | ||
...( useSlotFills( dimensionsGroup.Slot.__unstableName ) || [] ), | ||
...( useSlotFills( typographyGroup.Slot.__unstableName ) || [] ), | ||
]; | ||
|
||
if ( appearanceFills.length ) { | ||
tabs.push( TAB_APPEARANCE ); | ||
} | ||
|
||
// Settings Tab: If there are any fills for the general InspectorControls | ||
// or Advanced Controls slot, then add this tab. | ||
const settingsFills = [ | ||
...( useSlotFills( defaultGroup.Slot.__unstableName ) || [] ), | ||
...( useSlotFills( InspectorAdvancedControls.slotName ) || [] ), | ||
]; | ||
|
||
if ( settingsFills.length ) { | ||
tabs.push( TAB_SETTINGS ); | ||
} | ||
|
||
return tabs; | ||
} |
9 changes: 9 additions & 0 deletions
9
...ages/block-editor/src/components/inspector-controls-tabs/use-is-list-view-tab-disabled.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// List view tab restricts the blocks that may render to it via the | ||
// allowlist below. | ||
const allowlist = [ 'core/navigation' ]; | ||
|
||
export const useIsListViewTabDisabled = ( blockName ) => { | ||
return ! allowlist.includes( blockName ); | ||
}; | ||
|
||
export default useIsListViewTabDisabled; |