Skip to content

Commit c8cefe7

Browse files
committed
Customize block titles
1 parent 04b367d commit c8cefe7

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

src/block/blocks/image/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
import type { BlockConfiguration } from '@wordpress/blocks';
22
import { registerBlockType } from '@wordpress/blocks';
33
import { __ } from '@wordpress/i18n';
4+
import { KnownElemNames } from '../../edit';
45
import Edit from './edit';
56
import { ImageIcon } from '../../components';
67
import metadata from './block.json';
78

9+
const title = __( 'Image', 'gravatar-enhanced' );
10+
811
const blockConfig: BlockConfiguration = {
912
...metadata,
1013
icon: ImageIcon,
11-
title: __( 'Image', 'gravatar-enhanced' ),
14+
// @ts-ignore
15+
__experimentalLabel: ( { name } ) => {
16+
if ( ! name ) {
17+
return title;
18+
}
19+
20+
return name === KnownElemNames.AVATAR ? __( 'Avatar', 'gravatar-enhanced' ) : name;
21+
},
22+
title,
1223
description: __( 'The Image block for the Gravatar block.', 'gravatar-enhanced' ),
1324
edit: Edit,
1425
};

src/block/blocks/link/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import type { BlockConfiguration } from '@wordpress/blocks';
22
import { registerBlockType } from '@wordpress/blocks';
33
import { __ } from '@wordpress/i18n';
4+
import { KnownElemNames } from '../../edit';
45
import Edit from './edit';
56
import { LinkIcon } from '../../components';
67
import metadata from './block.json';
78

9+
const title = __( 'Link', 'gravatar-enhanced' );
10+
811
const blockConfig: BlockConfiguration = {
912
...metadata,
1013
icon: LinkIcon,
11-
title: __( 'Link', 'gravatar-enhanced' ),
14+
// @ts-ignore
15+
__experimentalLabel: ( { name } ) => {
16+
return name === KnownElemNames.VIEW_PROFILE ? __( 'Profile Link', 'gravatar-enhanced' ) : title;
17+
},
18+
title,
1219
description: __( 'The Link block for the Gravatar block.', 'gravatar-enhanced' ),
1320
edit: Edit,
1421
};

src/block/blocks/paragraph/index.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
import type { BlockConfiguration } from '@wordpress/blocks';
22
import { registerBlockType } from '@wordpress/blocks';
33
import { __ } from '@wordpress/i18n';
4+
import { KnownElemNames } from '../../edit';
45
import Edit from './edit';
56
import { ParagraphIcon } from '../../components';
67
import metadata from './block.json';
78

9+
const title = __( 'Paragraph', 'gravatar-enhanced' );
10+
811
const blockConfig: BlockConfiguration = {
912
...metadata,
1013
icon: ParagraphIcon,
11-
title: __( 'Paragraph', 'gravatar-enhanced' ),
14+
// @ts-ignore
15+
__experimentalLabel: ( { name } ) => {
16+
switch ( name ) {
17+
case KnownElemNames.JOB:
18+
return __( 'Job Title', 'gravatar-enhanced' );
19+
case KnownElemNames.COMPANY:
20+
return __( 'Company', 'gravatar-enhanced' );
21+
case KnownElemNames.LOCATION:
22+
return __( 'Location', 'gravatar-enhanced' );
23+
case KnownElemNames.DESCRIPTION:
24+
return __( 'About Me', 'gravatar-enhanced' );
25+
default:
26+
return title;
27+
}
28+
},
29+
title,
1230
description: __( 'The Paragraph block for the Gravatar block.', 'gravatar-enhanced' ),
1331
edit: Edit,
1432
};

src/block/edit.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ export default function Edit( { attributes, setAttributes, clientId }: BlockEdit
263263
...verified_accounts,
264264
];
265265
const verifiedAccounts = verified_accounts.map(
266-
( { url, service_type, service_icon, service_label, is_hidden } ) =>
266+
( { url, service_icon, service_label, is_hidden } ) =>
267267
! is_hidden &&
268-
getBlockTempate( BlockNames.IMAGE, service_type, {
268+
getBlockTempate( BlockNames.IMAGE, service_label, {
269269
linkUrl: url,
270270
imageUrl: service_icon,
271271
imageWidth: 32,

0 commit comments

Comments
 (0)