-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Blocks: Adding the quote block (#419)
- Loading branch information
1 parent
6b64b5c
commit ffc663c
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ import './heading'; | |
import './image'; | ||
import './text'; | ||
import './list'; | ||
import './quote'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters