Skip to content

Commit

Permalink
Fix Site Title toolbar normalization (#31032)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras authored Apr 21, 2021
1 parent 1fd4a92 commit 8c87d1c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
8 changes: 4 additions & 4 deletions packages/block-library/src/site-title/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useEntityProp } from '@wordpress/core-data';
import { __ } from '@wordpress/i18n';
import {
RichText,
AlignmentToolbar,
AlignmentControl,
BlockControls,
useBlockProps,
} from '@wordpress/block-editor';
Expand All @@ -19,7 +19,7 @@ import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
/**
* Internal dependencies
*/
import LevelToolbar from './level-toolbar';
import LevelControl from './level-toolbar';

export default function SiteTitleEdit( {
attributes,
Expand All @@ -37,13 +37,13 @@ export default function SiteTitleEdit( {
return (
<>
<BlockControls group="block">
<LevelToolbar
<LevelControl
level={ level }
onChange={ ( newLevel ) =>
setAttributes( { level: newLevel } )
}
/>
<AlignmentToolbar
<AlignmentControl
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { textAlign: nextAlign } );
Expand Down
42 changes: 19 additions & 23 deletions packages/block-library/src/site-title/edit/level-toolbar.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
/**
* WordPress dependencies
*/
import { ToolbarGroup } from '@wordpress/components';
import { DropdownMenu } from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import LevelIcon from './level-icon';

export default function LevelToolbar( { level, onChange } ) {
export default function LevelControl( { level, onChange } ) {
const allControls = [ 1, 2, 3, 4, 5, 6, 0 ].map( ( currentLevel ) => {
const isActive = currentLevel === level;
return {
icon: <LevelIcon level={ currentLevel } isPressed={ isActive } />,
title:
currentLevel === 0
? __( 'Paragraph' )
: // translators: %s: heading level e.g: "1", "2", "3"
sprintf( __( 'Heading %d' ), currentLevel ),
isActive,
onClick: () => onChange( currentLevel ),
};
} );
return (
<ToolbarGroup
isCollapsed
icon={ <LevelIcon level={ level } /> }
controls={ [ 1, 2, 3, 4, 5, 6, 0 ].map( ( currentLevel ) => {
const isActive = currentLevel === level;
return {
icon: (
<LevelIcon
level={ currentLevel }
isPressed={ isActive }
/>
),
title:
currentLevel === 0
? __( 'Paragraph' )
: // translators: %s: heading level e.g: "1", "2", "3"
sprintf( __( 'Heading %d' ), currentLevel ),
isActive,
onClick: () => onChange( currentLevel ),
};
} ) }
<DropdownMenu
label={ __( 'Change heading level' ) }
icon={ <LevelIcon level={ level } /> }
controls={ allControls }
isToolbarButton
/>
);
}

0 comments on commit 8c87d1c

Please sign in to comment.