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

Table of contents block: add color block supports #43363

Merged
merged 1 commit into from
Aug 19, 2022

Conversation

ramonjd
Copy link
Member

@ramonjd ramonjd commented Aug 18, 2022

Related:

What?

Enabling full color block supports for the Table of contents block

Why?

To create consistency across blocks.

How?

Adding the relevant block supports in block.json

Testing Instructions

  1. Load the block editor with a Table of contents block. Add some content or use the example block code below.
  2. Confirm the colors control panel is there
  3. Add background color or gradient, link text and text colors
  4. Save and confirm the styles appear on the frontend.
  5. Test the new support works for the block via theme.json and global styles. See example JSON below.
Example block code
<!-- wp:table-of-contents {"headings":[{"content":"Did you hear about the two thieves who stole a calendar?","level":2,"link":"http://localhost:8888/?p=27#did-you-hear-about-the-two-thieves-who-stole-a-calendar"},{"content":"They each got six months.","level":3,"link":"http://localhost:8888/?p=27#they-each-got-six-months"},{"content":"Ever wondered why bees hum?","level":2,"link":"http://localhost:8888/?p=27#ever-wondered-why-bees-hum"},{"content":"It's because they don't know the words.","level":3,"link":"http://localhost:8888/?p=27#it-s-because-they-don-t-know-the-words"},{"content":"What did the big flower say to the littler flower?","level":2,"link":"http://localhost:8888/?p=27#what-did-the-big-flower-say-to-the-littler-flower"},{"content":"Hi, bud!","level":3,"link":"http://localhost:8888/?p=27#hi-bud"},{"content":"Where do bees go to the bathroom?","level":2,"link":"http://localhost:8888/?p=27#where-do-bees-go-to-the-bathroom"},{"content":"The BP station.","level":3,"link":"http://localhost:8888/?p=27#the-bp-station"}],"style":{"elements":{"link":{"color":{"text":"var:preset|color|pale-cyan-blue"}}}},"backgroundColor":"vivid-purple","textColor":"luminous-vivid-orange"} -->
<nav class="wp-block-table-of-contents has-luminous-vivid-orange-color has-vivid-purple-background-color has-text-color has-background has-link-color"><ol><li><a class="wp-block-table-of-contents__entry" href="http://localhost:8888/?p=27#did-you-hear-about-the-two-thieves-who-stole-a-calendar">Did you hear about the two thieves who stole a calendar?</a><ol><li><a class="wp-block-table-of-contents__entry" href="http://localhost:8888/?p=27#they-each-got-six-months">They each got six months.</a></li></ol></li><li><a class="wp-block-table-of-contents__entry" href="http://localhost:8888/?p=27#ever-wondered-why-bees-hum">Ever wondered why bees hum?</a><ol><li><a class="wp-block-table-of-contents__entry" href="http://localhost:8888/?p=27#it-s-because-they-don-t-know-the-words">It's because they don't know the words.</a></li></ol></li><li><a class="wp-block-table-of-contents__entry" href="http://localhost:8888/?p=27#what-did-the-big-flower-say-to-the-littler-flower">What did the big flower say to the littler flower?</a><ol><li><a class="wp-block-table-of-contents__entry" href="http://localhost:8888/?p=27#hi-bud">Hi, bud!</a></li></ol></li><li><a class="wp-block-table-of-contents__entry" href="http://localhost:8888/?p=27#where-do-bees-go-to-the-bathroom">Where do bees go to the bathroom?</a><ol><li><a class="wp-block-table-of-contents__entry" href="http://localhost:8888/?p=27#the-bp-station">The BP station.</a></li></ol></li></ol></nav>
<!-- /wp:table-of-contents -->

<!-- wp:heading -->
<h2 id="did-you-hear-about-the-two-thieves-who-stole-a-calendar">Did you hear about the two thieves who stole a calendar?</h2>
<!-- /wp:heading -->

<!-- wp:heading {"level":3} -->
<h3 id="they-each-got-six-months">They each got six months.</h3>
<!-- /wp:heading -->

<!-- wp:heading -->
<h2 id="ever-wondered-why-bees-hum">Ever wondered why bees hum?</h2>
<!-- /wp:heading -->

<!-- wp:heading {"level":3} -->
<h3 id="it-s-because-they-don-t-know-the-words">It's because they don't know the words.</h3>
<!-- /wp:heading -->

<!-- wp:heading -->
<h2 id="what-did-the-big-flower-say-to-the-littler-flower">What did the big flower say to the littler flower?</h2>
<!-- /wp:heading -->

<!-- wp:heading {"level":3} -->
<h3 id="hi-bud">Hi, bud!</h3>
<!-- /wp:heading -->

