Skip to content

Commit

Permalink
Merge pull request #607 from WordPress/add/547-pullquote
Browse files Browse the repository at this point in the history
Pullquote Block
  • Loading branch information
mkaz authored May 5, 2017
2 parents 6bed579 + 5996a31 commit dac64a6
Show file tree
Hide file tree
Showing 3 changed files with 94 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 @@ -7,3 +7,4 @@ import './list';
import './quote';
import './separator';
import './button';
import './pullquote';
70 changes: 70 additions & 0 deletions blocks/library/pullquote/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Internal dependencies
*/
import './style.scss';
import { registerBlock, query as hpq } from 'api';
import Editable from 'components/editable';

const { children, query } = hpq;

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

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

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

return (
<blockquote className="blocks-pullquote">
<Editable
value={ value || wp.i18n.__( 'Write Quote…' ) }
onChange={
( nextValue ) => setAttributes( {
value: nextValue
} )
}
focus={ focus && focus.editable === 'value' ? focus : null }
onFocus={ () => setFocus( { editable: 'value' } ) }
/>
{ ( citation || !! focus ) && (
<footer>
<Editable
tagName="footer"
value={ citation || wp.i18n.__( 'Write caption…' ) }
onChange={
( nextCitation ) => setAttributes( {
citation: nextCitation
} )
}
focus={ focus && focus.editable === 'citation' ? focus : null }
onFocus={ () => setFocus( { editable: 'citation' } ) }
inline
/>
</footer>
) }
</blockquote>
);
},

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

return (
<blockquote className="blocks-pullquote">
{ value && value.map( ( paragraph, i ) => (
<p key={ i }>{ paragraph }</p>
) ) }

{ citation && citation.length > 0 && (
<footer>{ citation }</footer>
) }
</blockquote>
);
}
} );
23 changes: 23 additions & 0 deletions blocks/library/pullquote/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.blocks-pullquote {
color: $light-gray-900;
padding: 2em;
text-align: center;

footer {
color: $dark-gray-900;
position: relative;
}

footer p {
font-size: 16px;
font-family: $default-font;
}
}

.editor-visual-editor .blocks-pullquote {
& > .blocks-editable p {
font-family: $default-font;
font-size: 48px;
font-weight: 900;
}
}

0 comments on commit dac64a6

Please sign in to comment.