Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore Site Title's Level toolbar and remove obsolete code #24758

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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