Skip to content
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

Add InspectorBlockInfo using SlotFill method #66170

Open
wants to merge 7 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/block-editor/src/components/block-card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ import { useSelect, useDispatch } from '@wordpress/data';
import BlockIcon from '../block-icon';
import { store as blockEditorStore } from '../../store';

function BlockCard( { title, icon, description, blockType, className, name } ) {
function BlockCard( {
title,
icon,
description,
blockType,
className,
name,
inspectorBlockInfo,
} ) {
if ( blockType ) {
deprecated( '`blockType` property in `BlockCard component`', {
since: '5.7',
Expand Down Expand Up @@ -78,6 +86,9 @@ function BlockCard( { title, icon, description, blockType, className, name } ) {
{ description && (
<Text className="block-editor-block-card__description">
{ description }
<div className="block-editor-block-card__inspector-block-info">
{ inspectorBlockInfo }
</div>
</Text>
) }
</VStack>
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export {
* Content Related Components
*/

export { default as InspectorBlockInfoFill } from './inspector-block-info/inspector-block-info';
export { default as __unstableBlockSettingsMenuFirstItem } from './block-settings-menu/block-settings-menu-first-item';
export { default as __unstableBlockToolbarLastItem } from './block-toolbar/block-toolbar-last-item';
export { default as __unstableBlockNameContext } from './block-toolbar/block-name-context';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* WordPress dependencies
*/
import { createSlotFill } from '@wordpress/components';

/**
* Internal dependencies
*/
import {
useBlockEditContext,
mayDisplayControlsKey,
} from '../block-edit/context';

const { Fill, Slot } = createSlotFill( 'InspectorBlockInfoFill' );

const InspectorBlockInfoFill = ( props ) => {
const context = useBlockEditContext();
if ( ! context[ mayDisplayControlsKey ] ) {
return null;
}
return <Fill { ...props } />;
};
InspectorBlockInfoFill.Slot = ( props ) => <Slot { ...props } />;

export default InspectorBlockInfoFill;
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import InspectorBlockInfoFill from '../inspector-block-info/inspector-block-info';
import { store as blockEditorStore } from '../../store';

/** @typedef {import('@wordpress/blocks').WPIcon} WPIcon */
Expand Down Expand Up @@ -98,6 +99,7 @@ export default function useBlockDisplayInformation( clientId ) {
positionLabel,
positionType: attributes?.style?.position?.type,
name: attributes?.metadata?.name,
inspectorBlockInfo: <InspectorBlockInfoFill.Slot />,
};
if ( ! match ) {
return blockTypeInfo;
Expand All @@ -112,6 +114,7 @@ export default function useBlockDisplayInformation( clientId ) {
positionLabel,
positionType: attributes?.style?.position?.type,
name: attributes?.metadata?.name,
inspectorBlockInfo: <InspectorBlockInfoFill.Slot />,
};
},
[ clientId ]
Expand Down
Loading