Skip to content

Commit ffa22b8

Browse files
Restore Site Title's Level toolbar and remove obsolete code (#24758)
By mistake, we had two edit files. One at `/edit.js` and one at `/edit/index.js`. Looks like the Level toolbar functionality was added by this commit 988ba5d#diff-655f76535495d8ae1d82693b57a4ffba at`/edit/index.js` and later on `/edit.js` was created again by this commit 0446ed1#diff-655f76535495d8ae1d82693b57a4ffba . After this commit, we lost the Level Toolbar which was residing in the `/edit/index.js`. Since we had an `edit` folder and an `edit.js` file, the import was confusing since we had no idea whether the file or the folder being resolved. This PR cleans up the mistake by removing the `/edit.js` and re-adding the Level toolbar. Co-authored-by: Bernie Reiter <ockham@raz.or.at>
1 parent 4b821c4 commit ffa22b8

File tree

3 files changed

+31
-53
lines changed

3 files changed

+31
-53
lines changed

packages/block-library/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### New Features
6+
7+
- Add heading level controls to Site Title block.
8+
59
## 2.12.0 (2020-01-13)
610

711
### Bug Fixes

packages/block-library/src/site-title/edit.js

-47
This file was deleted.

packages/block-library/src/site-title/edit/index.js

+27-6
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,58 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import classnames from 'classnames';
5+
16
/**
27
* WordPress dependencies
38
*/
49
import { useEntityProp } from '@wordpress/core-data';
5-
import { BlockControls, RichText } from '@wordpress/block-editor';
610
import { __ } from '@wordpress/i18n';
11+
import {
12+
RichText,
13+
AlignmentToolbar,
14+
BlockControls,
15+
__experimentalBlock as Block,
16+
} from '@wordpress/block-editor';
717

818
/**
919
* Internal dependencies
1020
*/
1121
import LevelToolbar from './level-toolbar';
1222

13-
export default function SiteTitleEdit( {
14-
attributes: { level },
15-
setAttributes,
16-
} ) {
23+
export default function SiteTitleEdit( { attributes, setAttributes } ) {
24+
const { level, textAlign } = attributes;
1725
const [ title, setTitle ] = useEntityProp( 'root', 'site', 'title' );
1826
const tagName = level === 0 ? 'p' : `h${ level }`;
27+
1928
return (
2029
<>
2130
<BlockControls>
31+
<AlignmentToolbar
32+
value={ textAlign }
33+
onChange={ ( nextAlign ) => {
34+
setAttributes( { textAlign: nextAlign } );
35+
} }
36+
/>
37+
2238
<LevelToolbar
2339
level={ level }
2440
onChange={ ( newLevel ) =>
2541
setAttributes( { level: newLevel } )
2642
}
2743
/>
2844
</BlockControls>
45+
2946
<RichText
30-
tagName={ tagName }
47+
tagName={ Block[ tagName ] }
3148
placeholder={ __( 'Site Title' ) }
3249
value={ title }
3350
onChange={ setTitle }
51+
className={ classnames( {
52+
[ `has-text-align-${ textAlign }` ]: textAlign,
53+
} ) }
3454
allowedFormats={ [] }
55+
disableLineBreaks
3556
/>
3657
</>
3758
);

0 commit comments

Comments
 (0)