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

Global Styles: Add Style Book to Global Styles #45960

Merged
merged 20 commits into from
Dec 5, 2022
Merged

Conversation

noisysocks
Copy link
Member

@noisysocks noisysocks commented Nov 22, 2022

What?

Resolves #44420.

Adds a new Style Book feature to Global Styles in the Site Editor. This displays a preview of all block types in a resizable editor frame.

Why?

From #44420:

It's not uncommon to find yourself styling a block in Global Styles without that block being present on the canvas. Consequently you're left unsure as to whether the desired outcome is achieved.

One solution to this could be providing a dedicated document containing all blocks, that users can observe on demand.

How?

A new component called StyleBook is added to @wordpress/edit-site. This uses the existing BlockPreview component to display a preview of every registered block in an iframe per block.

Each iframe has the site styles loaded into it, allowing you to preview them. The background colour of StyleBook is matched with the theme using useStyle( 'color.background' ). This all works because StyleBook is a descendent of BlockEditorSettings and GlobalStylesProvider.

Clicking on a block preview opens that block in Global Styles. This is done by having StyleBook be a Fill rendered by GlobalStylesUI. That lets us have access to the Global Styles navigation state using useNavigator. The style book is then mounted into the correct part of the editor DOM using StyleBook.Slot.

Testing Instructions

  1. Go to Appearance → Editor.
  2. Open the (Global) Styles panel.
  3. Click on the new Open Style Book button. (Illuminati eye icon.)
  4. Have fun.

Screenshots or screencast

Kapture.2022-11-30.at.17.43.06.mp4

@codesandbox
Copy link

codesandbox bot commented Nov 22, 2022

CodeSandbox logoCodeSandbox logo  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@github-actions
Copy link

github-actions bot commented Nov 22, 2022

Size Change: +2.05 kB (0%)

Total Size: 1.33 MB

