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 Block Bindings Panel to Block Inspector #61527

Merged
merged 18 commits into from
May 17, 2024
Merged
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
70 changes: 70 additions & 0 deletions packages/block-editor/src/hooks/block-bindings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { store as blocksStore } from '@wordpress/blocks';
import {
PanelBody,
__experimentalHStack as HStack,
__experimentalItemGroup as ItemGroup,
__experimentalItem as Item,
} from '@wordpress/components';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import { unlock } from '../lock-unlock';
import InspectorControls from '../components/inspector-controls';

export const BlockBindingsPanel = ( { metadata } ) => {
const { bindings } = metadata || {};
const { sources } = useSelect( ( select ) => {
const _sources = unlock(
select( blocksStore )
).getAllBlockBindingsSources();

return {
sources: _sources,
};
}, [] );

if ( ! bindings ) {
return null;
}

return (
<InspectorControls>
<PanelBody
title={ __( 'Bindings' ) }
className="components-panel__block-bindings-panel"
>
<ItemGroup isBordered isSeparated size="large">
{ Object.keys( bindings ).map( ( key ) => {
return (
<Item key={ key }>
<HStack>
<span>{ key }</span>
<span className="components-item__block-bindings-source">
{ sources[ bindings[ key ].source ]
? sources[ bindings[ key ].source ]
.label
: bindings[ key ].source }
</span>
</HStack>
</Item>
);
} ) }
</ItemGroup>
</PanelBody>
</InspectorControls>
);
};

export default {
edit: BlockBindingsPanel,
attributeKeys: [ 'metadata' ],
hasSupport() {
return true;
},
};
3 changes: 3 additions & 0 deletions packages/block-editor/src/hooks/block-bindings.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.components-panel__block-bindings-panel .components-item__block-bindings-source {
color: $gray-700;
}
2 changes: 2 additions & 0 deletions packages/block-editor/src/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ import childLayout from './layout-child';
import contentLockUI from './content-lock-ui';
import './metadata';
import blockHooks from './block-hooks';
import blockBindingsPanel from './block-bindings';
import './block-renaming';
import './use-bindings-attributes';

createBlockEditFilter(
[
blockBindingsPanel,
align,
textAlign,
anchor,
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
@import "./components/tool-selector/style.scss";
@import "./components/url-input/style.scss";
@import "./components/url-popover/style.scss";
@import "./hooks/block-bindings.scss";
@import "./hooks/block-hooks.scss";
@import "./hooks/border.scss";
@import "./hooks/color.scss";
Expand Down
Loading