Skip to content
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
17 changes: 17 additions & 0 deletions blocks/block-controls/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* External dependencies
*/
import { Fill } from 'react-slot-fill';

/**
* WordPress dependencies
*/
import Toolbar from 'components/toolbar';

export default function BlockControls( { controls } ) {
return (
<Fill name="Formatting.Toolbar">
<Toolbar controls={ controls } />
</Fill>
);
}
34 changes: 19 additions & 15 deletions blocks/library/heading/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { isString } from 'lodash';
import './style.scss';
import { registerBlock, createBlock, query } from '../../api';
import Editable from '../../editable';
import BlockControls from '../../block-controls';

const { children, prop } = query;

Expand All @@ -24,18 +25,6 @@ registerBlock( 'core/heading', {
nodeName: prop( 'h1,h2,h3,h4,h5,h6', 'nodeName' ),
},

controls: [
...'123456'.split( '' ).map( ( level ) => ( {
icon: 'heading',
title: wp.i18n.sprintf( wp.i18n.__( 'Heading %s' ), level ),
isActive: ( { nodeName } ) => 'H' + level === nodeName,
onClick( attributes, setAttributes ) {
setAttributes( { nodeName: 'H' + level } );
},
subscript: level,
} ) ),
],

transforms: {
from: [
{
Expand Down Expand Up @@ -90,17 +79,32 @@ registerBlock( 'core/heading', {
edit( { attributes, setAttributes, focus, setFocus, mergeBlocks } ) {
const { content, nodeName = 'H2' } = attributes;

return (
return [
focus && (
<BlockControls
key="controls"
controls={
'123456'.split( '' ).map( ( level ) => ( {
icon: 'heading',
title: wp.i18n.sprintf( wp.i18n.__( 'Heading %s' ), level ),
isActive: 'H' + level === nodeName,
onClick: () => setAttributes( { nodeName: 'H' + level } ),
subscript: level,
} ) )
}
/>
),
<Editable
key="editable"
tagName={ nodeName.toLowerCase() }
value={ content }
focus={ focus }
onFocus={ setFocus }
onChange={ ( value ) => setAttributes( { content: value } ) }
onMerge={ mergeBlocks }
inline
/>
);
/>,
];
},

save( { attributes } ) {
Expand Down