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 1 commit
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 level controls to Site Title block
david-szabo97 marked this conversation as resolved.
Show resolved Hide resolved

## 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.

35 changes: 28 additions & 7 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 }`;
const tagName = 0 === level ? 'p' : `h${ level }`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't enforce Yoda conditions in our JS (since we're enforcing typed comparisons -- === instead of == -- anyway).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I copy-pasted it from the previous source and yeah, it felt strange to have Yoda conditions in JS. I'll revert this change since I don't like it either.


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