Skip to content

Commit

Permalink
Blocks: Adding the quote block (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Apr 17, 2017
1 parent 6b64b5c commit ffc663c
Show file tree
Hide file tree
Showing 4 changed files with 95 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 @@ -3,3 +3,4 @@ import './heading';
import './image';
import './text';
import './list';
import './quote';
66 changes: 66 additions & 0 deletions blocks/library/quote/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Internal dependencies
*/
import './style.scss';
import { registerBlock, query as hpq } from 'api';
import Editable from 'components/editable';

const { parse, html, query } = hpq;

const fromValueToParagraphs = ( value ) => value.map( ( paragraph ) => `<p>${ paragraph }</p>` ).join( '' );
const fromParagraphsToValue = ( paragraphs ) => parse( paragraphs, query( 'p', html() ) );

registerBlock( 'core/quote', {
title: wp.i18n.__( 'Quote' ),
icon: 'format-quote',
category: 'common',

attributes: {
value: query( 'blockquote > p', html() ),
citation: html( 'footer' )
},

edit( { attributes, setAttributes } ) {
const { value, citation } = attributes;

return (
<blockquote className="blocks-quote">
<Editable
value={ fromValueToParagraphs( value ) }
onChange={
( paragraphs ) => setAttributes( {
value: fromParagraphsToValue( paragraphs )
} )
} />
<footer>
<Editable
value={ citation }
onChange={
( newValue ) => setAttributes( {
citation: newValue
} )
} />
</footer>
</blockquote>
);
},

save( attributes ) {
const { value, citation } = attributes;

return (
<blockquote>
{ value.map( ( paragraph, i ) => (
<p
key={ i }
dangerouslySetInnerHTML={ {
__html: paragraph
} } />
) ) }
<footer dangerouslySetInnerHTML={ {
__html: citation
} } />
</blockquote>
);
}
} );
24 changes: 24 additions & 0 deletions blocks/library/quote/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.blocks-quote {
margin: 0;
box-shadow: inset 0px 0px 0px 0px $light-gray-500;
transition: all .2s ease;
font-size: 20px;
border-left: 4px solid $black;
padding-left: 1em;
font-style: italic;

footer {
color: $dark-gray-100;
font-size: 0.9em;
font-style: normal;
margin-left: 1.3em;
position: relative;

&:before {
content: '';
position: absolute;
left: -1.3em;
top: 0;
}
}
}
4 changes: 4 additions & 0 deletions languages/gutenberg.pot
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ msgstr ""
msgid "Justify"
msgstr ""

#: blocks/library/quote/index.js:14
msgid "Quote"
msgstr ""

#: blocks/library/text/index.js:10
msgid "Text"
msgstr ""
Expand Down

0 comments on commit ffc663c

Please sign in to comment.