<!-- wp:heading -->
<h2 id="where-do-bees-go-to-the-bathroom">Where do bees go to the bathroom?</h2>
<!-- /wp:heading -->

<!-- wp:heading {"level":3} -->
<h3 id="the-bp-station">The BP station.<a href="https://icanhazdadjoke.com/j/AI6hiGtzAd"></a><a href="https://icanhazdadjoke.com/j/IJYvcFIBAlb"></a><a href="https://icanhazdadjoke.com/j/ZDAIRn39prc"></a><a href="https://icanhazdadjoke.com/j/FYobM71o4ob"></a></h3>
<!-- /wp:heading -->
	"styles": {
		"blocks": {
			"core/table-of-contents": {
				"color": {
					"background": "green"
				}
			}
		}
	}

Screen Shot 2022-08-18 at 7 15 00 pm

@ramonjd ramonjd added [Type] Enhancement A suggestion for improvement. [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Block] Table of contents (experimental) Affects the Table of contents Block labels Aug 18, 2022
@ramonjd ramonjd self-assigned this Aug 18, 2022
@ramonjd
Copy link
Member Author

ramonjd commented Aug 19, 2022

Fixing the failing e2e test in this commit: 3ba738875c953c3381d5022ccd809ab9e537e5e2

@ramonjd ramonjd force-pushed the add/table-of-content-color-block-supports branch from f5aa5c2 to 67660ef Compare August 19, 2022 03:55
@glendaviesnz
Copy link
Contributor

glendaviesnz commented Aug 19, 2022

This works for me, except setting the link color in theme.json:
Screen Shot 2022-08-19 at 4 13 37 PM

the linter complains that link is not allowed, but I see it used elsewhere in the blockbase theme.json

@ramonjd
Copy link
Member Author

ramonjd commented Aug 19, 2022

This works for me, except setting the link color in theme.json:

Interesting, looks like the schema doesn't support it. Perhaps it's intentional?

https://github.com/WordPress/gutenberg/blob/a9ae1b70be556b4f31974932eb91e05e7059d162/schemas/json/theme.json#L956-L955

@glendaviesnz
Copy link
Contributor

Interesting, looks like the schema doesn't support it. Perhaps it's intentional?

ok, I guess that is another can we can kick down the road, it works in the UI so lets run with it

Copy link
Contributor

@glendaviesnz glendaviesnz left a comment

Choose a reason for hiding this comment

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

Works in the UI, but setting link doesn't currently work in theme.json so that may need to be followed up at some point if that is an expectation.

@ramonjd
Copy link
Member Author

ramonjd commented Aug 19, 2022

Looks like the theme json class doesn't even look for it. There's no path in

const PROPERTIES_METADATA = array(

My assumption is that is needs to be handled as an "element", similar to the way we're doing it for block supports in elements.php but on the global styles level.

It doesn't work for any text block that I'm testing (para, heading)...

@ramonjd
Copy link
Member Author

ramonjd commented Aug 19, 2022

ok, I guess that is another can we can kick down the road, it works in the UI so lets run with it

I've added it as a follow up in #43245

@ramonjd ramonjd merged commit 18c8c77 into trunk Aug 19, 2022
@ramonjd ramonjd deleted the add/table-of-content-color-block-supports branch August 19, 2022 04:47
@github-actions github-actions bot added this to the Gutenberg 14.0 milestone Aug 19, 2022
@ZebulanStanphill
Copy link
Member

Thanks for these PRs. 👍

@ZebulanStanphill
Copy link
Member

I just remembered that most (if not all) text blocks with background color controls have additional styles to add padding when a background color is present... including the List block.

I guess the same thing should happen here, though I imagine the exact styles couldn't just be copied over from the List block since in this case, the padding would be applied to the wrapping <nav> rather than the contained <ol>.

In the List block, this auto-padding would override any padding already set on the <ol>, but in the Table of Contents block, the <ol> padding would be kept, and the <nav> padding would add to the overall spacing.

I actually considered making a PR to add color controls to the Table of Contents some months ago, but I got stuck trying to figure out what to do here.

@ramonjd
Copy link
Member Author

ramonjd commented Aug 22, 2022

Thanks for raising this!

I just remembered that most (if not all) text blocks with background color controls have additional styles to add padding when a background color is present

What if we didn't adding padding here? Using padding values one can achieve the same effect and have greater control:

Screen Shot 2022-08-22 at 10 22 06 am

There's a related discussion about the extra padding given to blocks with background color (and whether it's a good thing at all)

There is the question of classic themes. The above issue considers the use of classic-only stylesheet.

@femkreations femkreations added the Needs User Documentation Needs new user documentation label Sep 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Table of contents (experimental) Affects the Table of contents Block [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi Needs User Documentation Needs new user documentation [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants