-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Site Title Block: Add alignment and tag level support (#22843)
* Add alignment control to the site title block edit function. * Add support for setting site title tag, and applying text alignment in the editor and front end. * Fix up classname output, and add a default site title classname. * Fix PHP linting issues.
- Loading branch information
Showing
3 changed files
with
47 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,9 @@ | |
"level": { | ||
"type": "number", | ||
"default": 1 | ||
}, | ||
"align": { | ||
"type": "string" | ||
} | ||
}, | ||
"supports": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,47 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useEntityProp } from '@wordpress/core-data'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
PlainText, | ||
RichText, | ||
AlignmentToolbar, | ||
BlockControls, | ||
__experimentalBlock as Block, | ||
} from '@wordpress/block-editor'; | ||
|
||
export default function SiteTitleEdit() { | ||
export default function SiteTitleEdit( { attributes, setAttributes } ) { | ||
const { level, align } = attributes; | ||
const [ title, setTitle ] = useEntityProp( 'root', 'site', 'title' ); | ||
const tagName = 0 === level ? 'p' : 'h' + level; | ||
|
||
return ( | ||
<PlainText | ||
__experimentalVersion={ 2 } | ||
tagName={ Block.h1 } | ||
placeholder={ __( 'Site Title' ) } | ||
value={ title } | ||
onChange={ setTitle } | ||
disableLineBreaks | ||
/> | ||
<> | ||
<BlockControls> | ||
<AlignmentToolbar | ||
value={ align } | ||
onChange={ ( nextAlign ) => { | ||
setAttributes( { align: nextAlign } ); | ||
} } | ||
/> | ||
</BlockControls> | ||
|
||
<RichText | ||
tagName={ Block[ tagName ] } | ||
placeholder={ __( 'Site Title' ) } | ||
value={ title } | ||
onChange={ setTitle } | ||
className={ classnames( { | ||
[ `has-text-align-${ align }` ]: align, | ||
} ) } | ||
allowedFormats={ [] } | ||
disableLineBreaks | ||
/> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters