Skip to content

Commit

Permalink
Add verse block (#1809)
Browse files Browse the repository at this point in the history
* Add block and tests.
* Adjust pre text block title and verse icon.
* Exclude link from format toolbar and darken text color.
  • Loading branch information
ellatrix authored and mtias committed Jul 11, 2017
1 parent d1e4c32 commit e74afaf
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 0 deletions.
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';
69 changes: 69 additions & 0 deletions blocks/library/verse/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* 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: 'carrot',

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 }
formattingControls={ [ 'bold', 'italic', 'strikethrough' ] }
/>
);
},

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 {
color: $dark-gray-900;
white-space: nowrap;
font-family: inherit;
font-size: inherit;
padding: 1em;
}
3 changes: 3 additions & 0 deletions blocks/test/fixtures/core__verse.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:core/verse -->
<pre class="wp-block-verse">A <em>verse</em><br>And more!</pre>
<!-- /wp:core/verse -->
20 changes: 20 additions & 0 deletions blocks/test/fixtures/core__verse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"uid": "_uid_0",
"name": "core/verse",
"attributes": {
"content": [
"A ",
{
"type": "em",
"children": "verse"
},
"",
{
"type": "br"
},
"And more!"
]
}
}
]
11 changes: 11 additions & 0 deletions blocks/test/fixtures/core__verse.parsed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"blockName": "core/verse",
"attrs": null,
"rawContent": "\n<pre class=\"wp-block-verse\">A <em>verse</em>…<br>And more!</pre>\n"
},
{
"attrs": {},
"rawContent": "\n"
}
]
3 changes: 3 additions & 0 deletions blocks/test/fixtures/core__verse.serialized.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:core/verse -->
<pre class="wp-block-verse">A <em>verse</em><br/>And more!</pre>
<!-- /wp:core/verse -->

0 comments on commit e74afaf

Please sign in to comment.