Filename Size Change
build/block-editor/index.min.js 181 kB +26 B (0%)
build/edit-site/index.min.js 62.6 kB +1.62 kB (+3%)
build/edit-site/style-rtl.css 8.75 kB +202 B (+2%)
build/edit-site/style.css 8.75 kB +197 B (+2%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 993 B
build/annotations/index.min.js 2.78 kB
build/api-fetch/index.min.js 2.27 kB
build/autop/index.min.js 2.15 kB
build/blob/index.min.js 487 B
build/block-directory/index.min.js 7.16 kB
build/block-directory/style-rtl.css 1.03 kB
build/block-directory/style.css 1.04 kB
build/block-editor/content-rtl.css 2.71 kB
build/block-editor/content.css 2.71 kB
build/block-editor/default-editor-styles-rtl.css 401 B
build/block-editor/default-editor-styles.css 401 B
build/block-editor/style-rtl.css 14.5 kB
build/block-editor/style.css 14.5 kB
build/block-library/blocks/archives/editor-rtl.css 107 B
build/block-library/blocks/archives/editor.css 106 B
build/block-library/blocks/archives/style-rtl.css 129 B
build/block-library/blocks/archives/style.css 129 B
build/block-library/blocks/audio/editor-rtl.css 185 B
build/block-library/blocks/audio/editor.css 185 B
build/block-library/blocks/audio/style-rtl.css 158 B
build/block-library/blocks/audio/style.css 158 B
build/block-library/blocks/audio/theme-rtl.css 172 B
build/block-library/blocks/audio/theme.css 172 B
build/block-library/blocks/avatar/editor-rtl.css 154 B
build/block-library/blocks/avatar/editor.css 154 B
build/block-library/blocks/avatar/style-rtl.css 126 B
build/block-library/blocks/avatar/style.css 126 B
build/block-library/blocks/block/editor-rtl.css 338 B
build/block-library/blocks/block/editor.css 338 B
build/block-library/blocks/button/editor-rtl.css 517 B
build/block-library/blocks/button/editor.css 517 B
build/block-library/blocks/button/style-rtl.css 566 B
build/block-library/blocks/button/style.css 566 B
build/block-library/blocks/buttons/editor-rtl.css 373 B
build/block-library/blocks/buttons/editor.css 373 B
build/block-library/blocks/buttons/style-rtl.css 368 B
build/block-library/blocks/buttons/style.css 368 B
build/block-library/blocks/calendar/style-rtl.css 270 B
build/block-library/blocks/calendar/style.css 270 B
build/block-library/blocks/categories/editor-rtl.css 125 B
build/block-library/blocks/categories/editor.css 124 B
build/block-library/blocks/categories/style-rtl.css 138 B
build/block-library/blocks/categories/style.css 138 B
build/block-library/blocks/code/editor-rtl.css 102 B
build/block-library/blocks/code/editor.css 102 B
build/block-library/blocks/code/style-rtl.css 159 B
build/block-library/blocks/code/style.css 159 B
build/block-library/blocks/code/theme-rtl.css 160 B
build/block-library/blocks/code/theme.css 160 B
build/block-library/blocks/columns/editor-rtl.css 147 B
build/block-library/blocks/columns/editor.css 147 B
build/block-library/blocks/columns/style-rtl.css 442 B
build/block-library/blocks/columns/style.css 442 B
build/block-library/blocks/comment-author-avatar/editor-rtl.css 163 B
build/block-library/blocks/comment-author-avatar/editor.css 163 B
build/block-library/blocks/comment-content/style-rtl.css 134 B
build/block-library/blocks/comment-content/style.css 134 B
build/block-library/blocks/comment-template/style-rtl.css 237 B
build/block-library/blocks/comment-template/style.css 236 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 159 B
build/block-library/blocks/comments-pagination-numbers/editor.css 157 B
build/block-library/blocks/comments-pagination/editor-rtl.css 258 B
build/block-library/blocks/comments-pagination/editor.css 249 B
build/block-library/blocks/comments-pagination/style-rtl.css 272 B
build/block-library/blocks/comments-pagination/style.css 268 B
build/block-library/blocks/comments-title/editor-rtl.css 118 B
build/block-library/blocks/comments-title/editor.css 118 B
build/block-library/blocks/comments/editor-rtl.css 875 B
build/block-library/blocks/comments/editor.css 874 B
build/block-library/blocks/comments/style-rtl.css 672 B
build/block-library/blocks/comments/style.css 671 B
build/block-library/blocks/cover/editor-rtl.css 646 B
build/block-library/blocks/cover/editor.css 647 B
build/block-library/blocks/cover/style-rtl.css 1.61 kB
build/block-library/blocks/cover/style.css 1.6 kB
build/block-library/blocks/embed/editor-rtl.css 327 B
build/block-library/blocks/embed/editor.css 327 B
build/block-library/blocks/embed/style-rtl.css 446 B
build/block-library/blocks/embed/style.css 446 B
build/block-library/blocks/embed/theme-rtl.css 172 B
build/block-library/blocks/embed/theme.css 172 B
build/block-library/blocks/file/editor-rtl.css 335 B
build/block-library/blocks/file/editor.css 335 B
build/block-library/blocks/file/style-rtl.css 288 B
build/block-library/blocks/file/style.css 288 B
build/block-library/blocks/file/view.min.js 353 B
build/block-library/blocks/freeform/editor-rtl.css 2.47 kB
build/block-library/blocks/freeform/editor.css 2.47 kB
build/block-library/blocks/gallery/editor-rtl.css 1.01 kB
build/block-library/blocks/gallery/editor.css 1.02 kB
build/block-library/blocks/gallery/style-rtl.css 1.58 kB
build/block-library/blocks/gallery/style.css 1.58 kB
build/block-library/blocks/gallery/theme-rtl.css 157 B
build/block-library/blocks/gallery/theme.css 157 B
build/block-library/blocks/group/editor-rtl.css 687 B
build/block-library/blocks/group/editor.css 687 B
build/block-library/blocks/group/style-rtl.css 105 B
build/block-library/blocks/group/style.css 105 B
build/block-library/blocks/group/theme-rtl.css 125 B
build/block-library/blocks/group/theme.css 125 B
build/block-library/blocks/heading/style-rtl.css 128 B
build/block-library/blocks/heading/style.css 128 B
build/block-library/blocks/html/editor-rtl.css 365 B
build/block-library/blocks/html/editor.css 366 B
build/block-library/blocks/image/editor-rtl.css 861 B
build/block-library/blocks/image/editor.css 859 B
build/block-library/blocks/image/style-rtl.css 662 B
build/block-library/blocks/image/style.css 666 B
build/block-library/blocks/image/theme-rtl.css 172 B
build/block-library/blocks/image/theme.css 172 B
build/block-library/blocks/latest-comments/style-rtl.css 333 B
build/block-library/blocks/latest-comments/style.css 333 B
build/block-library/blocks/latest-posts/editor-rtl.css 250 B
build/block-library/blocks/latest-posts/editor.css 249 B
build/block-library/blocks/latest-posts/style-rtl.css 514 B
build/block-library/blocks/latest-posts/style.css 514 B
build/block-library/blocks/list/style-rtl.css 135 B
build/block-library/blocks/list/style.css 135 B
build/block-library/blocks/media-text/editor-rtl.css 300 B
build/block-library/blocks/media-text/editor.css 298 B
build/block-library/blocks/media-text/style-rtl.css 540 B
build/block-library/blocks/media-text/style.css 539 B
build/block-library/blocks/more/editor-rtl.css 465 B
build/block-library/blocks/more/editor.css 465 B
build/block-library/blocks/navigation-link/editor-rtl.css 746 B
build/block-library/blocks/navigation-link/editor.css 744 B
build/block-library/blocks/navigation-link/style-rtl.css 153 B
build/block-library/blocks/navigation-link/style.css 153 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 333 B
build/block-library/blocks/navigation-submenu/editor.css 333 B
build/block-library/blocks/navigation/editor-rtl.css 2.19 kB
build/block-library/blocks/navigation/editor.css 2.19 kB
build/block-library/blocks/navigation/style-rtl.css 2.26 kB
build/block-library/blocks/navigation/style.css 2.25 kB
build/block-library/blocks/navigation/view-modal.min.js 2.81 kB
build/block-library/blocks/navigation/view.min.js 447 B
build/block-library/blocks/nextpage/editor-rtl.css 428 B
build/block-library/blocks/nextpage/editor.css 428 B
build/block-library/blocks/page-list/editor-rtl.css 397 B
build/block-library/blocks/page-list/editor.css 398 B
build/block-library/blocks/page-list/style-rtl.css 212 B
build/block-library/blocks/page-list/style.css 212 B
build/block-library/blocks/paragraph/editor-rtl.css 214 B
build/block-library/blocks/paragraph/editor.css 214 B
build/block-library/blocks/paragraph/style-rtl.css 321 B
build/block-library/blocks/paragraph/style.css 321 B
build/block-library/blocks/post-author/style-rtl.css 212 B
build/block-library/blocks/post-author/style.css 212 B
build/block-library/blocks/post-comments-form/editor-rtl.css 137 B
build/block-library/blocks/post-comments-form/editor.css 137 B
build/block-library/blocks/post-comments-form/style-rtl.css 536 B
build/block-library/blocks/post-comments-form/style.css 537 B
build/block-library/blocks/post-date/style-rtl.css 107 B
build/block-library/blocks/post-date/style.css 107 B
build/block-library/blocks/post-excerpt/editor-rtl.css 119 B
build/block-library/blocks/post-excerpt/editor.css 119 B
build/block-library/blocks/post-excerpt/style-rtl.css 116 B
build/block-library/blocks/post-excerpt/style.css 116 B
build/block-library/blocks/post-featured-image/editor-rtl.css 620 B
build/block-library/blocks/post-featured-image/editor.css 618 B
build/block-library/blocks/post-featured-image/style-rtl.css 349 B
build/block-library/blocks/post-featured-image/style.css 349 B
build/block-library/blocks/post-navigation-link/style-rtl.css 190 B
build/block-library/blocks/post-navigation-link/style.css 189 B
build/block-library/blocks/post-template/editor-rtl.css 140 B
build/block-library/blocks/post-template/editor.css 139 B
build/block-library/blocks/post-template/style-rtl.css 317 B
build/block-library/blocks/post-template/style.css 317 B
build/block-library/blocks/post-terms/style-rtl.css 136 B
build/block-library/blocks/post-terms/style.css 136 B
build/block-library/blocks/post-title/style-rtl.css 138 B
build/block-library/blocks/post-title/style.css 138 B
build/block-library/blocks/preformatted/style-rtl.css 139 B
build/block-library/blocks/preformatted/style.css 139 B
build/block-library/blocks/pullquote/editor-rtl.css 170 B
build/block-library/blocks/pullquote/editor.css 170 B
build/block-library/blocks/pullquote/style-rtl.css 357 B
build/block-library/blocks/pullquote/style.css 357 B
build/block-library/blocks/pullquote/theme-rtl.css 201 B
build/block-library/blocks/pullquote/theme.css 201 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 158 B
build/block-library/blocks/query-pagination-numbers/editor.css 156 B
build/block-library/blocks/query-pagination/editor-rtl.css 258 B
build/block-library/blocks/query-pagination/editor.css 247 B
build/block-library/blocks/query-pagination/style-rtl.css 326 B
build/block-library/blocks/query-pagination/style.css 322 B
build/block-library/blocks/query-title/style-rtl.css 108 B
build/block-library/blocks/query-title/style.css 108 B
build/block-library/blocks/query/editor-rtl.css 475 B
build/block-library/blocks/query/editor.css 477 B
build/block-library/blocks/quote/style-rtl.css 253 B
build/block-library/blocks/quote/style.css 253 B
build/block-library/blocks/quote/theme-rtl.css 255 B
build/block-library/blocks/quote/theme.css 259 B
build/block-library/blocks/read-more/style-rtl.css 168 B
build/block-library/blocks/read-more/style.css 168 B
build/block-library/blocks/rss/editor-rtl.css 239 B
build/block-library/blocks/rss/editor.css 240 B
build/block-library/blocks/rss/style-rtl.css 323 B
build/block-library/blocks/rss/style.css 323 B
build/block-library/blocks/search/editor-rtl.css 205 B
build/block-library/blocks/search/editor.css 205 B
build/block-library/blocks/search/style-rtl.css 441 B
build/block-library/blocks/search/style.css 439 B
build/block-library/blocks/search/theme-rtl.css 149 B
build/block-library/blocks/search/theme.css 149 B
build/block-library/blocks/separator/editor-rtl.css 184 B
build/block-library/blocks/separator/editor.css 184 B
build/block-library/blocks/separator/style-rtl.css 269 B
build/block-library/blocks/separator/style.css 269 B
build/block-library/blocks/separator/theme-rtl.css 229 B
build/block-library/blocks/separator/theme.css 229 B
build/block-library/blocks/shortcode/editor-rtl.css 508 B
build/block-library/blocks/shortcode/editor.css 508 B
build/block-library/blocks/site-logo/editor-rtl.css 522 B
build/block-library/blocks/site-logo/editor.css 522 B
build/block-library/blocks/site-logo/style-rtl.css 238 B
build/block-library/blocks/site-logo/style.css 238 B
build/block-library/blocks/site-tagline/editor-rtl.css 129 B
build/block-library/blocks/site-tagline/editor.css 129 B
build/block-library/blocks/site-title/editor-rtl.css 155 B
build/block-library/blocks/site-title/editor.css 155 B
build/block-library/blocks/site-title/style-rtl.css 101 B
build/block-library/blocks/site-title/style.css 101 B
build/block-library/blocks/social-link/editor-rtl.css 219 B
build/block-library/blocks/social-link/editor.css 219 B
build/block-library/blocks/social-links/editor-rtl.css 709 B
build/block-library/blocks/social-links/editor.css 708 B
build/block-library/blocks/social-links/style-rtl.css 1.43 kB
build/block-library/blocks/social-links/style.css 1.43 kB
build/block-library/blocks/spacer/editor-rtl.css 372 B
build/block-library/blocks/spacer/editor.css 372 B
build/block-library/blocks/spacer/style-rtl.css 96 B
build/block-library/blocks/spacer/style.css 96 B
build/block-library/blocks/table/editor-rtl.css 491 B
build/block-library/blocks/table/editor.css 491 B
build/block-library/blocks/table/style-rtl.css 670 B
build/block-library/blocks/table/style.css 669 B
build/block-library/blocks/table/theme-rtl.css 220 B
build/block-library/blocks/table/theme.css 220 B
build/block-library/blocks/tag-cloud/style-rtl.css 287 B
build/block-library/blocks/tag-cloud/style.css 288 B
build/block-library/blocks/template-part/editor-rtl.css 436 B
build/block-library/blocks/template-part/editor.css 436 B
build/block-library/blocks/template-part/theme-rtl.css 139 B
build/block-library/blocks/template-part/theme.css 139 B
build/block-library/blocks/text-columns/editor-rtl.css 135 B
build/block-library/blocks/text-columns/editor.css 135 B
build/block-library/blocks/text-columns/style-rtl.css 198 B
build/block-library/blocks/text-columns/style.css 198 B
build/block-library/blocks/verse/style-rtl.css 130 B
build/block-library/blocks/verse/style.css 130 B
build/block-library/blocks/video/editor-rtl.css 720 B
build/block-library/blocks/video/editor.css 723 B
build/block-library/blocks/video/style-rtl.css 218 B
build/block-library/blocks/video/style.css 218 B
build/block-library/blocks/video/theme-rtl.css 171 B
build/block-library/blocks/video/theme.css 171 B
build/block-library/classic-rtl.css 193 B
build/block-library/classic.css 193 B
build/block-library/common-rtl.css 1.05 kB
build/block-library/common.css 1.05 kB
build/block-library/editor-elements-rtl.css 126 B
build/block-library/editor-elements.css 126 B
build/block-library/editor-rtl.css 11.7 kB
build/block-library/editor.css 11.7 kB
build/block-library/elements-rtl.css 105 B
build/block-library/elements.css 105 B
build/block-library/index.min.js 196 kB
build/block-library/reset-rtl.css 514 B
build/block-library/reset.css 514 B
build/block-library/style-rtl.css 12.4 kB
build/block-library/style.css 12.4 kB
build/block-library/theme-rtl.css 749 B
build/block-library/theme.css 753 B
build/block-serialization-default-parser/index.min.js 1.13 kB
build/block-serialization-spec-parser/index.min.js 2.83 kB
build/blocks/index.min.js 50.4 kB
build/components/index.min.js 203 kB
build/components/style-rtl.css 11.7 kB
build/components/style.css 11.7 kB
build/compose/index.min.js 12.3 kB
build/core-data/index.min.js 15.9 kB
build/customize-widgets/index.min.js 11.6 kB
build/customize-widgets/style-rtl.css 1.41 kB
build/customize-widgets/style.css 1.41 kB
build/data-controls/index.min.js 663 B
build/data/index.min.js 8.12 kB
build/date/index.min.js 32.1 kB
build/deprecated/index.min.js 518 B
build/dom-ready/index.min.js 336 B
build/dom/index.min.js 4.74 kB
build/edit-navigation/index.min.js 16.2 kB
build/edit-navigation/style-rtl.css 4.12 kB
build/edit-navigation/style.css 4.13 kB
build/edit-post/classic-rtl.css 569 B
build/edit-post/classic.css 570 B
build/edit-post/index.min.js 34.5 kB
build/edit-post/style-rtl.css 7.45 kB
build/edit-post/style.css 7.44 kB
build/edit-widgets/index.min.js 16.7 kB
build/edit-widgets/style-rtl.css 4.48 kB
build/edit-widgets/style.css 4.48 kB
build/editor/index.min.js 44 kB
build/editor/style-rtl.css 3.69 kB
build/editor/style.css 3.68 kB
build/element/index.min.js 4.72 kB
build/escape-html/index.min.js 548 B
build/experiments/index.min.js 882 B
build/format-library/index.min.js 6.96 kB
build/format-library/style-rtl.css 596 B
build/format-library/style.css 596 B
build/hooks/index.min.js 1.66 kB
build/html-entities/index.min.js 454 B
build/i18n/index.min.js 3.79 kB
build/is-shallow-equal/index.min.js 535 B
build/keyboard-shortcuts/index.min.js 1.79 kB
build/keycodes/index.min.js 1.86 kB
build/list-reusable-blocks/index.min.js 2.13 kB
build/list-reusable-blocks/style-rtl.css 858 B
build/list-reusable-blocks/style.css 857 B
build/media-utils/index.min.js 2.94 kB
build/notices/index.min.js 977 B
build/nux/index.min.js 2.07 kB
build/nux/style-rtl.css 772 B
build/nux/style.css 768 B
build/plugins/index.min.js 1.95 kB
build/preferences-persistence/index.min.js 2.23 kB
build/preferences/index.min.js 1.35 kB
build/primitives/index.min.js 960 B
build/priority-queue/index.min.js 1.59 kB
build/react-i18n/index.min.js 702 B
build/react-refresh-entry/index.min.js 8.44 kB
build/react-refresh-runtime/index.min.js 7.31 kB
build/redux-routine/index.min.js 2.75 kB
build/reusable-blocks/index.min.js 2.26 kB
build/reusable-blocks/style-rtl.css 281 B
build/reusable-blocks/style.css 281 B
build/rich-text/index.min.js 10.7 kB
build/server-side-render/index.min.js 2.19 kB
build/shortcode/index.min.js 1.52 kB
build/style-engine/index.min.js 1.51 kB
build/token-list/index.min.js 650 B
build/url/index.min.js 3.7 kB
build/vendors/inert-polyfill.min.js 2.48 kB
build/vendors/react-dom.min.js 41.8 kB
build/vendors/react.min.js 4.02 kB
build/viewport/index.min.js 1.09 kB
build/warning/index.min.js 280 B
build/widgets/index.min.js 7.23 kB
build/widgets/style-rtl.css 1.21 kB
build/widgets/style.css 1.21 kB
build/wordcount/index.min.js 1.06 kB

compressed-size-action

@ockham ockham added Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Feature New feature to highlight in changelogs. labels Nov 24, 2022
@noisysocks
Copy link
Member Author

This is taking shape now! I updated the video in the description and listed my remaining todos which I'll work on next week.

@noisysocks noisysocks changed the title WIP: Add Story Book to Global Styles WIP: Add Style Book to Global Styles Nov 25, 2022
@javierarce
Copy link
Contributor

I'm having some problems testing this PR due to some storybook errors (here's my log after running npm run dev)

