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

Social Icons: Add icon & background color options #28084

Merged
merged 5 commits into from
Jan 19, 2021

Conversation

aaronrobertshaw
Copy link
Contributor

@aaronrobertshaw aaronrobertshaw commented Jan 11, 2021

Fixes: #21605

Description

This is an alternate approach to #25372 using CSS variables on the primary Social Links block that are then used by styles on the individual Social Link blocks.

Compared to the original approach this PR:

  • Avoids having to maintain and pass color hex values through context to the individual blocks
  • Does not need to manually adjust server side rendering of social link blocks
  • Social Links block gets icon and background colors set as CSS variables which are used by CSS rules targeting the individual Social Link blocks.

How has this been tested?

Manual Testing.

  1. Create new post and add social links block with a few links added to it.
  2. Save post
  3. Checkout this PR
  4. Reload the editor and ensure no block validation errors
  5. Select the social links block and toggle icon or background color options
  6. Try switching block styles
    • "Logos only" style will clear any previous background color selection
    • Having only an icon color selected will result in no icon background color
  7. Save the post and confirm colors on the frontend match the editor.

Screenshots

TwentyTwentyOne TwentyTwenty
SocialLinksCSSVariables SocialLinksCSSVariables2

Types of changes

Enhancement

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@aaronrobertshaw aaronrobertshaw added [Type] Enhancement A suggestion for improvement. [Block] Social Affects the Social Block - used to display Social Media accounts [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi labels Jan 11, 2021
@aaronrobertshaw aaronrobertshaw self-assigned this Jan 11, 2021
@aaronrobertshaw aaronrobertshaw requested a review from mkaz as a code owner January 11, 2021 09:22
@github-actions
Copy link

github-actions bot commented Jan 11, 2021

Size Change: -18.2 kB (-1%)

Total Size: 1.28 MB

Filename Size Change
build/a11y/index.js 1.14 kB -1 B (0%)
build/annotations/index.js 3.8 kB -3 B (0%)
build/api-fetch/index.js 3.42 kB +2 B (0%)
build/autop/index.js 2.84 kB +5 B (0%)
build/blob/index.js 665 B +1 B (0%)
build/block-directory/index.js 9.08 kB +39 B (0%)
build/block-editor/index.js 122 kB -8.4 kB (-6%)
build/block-editor/style-rtl.css 11.9 kB +561 B (+5%) 🔍
build/block-editor/style.css 11.9 kB +567 B (+5%) 🔍
build/block-library/blocks/cover/editor-rtl.css 524 B +16 B (+3%)
build/block-library/blocks/cover/editor.css 522 B +16 B (+3%)
build/block-library/blocks/cover/style-rtl.css 1.3 kB -28 B (-2%)
build/block-library/blocks/cover/style.css 1.3 kB -26 B (-2%)
build/block-library/blocks/gallery/editor-rtl.css 783 B +34 B (+5%) 🔍
build/block-library/blocks/gallery/editor.css 783 B +33 B (+4%)
build/block-library/blocks/navigation/style-rtl.css 289 B +15 B (+5%) 🔍
build/block-library/blocks/navigation/style.css 289 B +15 B (+5%) 🔍
build/block-library/blocks/paragraph/style-rtl.css 390 B +39 B (+11%) ⚠️
build/block-library/blocks/paragraph/style.css 391 B +39 B (+11%) ⚠️
build/block-library/blocks/social-links/style-rtl.css 1.48 kB +43 B (+3%)
build/block-library/blocks/social-links/style.css 1.48 kB +43 B (+3%)
build/block-library/blocks/spacer/editor-rtl.css 416 B +26 B (+7%) 🔍
build/block-library/blocks/spacer/editor.css 416 B +26 B (+7%) 🔍
build/block-library/blocks/verse/style-rtl.css 215 B +1 B (0%)
build/block-library/blocks/verse/style.css 215 B +1 B (0%)
build/block-library/editor-rtl.css 8.97 kB +40 B (0%)
build/block-library/editor.css 8.97 kB +41 B (0%)
build/block-library/index.js 142 kB -8.92 kB (-6%)
build/block-library/style-rtl.css 8.57 kB +44 B (+1%)
build/block-library/style.css 8.58 kB +45 B (+1%)
build/block-serialization-default-parser/index.js 1.88 kB +4 B (0%)
build/blocks/index.js 48.1 kB +99 B (0%)
build/components/index.js 173 kB +993 B (+1%)
build/components/style-rtl.css 15.5 kB +3 B (0%)
build/components/style.css 15.5 kB +2 B (0%)
build/compose/index.js 11.3 kB +9 B (0%)
build/core-data/index.js 15.2 kB +46 B (0%)
build/data-controls/index.js 829 B -1 B (0%)
build/data/index.js 8.99 kB +22 B (0%)
build/date/index.js 31.8 kB -1 B (0%)
build/deprecated/index.js 769 B +1 B (0%)
build/edit-navigation/index.js 11.2 kB +20 B (0%)
build/edit-post/index.js 306 kB +103 B (0%)
build/edit-post/style-rtl.css 6.51 kB -133 B (-2%)
build/edit-post/style.css 6.5 kB -131 B (-2%)
build/edit-site/index.js 24.2 kB -270 B (-1%)
build/edit-site/style-rtl.css 4.01 kB -29 B (-1%)
build/edit-site/style.css 4.01 kB -27 B (-1%)
build/edit-widgets/index.js 23.6 kB -2.41 kB (-9%)
build/edit-widgets/style-rtl.css 3.17 kB -54 B (-2%)
build/edit-widgets/style.css 3.17 kB -54 B (-2%)
build/editor/editor-styles-rtl.css 543 B +67 B (+14%) ⚠️
build/editor/editor-styles.css 545 B +67 B (+14%) ⚠️
build/editor/index.js 41.9 kB -840 B (-2%)
build/element/index.js 4.62 kB +1 B (0%)
build/format-library/index.js 6.76 kB +14 B (0%)
build/hooks/index.js 2.27 kB +2 B (0%)
build/i18n/index.js 3.57 kB +1 B (0%)
build/is-shallow-equal/index.js 697 B -1 B (0%)
build/keyboard-shortcuts/index.js 2.54 kB +3 B (0%)
build/keycodes/index.js 1.94 kB -1 B (0%)
build/list-reusable-blocks/index.js 3.15 kB +3 B (0%)
build/media-utils/index.js 5.32 kB +1 B (0%)
build/notices/index.js 1.85 kB -1 B (0%)
build/nux/index.js 3.42 kB -4 B (0%)
build/plugins/index.js 2.54 kB +1 B (0%)
build/redux-routine/index.js 2.84 kB -1 B (0%)
build/reusable-blocks/index.js 2.92 kB +6 B (0%)
build/rich-text/index.js 13.5 kB +30 B (0%)
build/server-side-render/index.js 2.77 kB -4 B (0%)
build/shortcode/index.js 1.7 kB +2 B (0%)
build/token-list/index.js 1.27 kB -1 B (0%)
build/url/index.js 3.02 kB -2 B (0%)
build/viewport/index.js 1.86 kB -3 B (0%)
build/warning/index.js 1.14 kB -1 B (0%)
build/wordcount/index.js 1.22 kB +1 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/block-directory/style-rtl.css 1.01 kB 0 B
build/block-directory/style.css 1.01 kB 0 B
build/block-library/blocks/archives/editor-rtl.css 196 B 0 B
build/block-library/blocks/archives/editor.css 196 B 0 B
build/block-library/blocks/audio/editor-rtl.css 194 B 0 B
build/block-library/blocks/audio/editor.css 194 B 0 B
build/block-library/blocks/audio/style-rtl.css 225 B 0 B
build/block-library/blocks/audio/style.css 225 B 0 B
build/block-library/blocks/block/editor-rtl.css 283 B 0 B
build/block-library/blocks/block/editor.css 283 B 0 B
build/block-library/blocks/button/editor-rtl.css 576 B 0 B
build/block-library/blocks/button/editor.css 577 B 0 B
build/block-library/blocks/button/style-rtl.css 552 B 0 B
build/block-library/blocks/button/style.css 552 B 0 B
build/block-library/blocks/buttons/editor-rtl.css 345 B 0 B
build/block-library/blocks/buttons/editor.css 346 B 0 B
build/block-library/blocks/buttons/style-rtl.css 419 B 0 B
build/block-library/blocks/buttons/style.css 419 B 0 B
build/block-library/blocks/calendar/style-rtl.css 319 B 0 B
build/block-library/blocks/calendar/style.css 319 B 0 B
build/block-library/blocks/categories/editor-rtl.css 210 B 0 B
build/block-library/blocks/categories/editor.css 209 B 0 B
build/block-library/blocks/categories/style-rtl.css 208 B 0 B
build/block-library/blocks/categories/style.css 208 B 0 B
build/block-library/blocks/code/style-rtl.css 216 B 0 B
build/block-library/blocks/code/style.css 216 B 0 B
build/block-library/blocks/columns/editor-rtl.css 300 B 0 B
build/block-library/blocks/columns/editor.css 299 B 0 B
build/block-library/blocks/columns/style-rtl.css 529 B 0 B
build/block-library/blocks/columns/style.css 528 B 0 B
build/block-library/blocks/embed/editor-rtl.css 594 B 0 B
build/block-library/blocks/embed/editor.css 595 B 0 B
build/block-library/blocks/embed/style-rtl.css 489 B 0 B
build/block-library/blocks/embed/style.css 489 B 0 B
build/block-library/blocks/file/editor-rtl.css 314 B 0 B
build/block-library/blocks/file/editor.css 313 B 0 B
build/block-library/blocks/file/style-rtl.css 352 B 0 B
build/block-library/blocks/file/style.css 352 B 0 B
build/block-library/blocks/freeform/editor-rtl.css 2.55 kB 0 B
build/block-library/blocks/freeform/editor.css 2.55 kB 0 B
build/block-library/blocks/gallery/style-rtl.css 1.17 kB 0 B
build/block-library/blocks/gallery/style.css 1.17 kB 0 B
build/block-library/blocks/group/editor-rtl.css 433 B 0 B
build/block-library/blocks/group/editor.css 432 B 0 B
build/block-library/blocks/group/style-rtl.css 190 B 0 B
build/block-library/blocks/group/style.css 190 B 0 B
build/block-library/blocks/heading/editor-rtl.css 248 B 0 B
build/block-library/blocks/heading/editor.css 248 B 0 B
build/block-library/blocks/heading/style-rtl.css 212 B 0 B
build/block-library/blocks/heading/style.css 212 B 0 B
build/block-library/blocks/html/editor-rtl.css 384 B 0 B
build/block-library/blocks/html/editor.css 385 B 0 B
build/block-library/blocks/image/editor-rtl.css 801 B 0 B
build/block-library/blocks/image/editor.css 800 B 0 B
build/block-library/blocks/image/style-rtl.css 569 B 0 B
build/block-library/blocks/image/style.css 570 B 0 B
build/block-library/blocks/latest-comments/editor-rtl.css 277 B 0 B
build/block-library/blocks/latest-comments/editor.css 275 B 0 B
build/block-library/blocks/latest-comments/style-rtl.css 382 B 0 B
build/block-library/blocks/latest-comments/style.css 382 B 0 B
build/block-library/blocks/latest-posts/editor-rtl.css 254 B 0 B
build/block-library/blocks/latest-posts/editor.css 254 B 0 B
build/block-library/blocks/latest-posts/style-rtl.css 634 B 0 B
build/block-library/blocks/latest-posts/style.css 634 B 0 B
build/block-library/blocks/list/editor-rtl.css 203 B 0 B
build/block-library/blocks/list/editor.css 203 B 0 B
build/block-library/blocks/list/style-rtl.css 201 B 0 B
build/block-library/blocks/list/style.css 201 B 0 B
build/block-library/blocks/media-text/editor-rtl.css 311 B 0 B
build/block-library/blocks/media-text/editor.css 311 B 0 B
build/block-library/blocks/media-text/style-rtl.css 642 B 0 B
build/block-library/blocks/media-text/style.css 640 B 0 B
build/block-library/blocks/more/editor-rtl.css 545 B 0 B
build/block-library/blocks/more/editor.css 545 B 0 B
build/block-library/blocks/navigation-link/editor-rtl.css 503 B 0 B
build/block-library/blocks/navigation-link/editor.css 504 B 0 B
build/block-library/blocks/navigation-link/style-rtl.css 805 B 0 B
build/block-library/blocks/navigation-link/style.css 803 B 0 B
build/block-library/blocks/navigation/editor-rtl.css 1.38 kB 0 B
build/block-library/blocks/navigation/editor.css 1.38 kB 0 B
build/block-library/blocks/nextpage/editor-rtl.css 507 B 0 B
build/block-library/blocks/nextpage/editor.css 507 B 0 B
build/block-library/blocks/paragraph/editor-rtl.css 236 B 0 B
build/block-library/blocks/paragraph/editor.css 236 B 0 B
build/block-library/blocks/post-author/editor-rtl.css 329 B 0 B
build/block-library/blocks/post-author/editor.css 329 B 0 B
build/block-library/blocks/post-author/style-rtl.css 303 B 0 B
build/block-library/blocks/post-author/style.css 303 B 0 B
build/block-library/blocks/post-comments-form/style-rtl.css 358 B 0 B
build/block-library/blocks/post-comments-form/style.css 358 B 0 B
build/block-library/blocks/post-content/editor-rtl.css 262 B 0 B
build/block-library/blocks/post-content/editor.css 262 B 0 B
build/block-library/blocks/post-excerpt/editor-rtl.css 206 B 0 B
build/block-library/blocks/post-excerpt/editor.css 206 B 0 B
build/block-library/blocks/post-featured-image/editor-rtl.css 453 B 0 B
build/block-library/blocks/post-featured-image/editor.css 453 B 0 B
build/block-library/blocks/post-featured-image/style-rtl.css 223 B 0 B
build/block-library/blocks/post-featured-image/style.css 223 B 0 B
build/block-library/blocks/preformatted/style-rtl.css 193 B 0 B
build/block-library/blocks/preformatted/style.css 193 B 0 B
build/block-library/blocks/pullquote/editor-rtl.css 304 B 0 B
build/block-library/blocks/pullquote/editor.css 304 B 0 B
build/block-library/blocks/pullquote/style-rtl.css 428 B 0 B
build/block-library/blocks/pullquote/style.css 428 B 0 B
build/block-library/blocks/query-loop/editor-rtl.css 217 B 0 B
build/block-library/blocks/query-loop/editor.css 216 B 0 B
build/block-library/blocks/query-loop/style-rtl.css 427 B 0 B
build/block-library/blocks/query-loop/style.css 429 B 0 B
build/block-library/blocks/query/editor-rtl.css 279 B 0 B
build/block-library/blocks/query/editor.css 279 B 0 B
build/block-library/blocks/quote/editor-rtl.css 195 B 0 B
build/block-library/blocks/quote/editor.css 195 B 0 B
build/block-library/blocks/quote/style-rtl.css 284 B 0 B
build/block-library/blocks/quote/style.css 285 B 0 B
build/block-library/blocks/rss/editor-rtl.css 307 B 0 B
build/block-library/blocks/rss/editor.css 309 B 0 B
build/block-library/blocks/rss/style-rtl.css 394 B 0 B
build/block-library/blocks/rss/style.css 393 B 0 B
build/block-library/blocks/search/editor-rtl.css 285 B 0 B
build/block-library/blocks/search/editor.css 285 B 0 B
build/block-library/blocks/search/style-rtl.css 454 B 0 B
build/block-library/blocks/search/style.css 456 B 0 B
build/block-library/blocks/separator/editor-rtl.css 229 B 0 B
build/block-library/blocks/separator/editor.css 229 B 0 B
build/block-library/blocks/separator/style-rtl.css 352 B 0 B
build/block-library/blocks/separator/style.css 352 B 0 B
build/block-library/blocks/shortcode/editor-rtl.css 603 B 0 B
build/block-library/blocks/shortcode/editor.css 603 B 0 B
build/block-library/blocks/site-logo/editor-rtl.css 321 B 0 B
build/block-library/blocks/site-logo/editor.css 321 B 0 B
build/block-library/blocks/site-logo/style-rtl.css 238 B 0 B
build/block-library/blocks/site-logo/style.css 238 B 0 B
build/block-library/blocks/social-link/editor-rtl.css 283 B 0 B
build/block-library/blocks/social-link/editor.css 283 B 0 B
build/block-library/blocks/social-links/editor-rtl.css 811 B 0 B
build/block-library/blocks/social-links/editor.css 810 B 0 B
build/block-library/blocks/spacer/style-rtl.css 184 B 0 B
build/block-library/blocks/spacer/style.css 184 B 0 B
build/block-library/blocks/subhead/editor-rtl.css 223 B 0 B
build/block-library/blocks/subhead/editor.css 223 B 0 B
build/block-library/blocks/subhead/style-rtl.css 210 B 0 B
build/block-library/blocks/subhead/style.css 210 B 0 B
build/block-library/blocks/table/editor-rtl.css 593 B 0 B
build/block-library/blocks/table/editor.css 593 B 0 B
build/block-library/blocks/table/style-rtl.css 501 B 0 B
build/block-library/blocks/table/style.css 501 B 0 B
build/block-library/blocks/tag-cloud/editor-rtl.css 237 B 0 B
build/block-library/blocks/tag-cloud/editor.css 235 B 0 B
build/block-library/blocks/tag-cloud/style-rtl.css 221 B 0 B
build/block-library/blocks/tag-cloud/style.css 221 B 0 B
build/block-library/blocks/template-part/editor-rtl.css 714 B 0 B
build/block-library/blocks/template-part/editor.css 714 B 0 B
build/block-library/blocks/text-columns/editor-rtl.css 220 B 0 B
build/block-library/blocks/text-columns/editor.css 220 B 0 B
build/block-library/blocks/text-columns/style-rtl.css 283 B 0 B
build/block-library/blocks/text-columns/style.css 283 B 0 B
build/block-library/blocks/verse/editor-rtl.css 194 B 0 B
build/block-library/blocks/verse/editor.css 194 B 0 B
build/block-library/blocks/video/editor-rtl.css 617 B 0 B
build/block-library/blocks/video/editor.css 617 B 0 B
build/block-library/blocks/video/style-rtl.css 303 B 0 B
build/block-library/blocks/video/style.css 304 B 0 B
build/block-library/common-rtl.css 1.01 kB 0 B
build/block-library/common.css 1.01 kB 0 B
build/block-library/theme-rtl.css 860 B 0 B
build/block-library/theme.css 860 B 0 B
build/block-serialization-spec-parser/index.js 3.06 kB 0 B
build/dom-ready/index.js 571 B 0 B
build/dom/index.js 4.95 kB 0 B
build/edit-navigation/style-rtl.css 938 B 0 B
build/edit-navigation/style.css 944 B 0 B
build/editor/style-rtl.css 3.89 kB 0 B
build/editor/style.css 3.89 kB 0 B
build/escape-html/index.js 735 B 0 B
build/format-library/style-rtl.css 620 B 0 B
build/format-library/style.css 621 B 0 B
build/html-entities/index.js 623 B 0 B
build/list-reusable-blocks/style-rtl.css 629 B 0 B
build/list-reusable-blocks/style.css 628 B 0 B
build/nux/style-rtl.css 731 B 0 B
build/nux/style.css 727 B 0 B
build/primitives/index.js 1.43 kB 0 B
build/priority-queue/index.js 790 B 0 B

compressed-size-action

Copy link
Member

@mkaz mkaz left a comment

Choose a reason for hiding this comment

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

This works well for me and I would agree I prefer this implementation over #25372

I didn't have any problems with implementation and usage, I would defer to @jasmussen for any comments on the CSS change, it looks like it just wraps it in a not if specified which worked fine in my testing, so I don't see an issue.

Good work on this, thanks! 👍

@jasmussen
Copy link
Contributor

This is awesome. Theme developers are going to be so happy with this.

Here's what I see:

Jan-13-2021 09-42-39

A couple of issues here:

1. I'm using TwentyTwentyOne Blocks and for whatever reason, setting the global color of the entire Social Icons block doesn't work. These appear to be the conflicting styles:
Screenshot 2021-01-13 at 09 45 53

You note:

some themes have specific styles for named background colors where it will override the selected icon color

We have to solve this. It'd be okay to increase specificity of the user-set colors. Setting the selector to this, solves it for me:

Screenshot 2021-01-13 at 09 47 36

Just add a CSS comment explaining why the extra specificity is added.

2. It's possible to override the color of just a single icon.

My very first instinct here is that this is a step too far. The color interface is identical whether you've selected the Social Icons parent block, or any individual block inside, meaning users will likely either set mixture of both, and be confused when one overrides the other. An additional instinct says that the use case of coloring only a single icon, as opposed to all of them at once, is an exceptionally rare use case that doesn't warrant the UX overhead.

I'm happy to defer to a sanity check by @jffng, @MaggieCabrera, @kjellr or @scruffian, who I believe have been yearning for this feature for a along time. If they prefer both the block itself, and individual social icons, to be colorable, I'll happily defer.

Thank you again for working on this 🏅

@kjellr
Copy link
Contributor

kjellr commented Jan 14, 2021

Thanks for the ping, @jasmussen! And thanks for the PR, @aaronrobertshaw! This is definitely a feature I'm excited to have. 🙌

I fully agree with @jasmussen's assessment, both about adding specificity to the user's color choice, and also the stance that these color options should apply only to all social links.

@aaronrobertshaw
Copy link
Contributor Author

  1. I'm using TwentyTwentyOne Blocks and for whatever reason, setting the global color of the entire Social Icons block doesn't work.

@jasmussen I can't replicate the issue of the global color selection not being passed to the child Social Link blocks and being applied. The CSS styles in the screenshot also appear different than those I see.

Demo CSS
SocialLinks Screen Shot 2021-01-15 at 12 02 05 pm

some themes have specific styles for named background colors where it will override the selected icon color

We have to solve this. It'd be okay to increase specificity of the user-set colors. Setting the selector to this, solves it for me:

I'll try and address this. The catch is the has-<color>-color and has-<color>-background-color styles come from the colors block support so I don't have control over their specificity. Especially if a theme is overwriting those exact same CSS classes as in the case I noted.

In the previous PR I overcame this by actually determining the color value and applying it as an inline style. This lead to a somewhat more hacky approach and a lot of additional changing of code that others weren't a huge fan of.

My very first instinct here is that this is a step too far. The color interface is identical whether you've selected the Social Icons parent block, or any individual block inside, meaning users will likely either set mixture of both, and be confused when one overrides the other. An additional instinct says that the use case of coloring only a single icon, as opposed to all of them at once, is an exceptionally rare use case that doesn't warrant the UX overhead.

That was my preference as well to only set the colors at the Social Links level as a group. Again, this was something that was covered in the original PR.

The approach in this PR uses the colors block support to be able to apply the color CSS classes etc to the individual blocks. The controls added at the "group" or Social Links level are simply used to pass through values to set the individual blocks' color support attributes. I'm not sure if I can disable/hide the color controls at the individual block level but still retain the color block support behaviour. I'll look into it.

There's also a possibility that I can leverage some CSS variables to find some middle ground.

@aaronrobertshaw
Copy link
Contributor Author

I've updated this to use a new approach leveraging CSS variables set on the main Social Links block.

Improvements over the last iteration are:

  • Theme styles for named colors no longer override user color selections
  • No need to opt into the colors block support on inner social link blocks
  • Color selections are made once only on the main social links block, simplifying UI

One downside was needing to store the color hex value for named colors in an attribute so the CSS variable inline style in save.js can still be correctly set.

PR description has been updated to reflect current approach.

@jasmussen and @kjellr would you mind taking another look at this and seeing if it is more to your liking? 🙂

@jasmussen
Copy link
Contributor

Awesome work, still. The removal of the ability to color individual icons greatly simplifies the experience.

However I still can't get the colors to take:

Screenshot 2021-01-15 at 09 56 41

They need relatively high specificity. Which theme are you testing on?

Also, I'm not sure moving to CSS variables for these is a good idea. You might want two social links menus on a single page, with different color sets. For example you may have a light header with a couple icons at the end of your navigation menu, which are dark gray against the white background. Then you might also have social links showing up at the end of every post, with different colors.

Won't the move to CSS variables make the choice of colors for one social icons block affect the colors of every other social icons blocks?

@ntsekouras
Copy link
Contributor

ntsekouras commented Jan 15, 2021

Hey 👋 - Thanks for working on this!

I'm wondering why you didn't try to implement with color supports in block-json in SocialLink block 🤔

I think it would be much simpler and would need just the addition of a bit of css. I haven't checked it yet though, but I will as I am curious :)

--edit I missed the fact that you wanted to change all colors at once :)

