Skip to content

Commit

Permalink
Use block label and icon for the inserter draggable chip. (#51048)
Browse files Browse the repository at this point in the history
* Use block label and icon for the inserter draggable blocks. Adjust the draggable chip width to respect the max-content.

* Only send `Pattern` as the label when it is a pattern.

* Apply suggestions from code review.

* Remove empty lines.

* add deps

---------

Co-authored-by: ntsekouras <ntsekouras@outlook.com>
  • Loading branch information
juanfra and ntsekouras committed Jun 26, 2023
1 parent 7ba89bc commit aafef4f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
height: $block-toolbar-height;
padding: 0 ( $grid-unit-15 + $border-width );
user-select: none;
width: max-content;

svg {
fill: currentColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* WordPress dependencies
*/
import { Draggable } from '@wordpress/components';
import { serialize } from '@wordpress/blocks';
import { serialize, store as blocksStore } from '@wordpress/blocks';
import { useSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
Expand All @@ -20,6 +21,16 @@ const InserterDraggableBlocks = ( {
blocks,
};

const blockTypeIcon = useSelect(
( select ) => {
const { getBlockType } = select( blocksStore );
return (
blocks.length === 1 && getBlockType( blocks[ 0 ].name )?.icon
);
},
[ blocks ]
);

return (
<Draggable
__experimentalTransferDataType="wp-blocks"
Expand All @@ -30,7 +41,7 @@ const InserterDraggableBlocks = ( {
__experimentalDragComponent={
<BlockDraggableChip
count={ blocks.length }
icon={ icon }
icon={ icon || ( ! isPattern && blockTypeIcon ) }
isPattern={ isPattern }
/>
}
Expand Down

0 comments on commit aafef4f

Please sign in to comment.