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: Add quote blocks style controls #482

Merged
merged 7 commits into from
Apr 21, 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
2 changes: 1 addition & 1 deletion blocks/library/heading/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ registerBlock( 'core/heading', {
onClick( attributes, setAttributes ) {
setAttributes( { tag: 'H' + level } );
},
level
subscript: level
} ) )
],

Expand Down
25 changes: 21 additions & 4 deletions blocks/library/quote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import './style.scss';
import { registerBlock, query as hpq } from 'api';
import Editable from 'components/editable';

const { parse, html, query } = hpq;
const { parse, html, query, attr } = hpq;

const fromValueToParagraphs = ( value ) => value ? value.map( ( paragraph ) => `<p>${ paragraph }</p>` ).join( '' ) : '';
const fromParagraphsToValue = ( paragraphs ) => parse( paragraphs, query( 'p', html() ) );
Expand All @@ -17,14 +17,30 @@ registerBlock( 'core/quote', {

attributes: {
value: query( 'blockquote > p', html() ),
citation: html( 'footer' )
citation: html( 'footer' ),
style: node => {
const value = attr( 'blockquote', 'class' )( node );
const match = value.match( /\bblocks-quote-style-(\d+)\b/ );
Copy link
Member

Choose a reason for hiding this comment

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

What happens if the class is removed from the blockquote ?

return match ? +match[ 1 ] : null;
},
},

controls: [ 1, 2 ].map( ( variation ) => ( {
icon: 'format-quote',
title: wp.i18n.sprintf( wp.i18n.__( 'Quote style %d' ), variation ),
isActive: ( { style = 1 } ) => +style === +variation,
onClick( attributes, setAttributes ) {
setAttributes( { style: variation } );
},
subscript: variation
} ) ),

edit( { attributes, setAttributes, focus, setFocus } ) {
const { value, citation } = attributes;
const style = +attributes.style || 1;

return (
<blockquote className="blocks-quote">
<blockquote className={ `blocks-quote blocks-quote-style-${ style }` }>
<Editable
value={ fromValueToParagraphs( value ) }
onChange={
Expand Down Expand Up @@ -55,9 +71,10 @@ registerBlock( 'core/quote', {

save( attributes ) {
const { value, citation } = attributes;
const style = +attributes.style || 1;

return (
<blockquote>
<blockquote className={ `blocks-quote-style-${ style }` }>
{ value && value.map( ( paragraph, i ) => (
<p
key={ i }
Expand Down
27 changes: 21 additions & 6 deletions blocks/library/quote/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
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;

p {
font-size: 0.9em;
font-style: normal;
}

&:before {
content: '— ';
position: absolute;
Expand All @@ -22,3 +21,19 @@
}
}
}

.editor-visual-editor .blocks-quote-style-1 {
border-left: 4px solid $black;
padding-left: 1em;
& > .blocks-editable p {
font-size: 20px;
}
}

.editor-visual-editor .blocks-quote-style-2 {
padding: 0 1em;
& > .blocks-editable p {
font-size: 24px;
font-style: italic;
}
}
2 changes: 1 addition & 1 deletion editor/components/toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Toolbar( { controls } ) {
key={ index }
icon={ control.icon }
label={ control.title }
data-level={ control.level }
data-subscript={ control.subscript }
onClick={ ( event ) => {
event.stopPropagation();
control.onClick();
Expand Down
4 changes: 2 additions & 2 deletions editor/components/toolbar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
color: $white;
}

&[data-level]:after {
content: attr( data-level );
&[data-subscript]:after {
content: attr( data-subscript );
font-family: $default-font;
font-size: 10px;
font-weight: bold;
Expand Down
4 changes: 4 additions & 0 deletions languages/gutenberg.pot
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ msgstr ""
msgid "Quote"
msgstr ""

#: blocks/library/quote/index.js:30
msgid "Quote style %d"
msgstr ""

#: blocks/library/text/index.js:13
msgid "Text"
msgstr ""
Expand Down
2 changes: 1 addition & 1 deletion post-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ window._wpGutenbergPost = {
'<!-- /wp:core/text -->',

'<!-- wp:core/quote -->',
'<blockquote><p>Real artists ship.</p><footer><p><a href="http://www.folklore.org/StoryView.py?story=Real_Artists_Ship.txt">Steve Jobs, 1983</a></p></footer></blockquote>',
'<blockquote class="blocks-quote-style-2"><p>Real artists ship.</p><footer><p><a href="http://www.folklore.org/StoryView.py?story=Real_Artists_Ship.txt">Steve Jobs, 1983</a></p></footer></blockquote>',
'<!-- /wp:core/quote -->',

'<!-- wp:core/image -->',
Expand Down