@aaronrobertshaw
Copy link
Contributor Author

They need relatively high specificity. Which theme are you testing on?

I tested with TwentyTwentyOne (as per the last gif) using latest master, v1.0, and v1.1, TwentyTwenty, Maywood, and Varia.

Prior to trying to replicate the issue you've seen, I updated all the themes as well. I also tested across browsers and still can't replicate the problem.

Also, I'm not sure moving to CSS variables for these is a good idea. You might want two social links menus on a single page, with different color sets.

Won't the move to CSS variables make the choice of colors for one social icons block affect the colors of every other social icons blocks?

This is actually part of the beauty of the CSS variables approach, that will not be the case. CSS variables can be inherited or scoped to a specific selector not just set globally on :root.

The current implementation I have in this PR sets the CSS variable as an inline style on the block. When the inner elements' CSS attempts to determine the variable's value via var(--wp--social-links--icon-color) for example, they look for the most locally scoped declaration of the CSS variable. In each block's case that would be the inline style for that individual block setting the variable.

Below are a few GIFs with multiple social links blocks using different color selections.

2021 2020 Maywood Seedlet Varia
SocialLinksColors2 SocialLinksColors SocialLinksColors-Maywood SocialLinksColors-Seedlet SocialLinksColors-Varia

If switching themes, their color palettes may not have matching named colors.

