Skip to content

Commit

Permalink
Add BlockBindingsButton component and remove BlockControlsFirst group
Browse files Browse the repository at this point in the history
  • Loading branch information
michalczaplinski authored and artemiomorales committed Feb 28, 2024
1 parent 44b1c72 commit 91c78a4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* WordPress dependencies
*/
import { ToolbarButton } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { connection } from '@wordpress/icons';
import { _x } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { store as blockEditorStore } from '../../store';

export default function BlockBindingsButton( { clientId } ) {
const { blockAttributes } = useSelect(
( select ) => {
const { getBlockAttributes } = select( blockEditorStore );
return {
blockAttributes: getBlockAttributes( clientId ),
};
},
[ clientId ]
);

return blockAttributes?.metadata?.bindings ? (
<ToolbarButton
icon={ connection }
label={ _x(
// TODO: Let's get this naming right
'Connected to a block bindings source',
'block toolbar button label'
) }
iconSize={ 24 }
></ToolbarButton>
) : null;
}
2 changes: 0 additions & 2 deletions packages/block-editor/src/components/block-controls/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ const BlockControlsBlock = createSlotFill( 'BlockControlsBlock' );
const BlockControlsInline = createSlotFill( 'BlockFormatControls' );
const BlockControlsOther = createSlotFill( 'BlockControlsOther' );
const BlockControlsParent = createSlotFill( 'BlockControlsParent' );
const BlockControlsFirst = createSlotFill( 'BlockControlsFirst' );

const groups = {
default: BlockControlsDefault,
block: BlockControlsBlock,
inline: BlockControlsInline,
other: BlockControlsOther,
parent: BlockControlsParent,
first: BlockControlsFirst,
};

export default groups;
7 changes: 2 additions & 5 deletions packages/block-editor/src/components/block-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import __unstableBlockNameContext from './block-name-context';
import NavigableToolbar from '../navigable-toolbar';
import { useHasAnyBlockControls } from '../block-controls/use-has-block-controls';
import Shuffle from './shuffle';
import BlockBindingsButton from '../block-bindings-button';

/**
* Renders the block toolbar.
Expand Down Expand Up @@ -166,11 +167,7 @@ export function PrivateBlockToolbar( {
{ ! isMultiToolbar &&
isLargeViewport &&
isDefaultEditingMode && <BlockParentSelector /> }
<BlockControls.Slot
// TODO: Rename "first" to something more meaningful.
group="first"
className="block-editor-block-toolbar__slot"
/>
<BlockBindingsButton clientId={ blockClientId } />
{ ( shouldShowVisualToolbar || isMultiToolbar ) &&
isDefaultEditingMode && (
<div
Expand Down
17 changes: 0 additions & 17 deletions packages/block-editor/src/hooks/use-bindings-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ import { getBlockType, store as blocksStore } from '@wordpress/blocks';
import { createHigherOrderComponent } from '@wordpress/compose';
import { useSelect } from '@wordpress/data';
import { addFilter } from '@wordpress/hooks';
import { ToolbarButton } from '@wordpress/components';
import { connection } from '@wordpress/icons';
import { _x } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { BlockControls } from '../components';
import { store as blockEditorStore } from '../store';
import { useBlockEditContext } from '../components/block-edit/context';
import { unlock } from '../lock-unlock';
Expand Down Expand Up @@ -93,19 +89,6 @@ const createEditFunctionWithBindingsAttribute = () =>
hasSource ? { '--wp-admin-theme-color': '#9747FF' } : {}
}
>
{ hasSource ? (
<BlockControls group="first">
<ToolbarButton
icon={ connection }
label={ _x(
// TODO: Let's get this naming right
'Connected to a block bindings source',
'block toolbar button label'
) }
iconSize={ 24 }
></ToolbarButton>
</BlockControls>
) : null }
<BlockEdit
key="edit"
{ ...props }
Expand Down
6 changes: 3 additions & 3 deletions packages/icons/src/library/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const connection = (
<Path d="M5 19L8 16L5 19Z" fill="#9747FF" />
<Path d="M16 8L19 5L16 8Z" fill="#9747FF" />
<G
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
stroke="#9747FF"
>
<Path d="M5 19L8 16" />
Expand Down

0 comments on commit 91c78a4

Please sign in to comment.