Skip to content

Commit

Permalink
Add verse block
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jul 8, 2017
1 parent dfdc4f9 commit f816789
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
1 change: 1 addition & 0 deletions blocks/library/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ import './html';
import './freeform';
import './latest-posts';
import './cover-image';
import './verse';
2 changes: 1 addition & 1 deletion blocks/library/preformatted/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Editable from '../../editable';
const { children } = query;

registerBlockType( 'core/preformatted', {
title: __( 'Preformatted' ),
title: __( 'Preformatted Text' ),

icon: 'text',

Expand Down
68 changes: 68 additions & 0 deletions blocks/library/verse/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* WordPress
*/
import { __ } from 'i18n';

/**
* Internal dependencies
*/
import './style.scss';
import { registerBlockType, createBlock, query } from '../../api';
import Editable from '../../editable';

const { children } = query;

registerBlockType( 'core/verse', {
title: __( 'Verse' ),

icon: 'edit',

category: 'formatting',

attributes: {
content: children( 'pre' ),
},

transforms: {
from: [
{
type: 'block',
blocks: [ 'core/text' ],
transform: ( attributes ) =>
createBlock( 'core/verse', attributes ),
},
],
to: [
{
type: 'block',
blocks: [ 'core/text' ],
transform: ( attributes ) =>
createBlock( 'core/text', attributes ),
},
],
},

edit( { attributes, setAttributes, focus, setFocus, className } ) {
const { content } = attributes;

return (
<Editable
tagName="pre"
value={ content }
onChange={ ( nextContent ) => {
setAttributes( {
content: nextContent,
} );
} }
focus={ focus }
onFocus={ setFocus }
placeholder={ __( 'Write…' ) }
className={ className }
/>
);
},

save( { attributes, className } ) {
return <pre className={ className }>{ attributes.content }</pre>;
},
} );
8 changes: 8 additions & 0 deletions blocks/library/verse/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pre.wp-block-verse,
.wp-block-verse pre {
white-space: nowrap;
font-family: inherit;
font-size: inherit;
color: inherit;
padding: 1em;
}

0 comments on commit f816789

Please sign in to comment.