In this situation, the previous color selection's named color would not match an option in the color controls so they would effectively clear the selection.

We are already maintaining a custom color value attribute to facilitate setting CSS variables in the save function. Using this instead of the withColors created color means if it does match we keep the selection. If it doesn't it is treated as a custom color.
This partially undoes the prior commit that switched all color selections to use the custom attribute value. Instead, by using them as a fallback only, if the named color is also in the new theme's palette, that themes colors are used.
@jasmussen
Copy link
Contributor

I suspect the specificity issues are related to none of those themes being block based, and potentially not leveraging some of the global styles stuff that's underway. I can confirm it works in non block based themes, but falls apart in block based ones. You can try using the block based themes in https://github.com/WordPress/theme-experiments.

Here's my own:

Screenshot 2021-01-18 at 08 55 18

Here's Twenty Twenty One Blocks:

Screenshot 2021-01-18 at 08 59 17

Here's a video of a little inspecting:

https://cloudup.com/cxeNNecoxC0

As you mentioned, it works in vanilla Twenty Twenty One:

Screenshot 2021-01-18 at 09 07 07

I can even see the right styles taking:

Screenshot 2021-01-18 at 09 06 56

☝️ that CSS appears to not be output at all in block based themes.

@aaronrobertshaw
Copy link
Contributor Author

