-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Blocks: Adding the quote block #419
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,4 @@ import './freeform'; | |
| import './image'; | ||
| import './text'; | ||
| import './list'; | ||
| import './quote'; | ||
| 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> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to hide this when the citation is empty and we're not focusing the block but it's not possible for now, because the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Should we create an issue to track this, or do you plan to tackle this in the near future?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was planing to take a look at this (but don't know really when) Let's create an issue for this :)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| <Editable | ||
| value={ citation } | ||
| onChange={ ( newValue ) => setAttributes( { citation: newValue } ) } /> | ||
| </footer> | ||
| </blockquote> | ||
| ); | ||
| }, | ||
|
|
||
| save( attributes ) { | ||
| const { value, citation } = attributes; | ||
| return ( | ||
| <blockquote> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we'll need some
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 How do we apply the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, we ought to be thinking about this, because I don't think it's particularly obvious and the "dangerous" terminology is quite off-putting. Perhaps we can walk the tree returned from the function and manually revise string children as |
||
| { value } | ||
| { !! citation && | ||
| <footer> | ||
| { citation } | ||
| </footer> | ||
| } | ||
| </blockquote> | ||
| ); | ||
| } | ||
| } ); | ||
| 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; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
|
||
| &:after { | ||
|
||
| content: '— '; | ||
| position: absolute; | ||
| left: -1.3em; | ||
| top: 0; | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, the shadow conflict. It's been on my mind lately whether we should rename
wp.blocks.queryto something else. I thought perhapsparsebeing the default exported function with other methods as properties available via destructuring, but I'm not sure I like the idea of block implementers thinking of this as a parse action (even if it is 😄 ).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we could simply reference
hpqas a proper external dependency and expect plugin authors to enqueue it themselves as a preloaded dependency. I quite liked masking the underlying implementation detail and providing a single unified interface for blocks though.