@wordpress/block-library
Version:
Block library for the WordPress editor.
48 lines (40 loc) • 1.09 kB
JavaScript
import { page, addSubmenu } from '@wordpress/icons';
import { _x } from '@wordpress/i18n';
import initBlock from '../utils/init-block';
import metadata from './block.json';
import edit from './edit';
import save from './save';
import transforms from './transforms';
const { name } = metadata;
export { metadata, name };
export const settings = {
icon: ( { context } ) => {
if ( context === 'list-view' ) {
return page;
}
return addSubmenu;
},
__experimentalLabel( attributes, { context } ) {
const { label } = attributes;
const customName = attributes?.metadata?.name;
// In the list view and breadcrumb, use the block's menu label as the label.
// If the menu label is empty, fall back to the default label.
if (
( context === 'list-view' || context === 'breadcrumb' ) &&
customName
) {
return customName;
}
return label;
},
edit,
example: {
attributes: {
label: _x( 'About', 'Example link text for Navigation Submenu' ),
type: 'page',
},
},
save,
transforms,
};
export const init = () => initBlock( { name, metadata, settings } );