@javierarce
Copy link
Contributor

One thing I noticed in the video is the placement of the ellipsis menu and the eye icon: we should show the eye first and then the ellipsis.

@noisysocks
Copy link
Member Author

noisysocks commented Nov 27, 2022

Oops sorry @javierarce I'll fix that up.

@noisysocks noisysocks changed the base branch from trunk to update/split-navigator-container-from-provider November 28, 2022 05:32
@noisysocks
Copy link
Member Author

I stacked this onto #46099. @javierarce you should be able to build the branch with no compile errors now.

@javierarce
Copy link
Contributor

javierarce commented Nov 28, 2022

Thanks!

Ok, this looks great, but I found some things:

  • I think we should change the pointer style to the hand when hovering a block
  • If you click several blocks in the canvas and then use the Global Styles sidebar back button to reach the top level (or the list of blocks), you'll be presented with every single block settings panel you clicked before. I think we shouldn't stack those clicks.
  • We should highlight the block on the canvas if you select it in the sidebar.
  • The content within each section should align vertically with the label:

Screenshot 2022-11-28 at 11 49 18

@jasmussen
Copy link
Contributor

Thanks all for working on this, and thanks for the videos and screenshots shared. Excellent!

I'm a bit late to join the conversation, so a few quick ones I've seen discussed in #44420, just to chime in on:

  • I think it's good to start with the eye. Even if it isn't entirely clear, that fact itself helps balance the prominence of the feature and lets us get this out there as a first version. As Jay alludes to, the site editor could get an I/A restructuring in the future, at which point we can revisit where and how the style book looks.
  • I would echo that we should consider using the dark gray background of focus mode, rather than the light gray background used here. This is mainly to avoid introducing new design elements. A different way of saying it is, if we should use a light background here, we should also use it for "focus mode", and "zoom out" modes. Conceptually, these are all related as they shift the main contents around.
  • One thing I liked about Global styles: Offer a way to view a document containing all blocks and styles #44420 was that it didn't include a "back" button. The main challenge with the back button is that it implies history/browser navigation, where as this is more of a "mode" that you can enter. In that light, the modal-esque close button made more sense.

