Skip to content

Commit

Permalink
Use custom name in block sidebar if available (retaining block type i…
Browse files Browse the repository at this point in the history
…nformation) (WordPress#65641)

* Use Badge for the block type

* Wrap when custom name is long enough

* Fix calc

Co-authored-by: getdave <[email protected]>
Co-authored-by: draganescu <[email protected]>
Co-authored-by: mikachan <[email protected]>
Co-authored-by: jameskoster <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: jeryj <[email protected]>
Co-authored-by: richtabor <[email protected]>
  • Loading branch information
8 people authored and yogeshbhutkar committed Dec 18, 2024
1 parent 57a642b commit da900fc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
26 changes: 21 additions & 5 deletions packages/block-editor/src/components/block-card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@ import {
Button,
__experimentalText as Text,
__experimentalVStack as VStack,
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { chevronLeft, chevronRight } from '@wordpress/icons';
import { __, _x, isRTL, sprintf } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';
import { createInterpolateElement } from '@wordpress/element';

/**
* Internal dependencies
*/
import BlockIcon from '../block-icon';
import { store as blockEditorStore } from '../../store';
import { unlock } from '../../lock-unlock';

const { Badge } = unlock( componentsPrivateApis );

function BlockCard( { title, icon, description, blockType, className, name } ) {
if ( blockType ) {
Expand Down Expand Up @@ -67,11 +72,22 @@ function BlockCard( { title, icon, description, blockType, className, name } ) {
<VStack spacing={ 1 }>
<h2 className="block-editor-block-card__title">
{ name?.length
? sprintf(
// translators: 1: Custom block name. 2: Block title.
_x( '%1$s (%2$s)', 'block label' ),
name,
title
? createInterpolateElement(
sprintf(
// translators: 1: Custom block name. 2: Block title.
_x(
'<span>%1$s</span> <badge>%2$s</badge>',
'block label'
),
name,
title
),
{
span: (
<span className="block-editor-block-card__name" />
),
badge: <Badge />,
}
)
: title }
</h2>
Expand Down
5 changes: 5 additions & 0 deletions packages/block-editor/src/components/block-card/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

.block-editor-block-card__title {
font-weight: 500;
display: flex;
align-items: center;
flex-wrap: wrap;
gap: calc($grid-unit-10 / 2) $grid-unit-10;

&.block-editor-block-card__title {
font-size: $default-font-size;
Expand All @@ -27,3 +31,4 @@
.block-editor-block-card.is-synced .block-editor-block-icon {
color: var(--wp-block-synced-color);
}

0 comments on commit da900fc

Please sign in to comment.