-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Blocks: Add quote blocks style controls #482
Conversation
blocks/library/quote/index.js
Outdated
@@ -20,11 +20,21 @@ registerBlock( 'core/quote', { | |||
citation: html( 'footer' ) | |||
}, | |||
|
|||
controls: [ '1', '2' ].map( ( level ) => ( { |
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 sure level
applies as well here as it does for a heading. variant
, variation
, or style
might be more accurate.
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.
Minor: Do you think it's any different or better to treat '1'
as a string vs. 1
as a number?
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.
I think a string is better to avoid any confusion while parsing and serializing the attribute back.
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, that's a good point. Speaking of... how are we parsing the attribute?
blocks/library/quote/index.js
Outdated
@@ -20,11 +20,21 @@ registerBlock( 'core/quote', { | |||
citation: html( 'footer' ) | |||
}, | |||
|
|||
controls: [ '1', '2' ].map( ( level ) => ( { | |||
icon: 'format-quote', | |||
title: wp.i18n.sprintf( wp.i18n.__( 'Quote %s' ), level ), |
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 should probably use %d
placeholder, see also #423 (comment)
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.
revert this change because I'm using strings
Having a hard time tracking down the specific discussion, but I know this had been raised at some point. Maybe a theme can define compatibility via |
blocks/library/quote/index.js
Outdated
onClick( attributes, setAttributes ) { | ||
setAttributes( { style: variation } ); | ||
}, | ||
variation |
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.
Looks like we've highlighted a problem that our <Toolbar />
is tightly coupled to the idea of a heading level:
https://github.com/WordPress/gutenberg/blob/d068400/editor/components/toolbar/index.js#L24
Edit: Unless we think "level" is appropriate terminology for the subscript adjacent a control. Now that I've used the word... maybe "subscript" ?
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.
Do you think we should rename it variation
or suffix
or something like that?
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 shame that our blueprinting wordsmith @jasmussen is absent today 😄
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.
I like subscript
0cacdaf
to
2fa1233
Compare
The quote style is a number; let's treat it like a number.
To me a better way to address this is to cast the value where it may be necessary to do so. Done in 968ec56. I also changed Edit: if either of these changes are not desired, feel free to revert, but they make sense to me. |
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.
Still looks like we're not ever parsing the style attribute.
Thanks @nylen for these changes, I do prefer the simpler string parsing, the 1,2 here are just identifiers for me and not really numbers but It's really minor. Let's ship it. |
citation: html( 'footer' ), | ||
style: node => { | ||
const value = attr( 'blockquote', 'class' )( node ); | ||
const match = value.match( /\bblocks-quote-style-(\d+)\b/ ); |
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.
What happens if the class
is removed from the blockquote
?
Makes me wonder at what point we start to defer to comment-serialized attributes as hints for what also exists in the markup, just to avoid complexity of matching class patterns etc. Which leads into another question... if we did serialize the quote style in the comment, it'd have to be parsed as a string, yeah? Unless we did adopt JSON or another pattern to distinguish between strings and other types:
<!-- wp:quote style:2 -->
<!-- wp:quote foo:"definitely-a-string" style:2 --> <!-- wp:quote {"foo":"definitely-a-string","style":2} --> |
Good question @aduth I guess like HTML attributes comment attributes are strings by default. I guess everything could be represented as a string but JSON attributes could be a good alternative especially for complex attributes (object attributes). Note that we already store the "align" attribute for the text block in the comment |
We could adopt strict JSON behavior for the value, always wrapping string in |
Following up on a couple of things here...
In this case I think the right thing to do would be to make them identifiers (string names) rather than numbers. I don't have a strong preference, I just think we should decide one way or the other and then stick to that decision fully.
I think we should try to avoid these attributes as much as possible, again in the interest of avoiding duplicated information.
Agree that our current method of storing attributes isn't very robust. I'd like to see either HTML-style attributes <!-- wp:quote {"foo":"definitely-a-string","style":2} --> |
I will defer to you all on what exactly to do here, as I'm sure there are intricate reasons one way or the other. To add some context, we are likely to see many other blocks as plugins, including special quote blocks perhaps with extra parameters. So when is it a new block vs. when is it a style for an existing block? I think it should be a style when it's the exact same markup and exact same surfaced parameters, and it would be lovely if someday maybe plugins could also add extra styles to existing blocks. That might be more scalable if they were numbers. |
I think the opposite is true. How do we guarantee that the numbers wouldn't conflict or change over time? It would be pretty bad to have a quote's style change depending on which plugins happened to be active at the time, for example. Here are the pros and cons I can think of at the moment. NumbersPros: Simpler mapping between data / names / toolbar icons; we don't have to try to name these things. Cons: More difficult for plugin authors. As above, how do we guarantee that numbers don't conflict or change over time? NamesPros: More explicit, more opportunity for plugins to create their own styles (they should probably be namespaced by plugin name, with a standard way to add styles across blocks). Cons: We have to name them; we have to surface the names in a user-friendly and accessible way. Overall I think names is probably a better way to go, but this can wait a while and we need to think through what we want this functionality to be able to do. For example, anything we allow plugins to do should be namespaced. |
#311
In this PR I'm adding the quote styles controls.
The question here is how we provide these styles to the theme developers, should they be automatically included, or do we expect theme authors to implement these two styles on their own? This question could probably be answered separately.