-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide list view tab and slot for nav block
- Loading branch information
1 parent
8530a42
commit 4bda26d
Showing
5 changed files
with
79 additions
and
6 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
44 changes: 44 additions & 0 deletions
44
packages/block-editor/src/components/inspector-controls-tabs/list-view-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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalUseSlotFills as useSlotFills } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import InspectorControls from '../inspector-controls'; | ||
import InspectorControlsGroups from '../inspector-controls/groups'; | ||
|
||
// This tab restricts the blocks that may render to it via the whitelist below. | ||
const whitelist = [ 'core/navigation' ]; | ||
|
||
export const useIsListViewDisabled = ( blockName ) => { | ||
return ! whitelist.includes( blockName ); | ||
}; | ||
|
||
const ListViewTab = ( { blockName, hasSingleBlockSelection } ) => { | ||
const { list } = InspectorControlsGroups; | ||
const fills = useSlotFills( list.Slot.__unstableName ) || []; | ||
|
||
// Unlike other tabs the List View is much more niche. As such it will be | ||
// omitted if the current block isn't in the whitelist. | ||
if ( useIsListViewDisabled( blockName ) ) { | ||
return; | ||
} | ||
|
||
return ( | ||
<> | ||
{ ! fills.length && ( | ||
<span className="block-editor-block-inspector__no-block-tools"> | ||
{ hasSingleBlockSelection | ||
? __( 'This block has no list options.' ) | ||
: __( 'The selected blocks have no list options.' ) } | ||
</span> | ||
) } | ||
<InspectorControls.Slot __experimentalGroup="list" /> | ||
</> | ||
); | ||
}; | ||
|
||
export default ListViewTab; |
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