This is a riff on that and this PR, very quick and dirty:

Screenshot 2022-11-28 at 15 52 46

I included in that a "welcome screen", which is mainly a way of saying: we could make that card itself be sort of interactive. Not only does it contain the tabs and the close button, but it contains info on how to use it. Not a strong opinion, and not a blocker for this PR — the main take-aways are the dark background.

Thank you Javi and Robert!

@annezazu annezazu mentioned this pull request Nov 28, 2022
57 tasks
@noisysocks
Copy link
Member Author

Awesome, thanks for giving it a spin and for the feedback! I'll get this ready to land as a first version. Hopefully in time for SotW.

@noisysocks noisysocks changed the base branch from update/split-navigator-container-from-provider to trunk November 29, 2022 07:03
@javierarce
Copy link
Contributor

I've updated the Figma file with @jasmussen's iteration, including a proposal for how to show the block types when the canvas is resized.

image

@noisysocks noisysocks marked this pull request as ready for review November 30, 2022 06:54
@noisysocks
Copy link
Member Author

noisysocks commented Nov 30, 2022

Ready for review! I updated the PR description and included a re-recorded video.

  • If you click several blocks in the canvas and then use the Global Styles sidebar back button to reach the top level (or the list of blocks), you'll be presented with every single block settings panel you clicked before. I think we shouldn't stack those clicks.

