-
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 all 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> | ||
); | ||
} | ||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#editor blockquote { | ||
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 it's preferable to add a class to the 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. Okay, sounds good. 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'm not the best person for naming things hahaha :) Always had trouble with it. I'll choose 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 matching the slug for the block would be a good place to start. That way the css classes are namespaced like the blocks are. 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. At some point we'll also need to consider if blocks can define their own default styles when rendered on the front-end of a site. 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.
To make it overridable, the fewer inline styles the better. The editor can't prevent the user from adding inline styles in raw mode, but it shouldn't encourage them in visual mode. The theme and plugins will be supplying the styles for the front-end look, though, so the block itself shouldn't have "default" styles beyond what the browser defines. The current method of defining editor-style.css should work the same way for this, right? 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. Right, I don't think we'd want to encourage any inline styles, which furthers the need to consider stylesheets distinguished between the editor and front-end versions of a block. While the blocks here are first-party, we should outline and use an approach consistent with what we expect from plugin authors who implement their own blocks (a plugin which implements a slider block will need ability to define editor and front-end baseline styles). Whatever we land on, I agree that theme styles should always take precedence when defined for a block. 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. To be clear, I think the editor should not define any styles for rendering the content in the blocks. |
||
margin: 2em; | ||
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. margin: 0 ? 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 just copying styles that I found in one of the prototypes. I can change these later got to go for now. 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. Yep, I guess the other one had a margin in all the blocks. The margin felt a bit weird while testing. |
||
box-shadow: inset 0px 0px 0px 0px #e0e5e9; | ||
transition: all .2s ease; | ||
font-size: 20px; | ||
border-left: 4px solid black; | ||
padding-left: 1em; | ||
font-style: italic; | ||
} | ||
|
||
#editor blockquote footer { | ||
color: #86909b; | ||
font-size: 0.9em; | ||
font-style: normal; | ||
margin-left: 1.3em; | ||
position: relative; | ||
} | ||
|
||
#editor blockquote footer: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.
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.