@jasmussen Thanks for your help and patience on this one.

I can confirm it works in non block based themes, but falls apart in block based ones. You can try using the block based themes in https://github.com/WordPress/theme-experiments.

I've tested with the themes from https://github.com/WordPress/theme-experiments including:

  • Twenty Twenty One Blocks
  • Twenty Twenty Blocks
  • Ambitious
  • Armando
  • Twenty Nineteen Blocks

All of them work fine for me with this PR (Twenty Nineteen Blocks has broken layout that's a separate issue).

The closest this PR now comes to Global Styles is using the withColors hook. That part is working for you or we wouldn't see the color controls. In your video I can see the inline styles setting the CSS variables as well. As you stated, it doesn't appear that you have the latest CSS containing the rules that use those.

The color selections via the CSS variables are applied to the individual Social Links via simple CSS rules added to packages/block-library/src/social-links/style.scss

The CSS classes applied to the group social links block and the individual link blocks match between your video and what I see. Double checking the CSS rule, it should be applied so long as its in your stylesheet.

I've also cloned a fresh copy of Gutenberg, setup a new wp-env install, manually uploaded the block themes, rebuilt Gutenberg and re-tested. Same result, they all work for me.

I'm obviously missing something.

2021 Blocks 2020 Blocks Ambitious Armando
SLC-TT1-blocks2 SLC-2020-blocks SLC-Ambitious SLC-Armando

@jasmussen jasmussen self-requested a review January 19, 2021 08:05
@jasmussen
Copy link
Contributor

My goodness.

I had npm run dev running in the background. Then from the main branch I checked out this one, and set the theme to TwentyTwentyOne, added a social links block and colored it, and it worked.

Then I opened a new tab, switched the theme to TwentyTwentyOne Blocks, opened the same post in the post editor, and saw that the colors did not work.

Then I debugged the two open tabs, without reloading, to figure out that the CSS to colorize each list item was simply missing in the tab that had TwentyTwentyOne Blocks. I even tried clearing cache thoroughly.

In a bit of frustration, I Ctrl+C'ed my npm run dev process and restarted it. And now it works fine in every theme.

I still don't quite understand why the existing background npm run dev compiled the files so that it worked in normal themes but not in block themes, or why restarting it fixed it also for block themes. But nevertheless, it appears to work fine. So I do apologize for the error, and thanks again for the work! Ship this one as fast as you can.

@aaronrobertshaw
Copy link
Contributor Author

In a bit of frustration, I Ctrl+C'ed my npm run dev process and restarted it. And now it works fine in every theme.

On some rare occasions I've seen the my local watch task see the .scss files change but not build correctly when switching branches. I've not thought much of it at the time and have probably developed a bit of a habit of restarting npm run dev if I switch branches.

I still don't quite understand why the existing background npm run dev compiled the files so that it worked in normal themes but not in block themes, or why restarting it fixed it also for block themes. But nevertheless, it appears to work fine.

That one is a bit of a mystery!

So I do apologize for the error, and thanks again for the work! Ship this one as fast as you can.

Not a problem. I'm glad it's working for you now. If nothing else, we've been pretty thorough testing this one across themes 🙂

@aaronrobertshaw aaronrobertshaw merged commit f6129f6 into master Jan 19, 2021
@aaronrobertshaw aaronrobertshaw deleted the add/colors-to-social-links branch January 19, 2021 08:22
@github-actions github-actions bot added this to the Gutenberg 9.9 milestone Jan 19, 2021
@jasmussen
Copy link
Contributor

This one will make a lot of people happy.

As a followup, we should still make the change where we move the color options to the toolbar, as shown in this comment. Aaron if you have energy of course, otherwise CC: @mkaz? Alternatively we can open a new ticket to do just that, so it doesn't fall off the radar.

@aaronrobertshaw
Copy link
Contributor Author

As a followup, we should still make the change where we move the color options to the toolbar, as shown in this comment. Aaron if you have energy of course, otherwise CC: @mkaz? Alternatively we can open a new ticket to do just that, so it doesn't fall off the radar.

How do you see the two different color options working in the block's toolbar?

We have both icon color and icon background color. Do we need to combine those into a single toolbar menu?

@jasmussen
Copy link
Contributor

jasmussen commented Jan 19, 2021

How do you see the two different color options working in the block's toolbar?

Something along these lines:

Screenshot 2021-01-19 at 09 51 45

Some of this is a little dependant on work in #27331 to further.

@aaronrobertshaw
Copy link
Contributor Author

Some of this is a little dependant on work in #27331 to further.

Perhaps opening up a new ticket to move the controls into the block toolbar after #27331 lands is the most efficient course of action? That is, unless others would rather see it done sooner. I don't have a strong opinion either way.

@jasmussen
Copy link
Contributor

I'll open a ticket.

@@ -348,6 +348,7 @@ These are the current color properties supported by blocks:
| Post Title | Yes | Yes | - | Yes |
| Site Tagline | Yes | Yes | - | Yes |
| Site Title | Yes | Yes | - | Yes |
| Social Links | Yes | - | - | Yes |
Copy link
Member

Choose a reason for hiding this comment

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

👋 While this PR added support for icon color & background, it doesn't use the block support mechanism, hence these properties can't be targeted via theme.json. I've prepared a fix for this at #29294

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the fix!

@oandregal
Copy link
Member

👋 I've filed an issue at #29297 that relates to the use of CSS Custom Properties in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Social Affects the Social Block - used to display Social Media accounts [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Color options for Social Icons block
6 participants