Totally agree with this. It should be doable but requires a few tricky changes to how Navigator works in @wordpress/components. Let's tackle it in a follow-up PR.

  • The content within each section should align vertically with the label:

It's difficult to align the labels perfectly because blocks can have different margins, line heights, etc. I implemented an approach which unsets the top and bottom margin of the block. I think this works well enough.

I included in that a "welcome screen", which is mainly a way of saying: we could make that card itself be sort of interactive. Not only does it contain the tabs and the close button, but it contains info on how to use it. Not a strong opinion, and not a blocker for this PR — the main take-aways are the dark background.

I didn't implement this as I have a few concerns 😀

It's strange to me that it has Gutenberg branding. This feature will ultimately ship in WordPress as a part of the Site Editor. I imagine many will see it and think "what's Gutenberg?"

I also don't love that it adds an extra step between opening the Style Book and previewing the styles. Could we instead have onboarding text within the Style Book somewhere?

At any rate, let's do this in a follow-up PR.

including a proposal for how to show the block types when the canvas is resized.

I skipped the part of this where the tabs turn into a dropdown. This behaviour should be something that TabPanel does automatically, so let's implement it in a follow-up @wordpress/components PR. For now as an interim solution I just made the tabs have overflow: auto.

@noisysocks noisysocks changed the title WIP: Add Style Book to Global Styles Add Style Book to Global Styles Nov 30, 2022
@bph
Copy link
Contributor

