Skip to content
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

Merged
merged 7 commits into from
Apr 21, 2017
Merged

Conversation

youknowriad
Copy link
Contributor

@youknowriad youknowriad commented Apr 21, 2017

#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.

@youknowriad youknowriad added the [Feature] Blocks Overall functionality of blocks label Apr 21, 2017
@youknowriad youknowriad self-assigned this Apr 21, 2017
@@ -20,11 +20,21 @@ registerBlock( 'core/quote', {
citation: html( 'footer' )
},

controls: [ '1', '2' ].map( ( level ) => ( {
Copy link
Member

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.

Copy link
Member

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?

Copy link
Contributor Author

@youknowriad youknowriad Apr 21, 2017

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.

Copy link
Member

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?

@@ -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 ),
Copy link
Member

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)

Copy link
Contributor Author

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

@aduth
Copy link
Member

aduth commented Apr 21, 2017

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?

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 add_theme_support? In which case we'd need a way to vary client-side block controls by server-side theme supports. Might tie in desire outlined in #399 to have server-side block filtering.

onClick( attributes, setAttributes ) {
setAttributes( { style: variation } );
},
variation
Copy link
Member

@aduth aduth Apr 21, 2017

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" ?

Copy link
Contributor Author

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?

Copy link
Member

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 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like subscript

@youknowriad youknowriad force-pushed the add/quote-block-styles branch from 0cacdaf to 2fa1233 Compare April 21, 2017 14:24
@nylen
Copy link
Member

nylen commented Apr 21, 2017

The quote style is a number; let's treat it like a number.

I think a string is better to avoid any confusion while parsing and serializing the attribute back.

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 Quote %d to Quote style %d because the latter makes more sense without context.

Edit: if either of these changes are not desired, feel free to revert, but they make sense to me.

aduth
aduth previously requested changes Apr 21, 2017
Copy link
Member

@aduth aduth left a 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.

@nylen nylen dismissed aduth’s stale review April 21, 2017 15:35

Good catch - done in 02e832c.

@youknowriad
Copy link
Contributor Author

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.

@youknowriad youknowriad merged commit f75cdde into master Apr 21, 2017
@youknowriad youknowriad deleted the add/quote-block-styles branch April 21, 2017 16:51
citation: html( 'footer' ),
style: node => {
const value = attr( 'blockquote', 'class' )( node );
const match = value.match( /\bblocks-quote-style-(\d+)\b/ );
Copy link
Member

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 ?

@aduth
Copy link
Member

aduth commented Apr 21, 2017

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:

style as string:

<!-- wp:quote style:2 -->

style as number:

<!-- wp:quote foo:"definitely-a-string" style:2 -->
<!-- wp:quote {"foo":"definitely-a-string","style":2} -->

@youknowriad
Copy link
Contributor Author

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

@aduth
Copy link
Member

aduth commented Apr 21, 2017

We could adopt strict JSON behavior for the value, always wrapping string in ". Also resolves the need for values with spaces.

http://www.json.org/value.gif

@nylen
Copy link
Member

nylen commented Apr 27, 2017

Following up on a couple of things here...

I do prefer the simpler string parsing, the 1,2 here are just identifiers for me and not really numbers

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.

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.

I think we should try to avoid these attributes as much as possible, again in the interest of avoiding duplicated information.

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:

Agree that our current method of storing attributes isn't very robust. I'd like to see either HTML-style attributes name="value" or - if we know that we really need to store typed data - this option:

<!-- wp:quote {"foo":"definitely-a-string","style":2} -->

@jasmussen
Copy link
Contributor

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 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.

@nylen
Copy link
Member

nylen commented Apr 28, 2017

[plugins adding extra styles] 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.

Numbers

Pros: 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?

Names

Pros: 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants