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

Components: Add styles package for new style system #30630

Closed
wants to merge 19 commits into from

Conversation

sarayourfriend
Copy link
Contributor

Description

Part of #30503

This PR adds the style package from G2. This package contains the theme as well as some simple helper functions. It also further enhances the css function's responsive styles by making them fall in line with the style system by enhancing the call to responsive with getScaleStyles. This means that responsive values will be transformed using the space function which means responsive values like [2, 4, 6] will all get passed to space, making them fall in line with the style system's spacing (🎉)

It also removes the IE11 shim for supporting CSS Custom Properties fallbacks by removing it entirely. I decided to do this becuase the RootStore method was causing a difficult/impossible to debug infinite loop for some reason and instead of spending hours debugging something that is going to be removed soon, I decided to just go ahead and remove it.

This PR also adds a number of unit tests that test both styles and create-styles, mostly around the css styled and component interpolation functions.

Note: to resolve an ESLint warning about direct window access, I had to change the useResponsiveValue function to accept a node parameter. We'll have to update it's usages to pass a node when we update existing components to use this version of styles.

Outstanding question: How to resolve and handle theme variables? Should we move the theme initialization into a common package that this then uses? Now that you can see more clearly how the theme is initialized, are there any ideas for how to clean this up and make it more comprehendible? Should we indeed remove all the various extra generated color variables as was suggested? Should we go ahead and convert non-color variables into regular JS object key/value objects (or do that in a fast-follow PR [my preference])?

How has this been tested?

Unit tests pass as well as type checks.

Types of changes

New, unexported and unused features.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • [N/A] My code follows the accessibility standards.
  • [N/A] I've tested my changes with keyboard and screen readers.
  • 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 (please manually search all *.native.js files for terms that need renaming or removal).

@sarayourfriend sarayourfriend self-assigned this Apr 8, 2021
@sarayourfriend sarayourfriend added [Feature] Component System WordPress component system [Package] Components /packages/components npm Packages Related to npm packages labels Apr 8, 2021
@github-actions
Copy link

github-actions bot commented Apr 8, 2021

Size Change: +41.9 kB (+3%)

Total Size: 1.47 MB

Filename Size Change
build/annotations/index.js 3.78 kB -5 B (0%)
build/api-fetch/index.js 3.41 kB -1 B (0%)
build/autop/index.js 2.83 kB +15 B (+1%)
build/block-directory/index.js 8.62 kB -3 B (0%)
build/block-editor/index.js 130 kB +2.44 kB (+2%)
build/block-editor/style-rtl.css 12.6 kB +144 B (+1%)
build/block-editor/style.css 12.6 kB +142 B (+1%)
build/block-library/blocks/buttons/style-rtl.css 368 B +4 B (+1%)
build/block-library/blocks/buttons/style.css 368 B +5 B (+1%)
build/block-library/blocks/cover/style-rtl.css 1.23 kB -11 B (-1%)
build/block-library/blocks/cover/style.css 1.23 kB -12 B (-1%)
build/block-library/blocks/file/editor-rtl.css 301 B +126 B (+72%) 🆘
build/block-library/blocks/file/editor.css 300 B +126 B (+72%) 🆘
build/block-library/blocks/file/style-rtl.css 255 B +7 B (+3%)
build/block-library/blocks/file/style.css 255 B +7 B (+3%)
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB -6 B (0%)
build/block-library/blocks/freeform/editor.css 2.44 kB -6 B (0%)
build/block-library/blocks/gallery/style-rtl.css 1.09 kB -14 B (-1%)
build/block-library/blocks/gallery/style.css 1.09 kB -15 B (-1%)
build/block-library/blocks/navigation/editor-rtl.css 1.24 kB +3 B (0%)
build/block-library/blocks/navigation/editor.css 1.24 kB +3 B (0%)
build/block-library/blocks/navigation/style-rtl.css 272 B +68 B (+33%) 🚨
build/block-library/blocks/navigation/style.css 271 B +66 B (+32%) 🚨
build/block-library/blocks/query/editor-rtl.css 810 B +15 B (+2%)
build/block-library/blocks/query/editor.css 809 B +15 B (+2%)
build/block-library/blocks/site-logo/editor-rtl.css 440 B +2 B (0%)
build/block-library/blocks/site-logo/editor.css 441 B +3 B (+1%)
build/block-library/blocks/site-logo/style-rtl.css 154 B +4 B (+3%)
build/block-library/blocks/site-logo/style.css 154 B +4 B (+3%)
build/block-library/blocks/social-links/editor-rtl.css 796 B +20 B (+3%)
build/block-library/blocks/social-links/editor.css 795 B +19 B (+2%)
build/block-library/blocks/verse/editor-rtl.css 0 B -50 B (removed) 🏆
build/block-library/blocks/verse/editor.css 0 B -50 B (removed) 🏆
build/block-library/blocks/video/editor-rtl.css 568 B +64 B (+13%) ⚠️
build/block-library/blocks/video/editor.css 569 B +66 B (+13%) ⚠️
build/block-library/blocks/video/style-rtl.css 173 B -14 B (-7%)
build/block-library/blocks/video/style.css 173 B -14 B (-7%)
build/block-library/editor-rtl.css 9.83 kB +60 B (+1%)
build/block-library/editor.css 9.82 kB +63 B (+1%)
build/block-library/index.js 154 kB +1.35 kB (+1%)
build/block-library/style-rtl.css 9.44 kB +34 B (0%)
build/block-library/style.css 9.44 kB +34 B (0%)
build/block-serialization-default-parser/index.js 1.87 kB +4 B (0%)
build/blocks/index.js 48.6 kB +139 B (0%)
build/components/index.js 285 kB +1.34 kB (0%)
build/components/style-rtl.css 16.2 kB -79 B (0%)
build/components/style.css 16.2 kB -80 B (0%)
build/compose/index.js 11.6 kB +330 B (+3%)
build/core-data/index.js 17.2 kB +38 B (0%)
build/customize-widgets/index.js 8.25 kB +1.16 kB (+16%) ⚠️
build/data/index.js 8.87 kB -14 B (0%)
build/dom/index.js 5.12 kB -51 B (-1%)
build/edit-navigation/index.js 17 kB +2 B (0%)
build/edit-navigation/style.css 2.86 kB -1 B (0%)
build/edit-post/index.js 339 kB +31.9 kB (+10%) ⚠️
build/edit-post/style-rtl.css 6.96 kB +9 B (0%)
build/edit-post/style.css 6.95 kB +8 B (0%)
build/edit-site/index.js 28.7 kB +692 B (+2%)
build/edit-site/style-rtl.css 4.9 kB +285 B (+6%) 🔍
build/edit-site/style.css 4.89 kB +281 B (+6%) 🔍
build/edit-widgets/index.js 16.7 kB +1 kB (+6%) 🔍
build/edit-widgets/style-rtl.css 2.97 kB -4 B (0%)
build/edit-widgets/style.css 2.98 kB -4 B (0%)
build/editor/index.js 42.6 kB +229 B (+1%)
build/editor/style-rtl.css 3.9 kB -23 B (-1%)
build/editor/style.css 3.9 kB -24 B (-1%)
build/element/index.js 4.62 kB -4 B (0%)
build/format-library/index.js 6.77 kB +12 B (0%)
build/hooks/index.js 2.28 kB -1 B (0%)
build/i18n/index.js 4.04 kB +25 B (+1%)
build/keyboard-shortcuts/index.js 2.53 kB -1 B (0%)
build/keycodes/index.js 1.95 kB -9 B (0%)
build/list-reusable-blocks/index.js 3.19 kB -1 B (0%)
build/media-utils/index.js 5.39 kB +9 B (0%)
build/notices/index.js 1.85 kB -5 B (0%)
build/nux/index.js 3.42 kB +2 B (0%)
build/plugins/index.js 2.95 kB -4 B (0%)
build/primitives/index.js 1.42 kB -8 B (-1%)
build/react-i18n/index.js 1.45 kB -2 B (0%)
build/redux-routine/index.js 2.83 kB -2 B (0%)
build/reusable-blocks/index.js 3.8 kB +10 B (0%)
build/rich-text/index.js 13.5 kB +33 B (0%)
build/server-side-render/index.js 2.6 kB -6 B (0%)
build/url/index.js 3.01 kB -10 B (0%)
build/viewport/index.js 1.85 kB -4 B (0%)
build/wordcount/index.js 1.22 kB -1 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/blob/index.js 664 B 0 B
build/block-directory/style-rtl.css 1 kB 0 B
build/block-directory/style.css 1.01 kB 0 B
build/block-library/blocks/archives/editor-rtl.css 61 B 0 B
build/block-library/blocks/archives/editor.css 60 B 0 B
build/block-library/blocks/audio/editor-rtl.css 58 B 0 B
build/block-library/blocks/audio/editor.css 58 B 0 B
build/block-library/blocks/audio/style-rtl.css 112 B 0 B
build/block-library/blocks/audio/style.css 112 B 0 B
build/block-library/blocks/block/editor-rtl.css 161 B 0 B
build/block-library/blocks/block/editor.css 161 B 0 B
build/block-library/blocks/button/editor-rtl.css 475 B 0 B
build/block-library/blocks/button/editor.css 474 B 0 B
build/block-library/blocks/button/style-rtl.css 503 B 0 B
build/block-library/blocks/button/style.css 503 B 0 B
build/block-library/blocks/buttons/editor-rtl.css 315 B 0 B
build/block-library/blocks/buttons/editor.css 315 B 0 B
build/block-library/blocks/calendar/style-rtl.css 208 B 0 B
build/block-library/blocks/calendar/style.css 208 B 0 B
build/block-library/blocks/categories/editor-rtl.css 84 B 0 B
build/block-library/blocks/categories/editor.css 83 B 0 B
build/block-library/blocks/categories/style-rtl.css 79 B 0 B
build/block-library/blocks/categories/style.css 79 B 0 B
build/block-library/blocks/code/style-rtl.css 90 B 0 B
build/block-library/blocks/code/style.css 90 B 0 B
build/block-library/blocks/columns/editor-rtl.css 190 B 0 B
build/block-library/blocks/columns/editor.css 190 B 0 B
build/block-library/blocks/columns/style-rtl.css 436 B 0 B
build/block-library/blocks/columns/style.css 435 B 0 B
build/block-library/blocks/cover/editor-rtl.css 605 B 0 B
build/block-library/blocks/cover/editor.css 605 B 0 B
build/block-library/blocks/embed/editor-rtl.css 486 B 0 B
build/block-library/blocks/embed/editor.css 486 B 0 B
build/block-library/blocks/embed/style-rtl.css 401 B 0 B
build/block-library/blocks/embed/style.css 400 B 0 B
build/block-library/blocks/file/frontend.js 765 B 0 B
build/block-library/blocks/gallery/editor-rtl.css 704 B 0 B
build/block-library/blocks/gallery/editor.css 705 B 0 B
build/block-library/blocks/group/editor-rtl.css 160 B 0 B
build/block-library/blocks/group/editor.css 160 B 0 B
build/block-library/blocks/group/style-rtl.css 57 B 0 B
build/block-library/blocks/group/style.css 57 B 0 B
build/block-library/blocks/heading/editor-rtl.css 129 B 0 B
build/block-library/blocks/heading/editor.css 129 B 0 B
build/block-library/blocks/heading/style-rtl.css 76 B 0 B
build/block-library/blocks/heading/style.css 76 B 0 B
build/block-library/blocks/html/editor-rtl.css 281 B 0 B
build/block-library/blocks/html/editor.css 281 B 0 B
build/block-library/blocks/image/editor-rtl.css 717 B 0 B
build/block-library/blocks/image/editor.css 716 B 0 B
build/block-library/blocks/image/style-rtl.css 476 B 0 B
build/block-library/blocks/image/style.css 478 B 0 B
build/block-library/blocks/latest-comments/style-rtl.css 281 B 0 B
build/block-library/blocks/latest-comments/style.css 282 B 0 B
build/block-library/blocks/latest-posts/editor-rtl.css 137 B 0 B
build/block-library/blocks/latest-posts/editor.css 137 B 0 B
build/block-library/blocks/latest-posts/style-rtl.css 523 B 0 B
build/block-library/blocks/latest-posts/style.css 522 B 0 B
build/block-library/blocks/legacy-widget/editor-rtl.css 398 B 0 B
build/block-library/blocks/legacy-widget/editor.css 399 B 0 B
build/block-library/blocks/list/style-rtl.css 63 B 0 B
build/block-library/blocks/list/style.css 63 B 0 B
build/block-library/blocks/media-text/editor-rtl.css 191 B 0 B
build/block-library/blocks/media-text/editor.css 191 B 0 B
build/block-library/blocks/media-text/style-rtl.css 535 B 0 B
build/block-library/blocks/media-text/style.css 532 B 0 B
build/block-library/blocks/more/editor-rtl.css 434 B 0 B
build/block-library/blocks/more/editor.css 434 B 0 B
build/block-library/blocks/navigation-link/editor-rtl.css 597 B 0 B
build/block-library/blocks/navigation-link/editor.css 597 B 0 B
build/block-library/blocks/navigation-link/style-rtl.css 1.07 kB 0 B
build/block-library/blocks/navigation-link/style.css 1.07 kB 0 B
build/block-library/blocks/nextpage/editor-rtl.css 395 B 0 B
build/block-library/blocks/nextpage/editor.css 395 B 0 B
build/block-library/blocks/page-list/editor-rtl.css 239 B 0 B
build/block-library/blocks/page-list/editor.css 240 B 0 B
build/block-library/blocks/page-list/style-rtl.css 167 B 0 B
build/block-library/blocks/page-list/style.css 167 B 0 B
build/block-library/blocks/paragraph/editor-rtl.css 157 B 0 B
build/block-library/blocks/paragraph/editor.css 157 B 0 B
build/block-library/blocks/paragraph/style-rtl.css 247 B 0 B
build/block-library/blocks/paragraph/style.css 248 B 0 B
build/block-library/blocks/post-author/editor-rtl.css 209 B 0 B
build/block-library/blocks/post-author/editor.css 209 B 0 B
build/block-library/blocks/post-author/style-rtl.css 183 B 0 B
build/block-library/blocks/post-author/style.css 184 B 0 B
build/block-library/blocks/post-comments-form/style-rtl.css 250 B 0 B
build/block-library/blocks/post-comments-form/style.css 250 B 0 B
build/block-library/blocks/post-content/editor-rtl.css 139 B 0 B
build/block-library/blocks/post-content/editor.css 139 B 0 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B 0 B
build/block-library/blocks/post-excerpt/editor.css 73 B 0 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B 0 B
build/block-library/blocks/post-excerpt/style.css 69 B 0 B
build/block-library/blocks/post-featured-image/editor-rtl.css 338 B 0 B
build/block-library/blocks/post-featured-image/editor.css 338 B 0 B
build/block-library/blocks/post-featured-image/style-rtl.css 100 B 0 B
build/block-library/blocks/post-featured-image/style.css 100 B 0 B
build/block-library/blocks/post-title/style-rtl.css 60 B 0 B
build/block-library/blocks/post-title/style.css 60 B 0 B
build/block-library/blocks/preformatted/style-rtl.css 103 B 0 B
build/block-library/blocks/preformatted/style.css 103 B 0 B
build/block-library/blocks/pullquote/editor-rtl.css 183 B 0 B
build/block-library/blocks/pullquote/editor.css 183 B 0 B
build/block-library/blocks/pullquote/style-rtl.css 318 B 0 B
build/block-library/blocks/pullquote/style.css 318 B 0 B
build/block-library/blocks/query-loop/editor-rtl.css 83 B 0 B
build/block-library/blocks/query-loop/editor.css 82 B 0 B
build/block-library/blocks/query-loop/style-rtl.css 315 B 0 B
build/block-library/blocks/query-loop/style.css 317 B 0 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B 0 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B 0 B
build/block-library/blocks/query-pagination/editor-rtl.css 270 B 0 B
build/block-library/blocks/query-pagination/editor.css 262 B 0 B
build/block-library/blocks/query-pagination/style-rtl.css 168 B 0 B
build/block-library/blocks/query-pagination/style.css 168 B 0 B
build/block-library/blocks/query-title/editor-rtl.css 86 B 0 B
build/block-library/blocks/query-title/editor.css 86 B 0 B
build/block-library/blocks/quote/style-rtl.css 169 B 0 B
build/block-library/blocks/quote/style.css 169 B 0 B
build/block-library/blocks/rss/editor-rtl.css 201 B 0 B
build/block-library/blocks/rss/editor.css 202 B 0 B
build/block-library/blocks/rss/style-rtl.css 290 B 0 B
build/block-library/blocks/rss/style.css 290 B 0 B
build/block-library/blocks/search/editor-rtl.css 189 B 0 B
build/block-library/blocks/search/editor.css 189 B 0 B
build/block-library/blocks/search/style-rtl.css 359 B 0 B
build/block-library/blocks/search/style.css 362 B 0 B
build/block-library/blocks/separator/editor-rtl.css 99 B 0 B
build/block-library/blocks/separator/editor.css 99 B 0 B
build/block-library/blocks/separator/style-rtl.css 251 B 0 B
build/block-library/blocks/separator/style.css 251 B 0 B
build/block-library/blocks/shortcode/editor-rtl.css 512 B 0 B
build/block-library/blocks/shortcode/editor.css 512 B 0 B
build/block-library/blocks/social-link/editor-rtl.css 164 B 0 B
build/block-library/blocks/social-link/editor.css 165 B 0 B
build/block-library/blocks/social-links/style-rtl.css 1.32 kB 0 B
build/block-library/blocks/social-links/style.css 1.33 kB 0 B
build/block-library/blocks/spacer/editor-rtl.css 308 B 0 B
build/block-library/blocks/spacer/editor.css 308 B 0 B
build/block-library/blocks/spacer/style-rtl.css 48 B 0 B
build/block-library/blocks/spacer/style.css 48 B 0 B
build/block-library/blocks/table/editor-rtl.css 478 B 0 B
build/block-library/blocks/table/editor.css 478 B 0 B
build/block-library/blocks/table/style-rtl.css 402 B 0 B
build/block-library/blocks/table/style.css 402 B 0 B
build/block-library/blocks/tag-cloud/editor-rtl.css 118 B 0 B
build/block-library/blocks/tag-cloud/editor.css 118 B 0 B
build/block-library/blocks/tag-cloud/style-rtl.css 94 B 0 B
build/block-library/blocks/tag-cloud/style.css 94 B 0 B
build/block-library/blocks/template-part/editor-rtl.css 552 B 0 B
build/block-library/blocks/template-part/editor.css 551 B 0 B
build/block-library/blocks/term-description/editor-rtl.css 90 B 0 B
build/block-library/blocks/term-description/editor.css 90 B 0 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B 0 B
build/block-library/blocks/text-columns/editor.css 95 B 0 B
build/block-library/blocks/text-columns/style-rtl.css 166 B 0 B
build/block-library/blocks/text-columns/style.css 166 B 0 B
build/block-library/blocks/verse/style-rtl.css 87 B 0 B
build/block-library/blocks/verse/style.css 87 B 0 B
build/block-library/common-rtl.css 1.31 kB 0 B
build/block-library/common.css 1.31 kB 0 B
build/block-library/reset-rtl.css 502 B 0 B
build/block-library/reset.css 503 B 0 B
build/block-library/theme-rtl.css 692 B 0 B
build/block-library/theme.css 693 B 0 B
build/block-serialization-spec-parser/index.js 3.06 kB 0 B
build/customize-widgets/style-rtl.css 630 B 0 B
build/customize-widgets/style.css 631 B 0 B
build/data-controls/index.js 836 B 0 B
build/date/index.js 31.9 kB 0 B
build/deprecated/index.js 787 B 0 B
build/dom-ready/index.js 577 B 0 B
build/edit-navigation/style-rtl.css 2.86 kB 0 B
build/edit-post/classic-rtl.css 454 B 0 B
build/edit-post/classic.css 454 B 0 B
build/escape-html/index.js 735 B 0 B
build/format-library/style-rtl.css 637 B 0 B
build/format-library/style.css 639 B 0 B
build/html-entities/index.js 622 B 0 B
build/is-shallow-equal/index.js 699 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/priority-queue/index.js 791 B 0 B
build/reusable-blocks/style-rtl.css 225 B 0 B
build/reusable-blocks/style.css 225 B 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/warning/index.js 1.14 kB 0 B

compressed-size-action

@gziolo gziolo requested a review from jasmussen April 9, 2021 07:47
/**
* Internal dependencies
*/
import { get } from '../../create-styles';
Copy link
Member

Choose a reason for hiding this comment

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

@jasmussen, who could help reviewing all those config values proposed here?

Copy link
Contributor

Choose a reason for hiding this comment

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

To be quite honest, I don't recognize that many of them. The colors I do recognize seem to be quite out of date with the colors defined in our mixin, which are these:

Screenshot 2021-04-09 at 09 57 21

Not only that, but there are numerous additional colors which appear to not be used anywhere, have been created in isolation, don't sync up with the G2 designs from #18667, or even the the colors proposed for the current default color schemes. If we do start using them, it will simply fragment and dilute the interface. I even see the "Inter" font introduced. It's not used anywhere. To frame it differently, anything we introduce should be based on the designs in #27331, and I'd appreciate us not introducing any fonts, colors, shadows or treatments not outlined there.

@@ -0,0 +1,10 @@
export * from './core';
Copy link
Member

@gziolo gziolo Apr 9, 2021

Choose a reason for hiding this comment

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

While it's convenient to re-export everything, I think we need to have better control over what goes into the public API in the future. I noticed this pattern used quite often in the ui folder. The biggest issue I foresee is that new methods can get exported only to use with tests but through the chain of catch it all re-exports they might suddenly become available for usage outside of the package.