bph commented Dec 6, 2022

The ‘story book’ is such a cool feature. And naming things is hard.

The Storybook that has been in the block editor until now is the interactive component tool for developers..
Could we possibly find a different name for the story book in his PR? Like “Style Guide”, “Block design guide”?

@noisysocks
Copy link
Member Author

Open to suggestions 😀 it's not too late to rename. FWIW, the implemented name is Style Book, not Story Book.

@noisysocks
Copy link
Member Author

@jasmussen @jameskoster I updated the font size in #46341.

@bph
Copy link
Contributor

bph commented Dec 7, 2022

Ah Style book. My brain just wasn't slowing down long enough to even see the difference. Sorry about that.

mpkelly pushed a commit to mpkelly/gutenberg that referenced this pull request Dec 7, 2022
* Add Style Book

* Disable toolbar butons when Style Book is open

* Disable Style Book when in Code Editor mode

* Make cursor a hand when hovering an example

* Remove top and bottom margin from block inside preview

* Add border beneath tab bar, make tab bar scroll on mobile

* Improve performance

* Improve a11y

* Add E2E tests

* Make example titles uppercase

* Hide toolbar when Style Book is open

* Make tabs always have white background

* Update tests

* Add a little note of encouragement for future developers

* Add border radius to Story Book

* Fix vertical alignment of close button

* Reduce font size and increase font weight of example labels

* Remove hover outline

* Use theme color for text instead of white or black

* Use math.div()
@madhusudhand
Copy link
Contributor

This is amazing. Created #46393 and #46394 for the followup.

@ryanwelcher ryanwelcher changed the title Add Style Book to Global Styles Global Styles: Add Style Book to Global Styles Dec 14, 2022
@femkreations femkreations added the Needs User Documentation Needs new user documentation label Feb 1, 2023
@sunyatasattva
Copy link
Contributor

Hey @noisysocks, sorry for intruding into the thread, but is there any way to disable Style Book for certain blocks? We can remove the example prop from the block.json, but that would make the live preview disappear from the inserter.

Some of our blocks are not style-able, or not style-able yet, so it'd be nice if there was an opt-out mechanism.

@noisysocks
Copy link
Member Author

The only way to opt out right now is by removing the example attribute. We can consider adding a different opt out mechanism. Just so that I understand the problem fully, what's your reason for not wanting a block to appear in Style Book?

@sunyatasattva
Copy link
Contributor

The main reason is that Global Styles are not quite supported, or are currently buggy, so we'd rather hide it temporarily, then give the users a false impression that they can use Global Styles on those blocks.

The secondary reason is that some of the blocks don't have any styles options whatsoever.

@noisysocks
Copy link
Member Author

Thinking about it some more I think an opt out mechanism might be inappropriate.

The point of Style Book is to see how style changes affect everything that might be inserted. It's equivalent to inserting all of the blocks in one's library into a page to test them. Even if a block doesn't adopt any global style settings, element styles may indirectly affect the block and users / theme developers should be aware of that impact.

@bph bph added the Needs Dev Note Requires a developer note for a major WordPress release cycle label Feb 6, 2023
@bph
Copy link
Contributor

bph commented Feb 6, 2023

Flagged for 'Single Post Dev Note`. It's a major enhancement for developers (their blocks show up into the style book) and the mechanism to opt-out via removing the 'example' attribute.

@bph bph mentioned this pull request Feb 6, 2023
47 tasks
@andrewserong
Copy link
Contributor

andrewserong commented Feb 10, 2023

Dev note for 6.2

Style Book preview of blocks in global styles

In WordPress 6.2 a new feature has been added to the global styles interface that allows a user to preview every block that can be inserted into their site. The Style Book can be accessed via the eye icon in the Styles header within global styles, and provides an at-a-glance preview of how global styles will affect the display of any block, without the user having to insert those blocks into a template.

Following the structure of the block inserter, the Style Book will be populated by every block that can be inserted via the block inserter, and that also an example set. The categories/tabs in the Style Book also follow the same categories used by the block inserter. For block developers that already set an example for custom blocks, no additional parameters are required for the block to be visible in the Style Book.

Within the Style Book, a user can click on a preview of a block and it will navigate them to the block-level global styles where the block's styling can be adjusted. Overall, this makes it easier for a user to preview changes to block-level global styles, without having to insert the block within the current template.

Even if a block has no direct styling controls, it is still valuable for blocks to appear in the Style Book, so that the user can see how the overall site design and styling settings will affect every block that can be inserted. For example, site-wide background and text colors, or font family or font sizes generally affect how all blocks will be displayed.

However, there still might be cases where block developers wish to hide blocks from being inserted and therefore also hide them from the Style Book. The two ways to hide blocks from the Style Book are:

  • If the block has supports.inserter set to false within the block.json file, then the block will be hidden from both the block inserter and the Style Book.
  • If the block does not have an example set.

To read more on adjusting the supports.inserter value, see the entry on block supports in the developer handbook.

The conditions of when to show or hide blocks from the Style Book are intentionally tied to the same logic as used by the block inserter. The principle behind the Style Book is that if a user can insert or view a preview of the block, then it should also be previewed within the context of global styles.


@bph here's a draft above — does that about cover it? Happy to continue to edit / add or remove things from this one as needed.

@bph
Copy link
Contributor

bph commented Feb 17, 2023

@andrewserong Thank you for drafting the dev note. I think it covers it. Maybe add an example block.json section
so we wouldn't need to link out to the documentation for this single snippet.

supports: {
    // Hide this block from the inserter.
    inserter: false
}

If you agree that this is suitable for a single dev note post, would you please create a draft on the Make Blog so we can get into the review process?

@andrewserong
Copy link
Contributor

Yes, of course, thanks @bph — I've added a draft for the Style Book dev note over in: https://make.wordpress.org/core/?p=102735&preview=1&_ppp=03ed6e05f5 (also moved the links to be inline and added the block.json example)

@noisysocks
Copy link
Member Author

Thanks for writing the note @andrewserong!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json Needs Dev Note Requires a developer note for a major WordPress release cycle Needs User Documentation Needs new user documentation [Type] Feature New feature to highlight in changelogs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Global styles: Offer a way to view a document containing all blocks and styles