Skip to content

Commit

Permalink
Blocks: Adding the quote block
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Apr 13, 2017
1 parent 413e853 commit 3e1e031
Show file tree
Hide file tree
Showing 4 changed files with 79 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 @@ -2,3 +2,4 @@ import './freeform';
import './image';
import './text';
import './list';
import './quote';
50 changes: 50 additions & 0 deletions blocks/library/quote/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Internal dependencies
*/
import './style.scss';
import { registerBlock, query as hpq } from 'api';
import Editable from 'components/editable';

const { html, query } = hpq;

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

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

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

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

save( attributes ) {
const { value, citation } = attributes;
return (
<blockquote>
{ value }
{ !! citation &&
<footer>
{ citation }
</footer>
}
</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;

&:after {
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 @@ -38,6 +38,10 @@ msgstr ""
msgid "Justify"
msgstr ""

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

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

0 comments on commit 3e1e031

Please sign in to comment.