Skip to content

Commit

Permalink
Add buttons to change heading level
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Apr 17, 2017
1 parent 2849506 commit 8502267
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 35 deletions.
4 changes: 3 additions & 1 deletion blocks/components/editable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export default class Editable extends wp.element.Component {
}

componentDidUpdate( prevProps ) {
if ( this.props.value !== prevProps.value ) {
if ( this.props.tagName !== prevProps.tagName ) {
this.initialize();
} else if ( this.props.value !== prevProps.value ) {
this.updateContent();
}
}
Expand Down
32 changes: 8 additions & 24 deletions blocks/library/heading/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,15 @@ registerBlock( 'core/heading', {
},

controls: [
{
icon: 'editor-alignleft',
title: wp.i18n.__( 'Align left' ),
isActive: ( { align } ) => ! align || 'left' === align,
...'123456'.split( '' ).map( ( level ) => ( {
icon: 'editor-alignleft', // TODO
text: level,
title: wp.i18n.sprintf( wp.i18n.__( 'Heading %s' ), level ),
isActive: ( { tag } ) => 'H' + level === tag,
onClick( attributes, setAttributes ) {
setAttributes( { align: undefined } );
setAttributes( { tag: 'H' + level } );
}
},
{
icon: 'editor-aligncenter',
title: wp.i18n.__( 'Align center' ),
isActive: ( { align } ) => 'center' === align,
onClick( attributes, setAttributes ) {
setAttributes( { align: 'center' } );
}
},
{
icon: 'editor-alignright',
title: wp.i18n.__( 'Align right' ),
isActive: ( { align } ) => 'right' === align,
onClick( attributes, setAttributes ) {
setAttributes( { align: 'right' } );
}
}
} ) )
],

edit( { attributes, setAttributes } ) {
Expand All @@ -60,8 +45,7 @@ registerBlock( 'core/heading', {
},

save( { attributes } ) {
const { align, tag, content } = attributes;
const Tag = tag;
const { align, tag: Tag, content } = attributes;

return (
<Tag
Expand Down
3 changes: 2 additions & 1 deletion editor/components/icon-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import './style.scss';
import Button from '../button';
import Dashicon from '../dashicon';

function IconButton( { icon, label, className, ...additionalProps } ) {
function IconButton( { icon, text, label, className, ...additionalProps } ) {
const classes = classnames( 'editor-icon-button', className );

return (
<Button { ...additionalProps } aria-label={ label } className={ classes }>
<Dashicon icon={ icon } />
{ text ? <span>{ text }</span> : null }
</Button>
);
}
Expand Down
6 changes: 5 additions & 1 deletion editor/components/icon-button/style.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.editor-icon-button {
display: flex;
align-items: center;
width: 36px;
min-width: 36px;
height: 36px;
border: none;
background: none;
Expand All @@ -14,4 +14,8 @@
color: $blue-medium;
}
}

span {
font-size: 12px;
}
}
1 change: 1 addition & 0 deletions editor/components/toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function Toolbar( { controls } ) {
<IconButton
key={ index }
icon={ control.icon }
text={ control.text }
label={ control.title }
onClick={ ( event ) => {
event.stopPropagation();
Expand Down
20 changes: 12 additions & 8 deletions languages/gutenberg.pot
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ msgstr ""
msgid "Heading"
msgstr ""

#: blocks/library/heading/index.js:26
msgid "Heading %s"
msgstr ""

#: blocks/library/image/index.js:10
msgid "Image"
msgstr ""

#: blocks/library/image/index.js:31
msgid "Write caption…"
msgstr ""

#: blocks/library/heading/index.js:25
#: blocks/library/list/index.js:25
#: blocks/library/text/index.js:24
Expand All @@ -29,14 +41,6 @@ msgstr ""
msgid "Align right"
msgstr ""

#: blocks/library/image/index.js:10
msgid "Image"
msgstr ""

#: blocks/library/image/index.js:31
msgid "Write caption…"
msgstr ""

#: blocks/library/list/index.js:11
msgid "List"
msgstr ""
Expand Down

0 comments on commit 8502267

Please sign in to comment.