Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6bcef66
Add BlockControlsFirst slot to block controls groups
michalczaplinski Feb 19, 2024
3d6fe72
Add connection icon to BlockControls toolbar button
michalczaplinski Feb 19, 2024
385b13c
Add block binding toolbar button if block is connected to a source
michalczaplinski Feb 19, 2024
44b1c72
Add i18n support for block toolbar button label
michalczaplinski Feb 21, 2024
91c78a4
Add BlockBindingsButton component and remove BlockControlsFirst group
michalczaplinski Feb 21, 2024
be8afcd
Refactor BlockBindingsButton to check for block connections
michalczaplinski Feb 22, 2024
1c51cc2
Change the ToolbarButton label
michalczaplinski Feb 22, 2024
752dcc3
Update block-bindings-button import to block-bindings-indicator
michalczaplinski Feb 22, 2024
bbdd7bf
Block Bindings: Add connection icon to list view (#59331)
artemiomorales Feb 26, 2024
3bc3062
Move bindings style to useBlockProps
artemiomorales Feb 27, 2024
9d6f97c
Remove extraneous comment
artemiomorales Feb 27, 2024
ec3885d
Move bindings selector logic to toolbar
artemiomorales Feb 28, 2024
d9a4b88
Rename indicator file
artemiomorales Feb 28, 2024
d571f82
Move purple stroke style from SVG markup to CSS
artemiomorales Feb 28, 2024
6cd25eb
Merge branch 'trunk' into fix/update-block-bindings-ui-indicator
artemiomorales Feb 28, 2024
ac72c0a
Check if block can be bound before adding styles
artemiomorales Feb 28, 2024
f63e4ef
Simplify the SVG icon:
michalczaplinski Feb 29, 2024
3f9fa3b
Update the CSS namespacing to include the `__`
michalczaplinski Feb 29, 2024
4dc1103
Fix issues with block binding indicator color
michalczaplinski Feb 29, 2024
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
Prev Previous commit
Next Next commit
Add block binding toolbar button if block is connected to a source
  • Loading branch information
michalczaplinski authored and artemiomorales committed Feb 28, 2024
commit 385b13cb41d6c50bc3624d5f489c6753bfcceac1
30 changes: 21 additions & 9 deletions packages/block-editor/src/hooks/use-bindings-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const createEditFunctionWithBindingsAttribute = () =>
).getAllBlockBindingsSources();
const { getBlockAttributes } = useSelect( blockEditorStore );

let hasSource = false;

const updatedAttributes = getBlockAttributes( clientId );
if ( updatedAttributes?.metadata?.bindings ) {
Object.entries( updatedAttributes.metadata.bindings ).forEach(
Expand Down Expand Up @@ -74,27 +76,37 @@ const createEditFunctionWithBindingsAttribute = () =>

if ( metaValue ) {
updatedAttributes[ attributeName ] = metaValue;
hasSource = true;
}
}
}
);
}

return (
<>
<BlockControls group="first">
<ToolbarButton
icon={ connection }
label="Block bindings"
iconSize={ 24 }
></ToolbarButton>
</BlockControls>
// TODO: only set this if the block is connected to a source.
// this might not be a good way to do it if a block can have child
// blocks that are NOT connected to a source.
<div
style={
hasSource ? { '--wp-admin-theme-color': '#9747FF' } : {}
}
>
{ hasSource ? (
<BlockControls group="first">
<ToolbarButton
icon={ connection }
label="Block bindings"
iconSize={ 24 }
></ToolbarButton>
</BlockControls>
) : null }
<BlockEdit
key="edit"
{ ...props }
attributes={ updatedAttributes }
/>
</>
</div>
);
},
'useBoundAttributes'
Expand Down
4 changes: 2 additions & 2 deletions packages/icons/src/library/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const connection = (
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<Path d="M5 19L8 16L5 19Z" fill="#911BEE" />
<Path d="M16 8L19 5L16 8Z" fill="#911BEE" />
<Path d="M5 19L8 16L5 19Z" fill="#9747FF" />
<Path d="M16 8L19 5L16 8Z" fill="#9747FF" />
<G
stroke-width="1.5"
stroke-linecap="round"
Expand Down