See https://github.com/WordPress/gutenberg/blob/trunk/packages/components/src/index.js for reference.

Sometimes it's convenient to export everything like in @wordpress/blocks:

export * from './api';

but then we are explicit one level deeper:
https://github.com/WordPress/gutenberg/blob/trunk/packages/blocks/src/api/index.js

* Internal dependencies
*/
import { get } from '../../create-styles';
import colorize from 'tinycolor2';
Copy link
Contributor

Choose a reason for hiding this comment

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

Just syncing up with @ajlende here, as I think tinycolor is also used for some of the Duotone stuff.

@sarayourfriend
Copy link
Contributor Author

Okay, after feedback about variables I've split them into two categories:

Theme variables, accessible as CSS Custom Properties via the get function. These are "public APIs" that align with the existing ones (or only add minimal ones like for font-size though maybe those should go into the next category)

Theme tokens, accessible only through the ui.tokens object as normal JS constants.

@sarayourfriend
Copy link
Contributor Author

@youknowriad @jasmussen @gziolo @mtias Could y'all take a look at this PR and let me know what all is left for it to be mergeable? Thanks! 🙂

@jasmussen
Copy link
Contributor

My primary concern is adding a slew of visual styles that aren't used yet, and that feedback appears well addressed, leaving only a code review.

