Skip to content

Commit

Permalink
Restore Site Title's Level toolbar and remove obsolete code (#24758)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
david-szabo97 and ockham authored Aug 25, 2020
1 parent 4b821c4 commit ffa22b8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 53 deletions.
4 changes: 4 additions & 0 deletions packages/block-library/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### New Features

- Add heading level controls to Site Title block.

## 2.12.0 (2020-01-13)

### Bug Fixes
Expand Down
47 changes: 0 additions & 47 deletions packages/block-library/src/site-title/edit.js

This file was deleted.

33 changes: 27 additions & 6 deletions packages/block-library/src/site-title/edit/index.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,58 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
import { useEntityProp } from '@wordpress/core-data';
import { BlockControls, RichText } from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import {
RichText,
AlignmentToolbar,
BlockControls,
__experimentalBlock as Block,
} from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import LevelToolbar from './level-toolbar';

export default function SiteTitleEdit( {
attributes: { level },
setAttributes,
} ) {
export default function SiteTitleEdit( { attributes, setAttributes } ) {
const { level, textAlign } = attributes;
const [ title, setTitle ] = useEntityProp( 'root', 'site', 'title' );
const tagName = level === 0 ? 'p' : `h${ level }`;

return (
<>
<BlockControls>
<AlignmentToolbar
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { textAlign: nextAlign } );
} }
/>

<LevelToolbar
level={ level }
onChange={ ( newLevel ) =>
setAttributes( { level: newLevel } )
}
/>
</BlockControls>

<RichText
tagName={ tagName }
tagName={ Block[ tagName ] }
placeholder={ __( 'Site Title' ) }
value={ title }
onChange={ setTitle }
className={ classnames( {
[ `has-text-align-${ textAlign }` ]: textAlign,
} ) }
allowedFormats={ [] }
disableLineBreaks
/>
</>
);
Expand Down

0 comments on commit ffa22b8

Please sign in to comment.