-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Plugin: Quote Block Initial Attempt #327
Changes from 5 commits
6afa34a
45414b6
ca95a8c
d253927
89c8dce
3cb0c08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
import './text'; | ||
import './quote'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const Editable = wp.blocks.Editable; | ||
const { html } = wp.blocks.query; | ||
|
||
wp.blocks.registerBlock( 'core/quote', { | ||
title: 'Quote', | ||
icon: 'format-quote', | ||
category: 'common', | ||
|
||
attributes: { | ||
value: html( 'blockquote > p' ), | ||
citation: html( 'footer' ) | ||
}, | ||
|
||
edit( attributes, onChange ) { | ||
const { value, citation } = attributes; | ||
|
||
return ( | ||
<blockquote> | ||
<Editable | ||
value={ value } | ||
onChange={ ( newValue ) => onChange( { value: newValue } ) } /> | ||
<footer> | ||
<Editable | ||
value={ citation } | ||
onChange={ ( newValue ) => onChange( { citation: newValue } ) } /> | ||
</footer> | ||
</blockquote> | ||
); | ||
}, | ||
|
||
save( attributes ) { | ||
const { value, citation } = attributes; | ||
return ( | ||
<blockquote> | ||
{ value } | ||
<footer> | ||
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. We may want to account for the case that 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. Yup sounds good! For some reason this slipped my brain, great catch. Does 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, specifically an |
||
{ citation } | ||
</footer> | ||
</blockquote> | ||
); | ||
} | ||
} ); |
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.
A
blockquote
could contain multiple paragraphs. In my explorer demo I usetext: query( 'p', html() )
instead which assignstext
as an array of each paragraph's HTML.https://aduth.github.io/hpq/
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.
Oh my bad, it was my recommendation
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.
Could we join the output directly using
hpq
?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.
We will probably want to map the values in
value
to its of<p>
component as well right?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.
Not super cleanly, but possible. Since each matcher is just a function receiving a node, you can create your own pass-through:
Or some compose-y equivalent.
I don't know that it's necessary a big issue to need to deal with this in the render behavior though.