One remaining question, though: does it make sense to introduce "dark mode" when none of the rest of WordPress is able to take advantage of it yet? If at all possible to omit also that, it seems like that would be the leanest version.


## Theme Tokens

Tokens are similar to variables except that they are not exposed as CSS Custom Properties. This is to avoid introducing too many new public APIs. Instead, we simply access them off of the `ui.tokens` object as you would any normal JavaScript object. `ui.tokens` is a _frozen_ object so runtime changes are no allowed to it, updates to it must be constant and done in the [`styles/tokens.js`](./tokens.js) module.
Copy link
Contributor

@youknowriad youknowriad Apr 16, 2021

Choose a reason for hiding this comment

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

So this does remove the possibility to implement the existing G2 themes right? since themes can't change these variables?

just to clarify for me, this is fine as a start but this is where I think we potentially need a ThemeProvider that relies on "context" in order to support this kind of themes, and at that point, it becomes clear that there's no much difference between "tokens" and "configuration" since both could be defined similary, the value of the configs can still be "CSS variables" while the values of the "tokens" can be just static values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Personally I think we should revert back to the existing solution and mark all the variables introduced by the new style system as unstable by prefixing them with --wp-unstable-token or something like that so that no one depends on them with the expectation that they won't change from under them.

I think this is best because it aligns with the original vision of the style system as relying solely on CSS custom properties, allowing theming through the original theme provider without introducing React context into the question which is a huge performance gain (if you're calling useTheme from every component in the tree this creates a significant performance hit that can be avoided just by using CSS custom properties).

What do you think, can we go back to the original implementation (with less variables of course) if we just mark the variables as unstable so we're not introducing a maintanence nightmare scenario?

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think, can we go back to the original implementation (with less variables of course) if we just mark the variables as unstable so we're not introducing a maintanence nightmare scenario?

I don't mind that personally yeah but I guess right now there's a big gap between what a "theme" is for G2 (hundreds of variables) and what a "theme" should be in my mind (a dozen variables at best). Do you think reconciling the two is possible?

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 mean we've already removed the hundreds of variables and paired it down to just a few dozen. I think we should expand our definition of theme to include spacing and some other things important to the "fit" and "feel" of the components that could be really valuable to be manipulated by a consumer through the ThemeProvider API... but the primary concern for themes is colors and fonts, which I think we're achieved now.

If we could move the tokens back into the regular theme now that would solve this concern for me.

What do you percieve to be the gap at this point in the definition of what a theme is, now that we've removed almost all the variables?

Copy link
Contributor

Choose a reason for hiding this comment

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

What we have now still feels a bit too much for me. I think G2's original goal was trying to allow "any theme" for any kind of design while I feel a WP focused component library should be more opinionated while allowing some customizations. It is important to think of a "theme" in this context as a "theme" for the entire WP-Admin and not just the component library.

In a lot of ways G2 was built as multi-purpose component library for any kind of JS frontends, similar to the number of components libraries that exist in the wild. This vision is where I feel there's a contradiction with what we want to achieve: a coherent component library for WordPress. So opinions are fine and even good and customization should be minimal IMO.

Based on this, for me the theme should be:

  • A main color
  • Potentially a secondary color
  • A grid unit (space)

a font family and font size, maybe but even that I don't think it's necessary for us (at least not at first).

I'm not sure I understand what you mean by "fit"/"feel".

Copy link
Contributor

Choose a reason for hiding this comment

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

Also what makes me uneasy about what G2 does at the moment is that it was develop as its own project and had to make a lot of decisions with designers from WordPress being involved in these discussions about what "theme" we want to support and what should be opinionated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By fit and feel I just mean spacing, border radius, border colors, background colors for elements that sit on top the background surface, intermediary colors like modal backdrop colors, animation variables (which are especially useful for automatically handling reduced motion instead of having to duplicate reduced motion handling across all components... or removing animations altogether if that's the target use-case needs it)... these are just some of the things I think fall into the fit and feel of a component system's design system or theme.

I don't think we need all 300 or whatever colors we had before, but I do think some of the things we've dropped are important to maintain for a component system to be customizable.

Say for example the WooCommerce plugin wanted to use WordPress/components, they'd need to be able to customize almost all of these things for wp/components to fall inline with their pre-existing design language.

Copy link
Contributor

Choose a reason for hiding this comment

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

WooCommerce plugin should customize the library to included its branding but it shouldn't be a departure from what the core styles are. This is where the different in vision stands, in the level of customizable things we want to have. I know @jasmussen has thoughts on this as well. It's clear to me for instance that the level of customizability G2 has currently is just way too much.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is an important balance to strike regarding how much is customizable. Too little and it might be a pain point, too much and it risks lacking character and direction. Ultimately that isn't something to decide completely, but I find it easier to start with less and add when it becomes necessary, rather than start with total customizability and realize we need to reel it in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha. If it's currently way too much then that's just how it is, let me know how best to pare it down and I'm happy to do so.

Personally I have no vision for this library, I just want it integrated so we can take advantage of the CSS-in-JS offerings it provides. I'm not married to any of the implementation details aside from ones I think give us a performance or usability edge over using raw Emotion.

The way this style system handles themes is not one of those things (aside from the performance aspect I pointed out of not wanting to use React context to pass around theme variables, that I think we should keep in CSS custom properties with the unstable prefix).

@@ -0,0 +1,34 @@
# Components

## StyleFrameProvider
Copy link
Contributor

Choose a reason for hiding this comment

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

This is great but I wonder if we could achieve the same without another provider, I mean why can't the style system directly relies on ownerDocument or something instead of requiring this provider.

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'm not sure I follow. Can you elaborate more on your alternative solution to iframe handling?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know the system enough how the current system works to propose anything meaningful. I guess my thinking is why can't a component just inject its own styles into the frame where it's used. This is just a random thought now, not important for this PR.

packages/components/src/ui/styles/components/box.js Outdated Show resolved Hide resolved
packages/components/src/ui/styles/hooks/use-rtl.js Outdated Show resolved Hide resolved
- `tokens`: A pre-defined set of theme variables, accessible via the frozen `tokens` object. See [Theme Tokens](#theme-tokens) below.
- Various mixins. See [Mixins](#mixins) below.

## Theme Configuration
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that we're only keeping the variables that are already defined in our Sass files as theme configuration, does this mean that we can now remove all the code that generates the CSS variables from create-styles like discussed in the previous PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No because the Sass variables are just Sass variables, they're not CSS custom properties so they're not accessible from CSS-in-JS. If anything I'd say we should remove the Sass variables and switch to just CSS custom properties?

Copy link
Contributor

@youknowriad youknowriad Apr 16, 2021

Choose a reason for hiding this comment

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

No I'm not talking about SASS variables, I'm talking about the CSS variables generated by the SASS mixin we already use to theme the components and UI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha. Currently that's only like one variable right?

We already declare a dependency on base-styles anyway so I don't see that as a problem 🤔 But if we changed the style system to use the unstable prefix I think we should keep it consistent and keep all the style system variables inside the style system and not rely on anything external to generate the variables, right?'

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the current system in create-styles that generates the variables on load from the theme is a bit too advanced for our needs. I don't really care whether we simplify that system and make it the canonical way of including the "default css variables" or whether we just enhance our existing mixin to include the new variables, but we should just have just one consistent system and use it across our packages. (components package not being the only package that can be themable and React dependency shouldn't be mandatory)

Copy link
Contributor

Choose a reason for hiding this comment

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

To clarify, I don't think this is necessarily something that we need to act upon on this PR necessarily but something that need to be solved.

@gziolo
Copy link
Member

gziolo commented Apr 16, 2021

If @jasmussen and @youknowriad are happy then I'm happy, too 😄

I don't have any concerns myself.

@sarayourfriend sarayourfriend deleted the add/styles branch April 21, 2021 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Component System WordPress component system npm Packages Related to npm packages [Package] Components /packages/components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants