Skip to content

Commit

Permalink
Plugin: Heading Block Initial Attempt
Browse files Browse the repository at this point in the history
Here is an initial attempt at using the current API for a heading block.
I just guessed as to how this should be structured, honestly have no
idea but I tried to mimic the codebase the best I could.
  • Loading branch information
BE-Webdesign authored and nylen committed Mar 27, 2017
1 parent 8e62d60 commit d66bbea
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
14 changes: 14 additions & 0 deletions blocks/components/wp-heading/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default function EditableHeading( { value, headingType } ) {
const headingsMap = {
H1: 'h1',
H2: 'h2',
H3: 'h3',
H4: 'h4',
H5: 'h5',
H6: 'h6',
};

const mapHeading = ( nodeName ) => headingsMap[ nodeName ];

return wp.element.createElement( mapHeading( headingType ), null, value );
}
1 change: 1 addition & 0 deletions blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as query from 'hpq';

export { query };
export { default as Editable } from './components/editable';
export { default as EditableHeading } from './components/wp-heading';
export { default as parse } from './parser';

/**
Expand Down
23 changes: 23 additions & 0 deletions editor/blocks/heading-block/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { query, html, prop } = wp.blocks.query;

wp.blocks.registerBlock( 'wp/heading', {
title: 'Heading',
icon: 'heading',

attributes: {
value: query( 'h1,h2,h3,h4,h5,h6', html() ),
headingType: query( 'h1,h2,h3,h4,h5,h6', prop( 'nodeName' ) ),
},

edit( attributes, onChange ) {
return wp.element.createElement( wp.blocks.EditableHeading, {
value: attributes.value,
headingType: attributes.headingType,
onChange: ( value ) => onChange( { value } )
} );
},

save( attributes ) {
return wp.element.createElement( 'p', null, attributes.value );
}
} );
1 change: 1 addition & 0 deletions editor/blocks/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import './text-block';
import './heading-block';

0 comments on commit d66bbea

Please sign in to comment.