Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blocks: Adding the quote block #419

Merged
merged 3 commits into from
Apr 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the effect we're trying to achieve with the transition? At least in my browser, the border width effect feels a little janky when switching between styles.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, let's remove that one. Though the idea of "transitioning between styles" is interesting, I think that will get old quickly, and it likely won't scale to other block transformations either.

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 @@ -38,6 +38,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