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

Control editor palette and gradients from theme.json #25419

Conversation

jorgefilipecosta
Copy link
Member

This PR allows theme.json to control the color palette, preset gradients.
It updates the objects in experimental-default-theme.json because meanwhile the defaults were changed.

How has this been tested?

I verified I could change colors and gradients by changing the values on experimental-default-theme.json (provided theme, the color palette was disabled).
I verified I could set a different color palette just for the paragraph block by using theme.json.

@github-actions
Copy link

github-actions bot commented Sep 17, 2020

Size Change: -836 B (0%)

Total Size: 1.2 MB

Filename Size Change
build/block-editor/index.js 128 kB -843 B (0%)
build/block-library/index.js 134 kB +35 B (0%)
build/format-library/index.js 7.49 kB -28 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.52 kB 0 B
build/api-fetch/index.js 3.33 kB 0 B
build/autop/index.js 2.72 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 8.41 kB 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-editor/style-rtl.css 11.1 kB 0 B
build/block-editor/style.css 11.1 kB 0 B
build/block-library/editor-rtl.css 8.59 kB 0 B
build/block-library/editor.css 8.59 kB 0 B
build/block-library/style-rtl.css 7.6 kB 0 B
build/block-library/style.css 7.59 kB 0 B
build/block-library/theme-rtl.css 741 B 0 B
build/block-library/theme.css 741 B 0 B
build/block-serialization-default-parser/index.js 1.77 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 47.5 kB 0 B
build/components/index.js 202 kB 0 B
build/components/style-rtl.css 15.5 kB 0 B
build/components/style.css 15.4 kB 0 B
build/compose/index.js 9.42 kB 0 B
build/core-data/index.js 12 kB 0 B
build/data-controls/index.js 1.27 kB 0 B
build/data/index.js 8.43 kB 0 B
build/date/index.js 31.9 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 4.44 kB 0 B
build/edit-navigation/index.js 10.4 kB 0 B
build/edit-navigation/style-rtl.css 868 B 0 B
build/edit-navigation/style.css 871 B 0 B
build/edit-post/index.js 306 kB 0 B
build/edit-post/style-rtl.css 6.24 kB 0 B
build/edit-post/style.css 6.22 kB 0 B
build/edit-site/index.js 19.6 kB 0 B
build/edit-site/style-rtl.css 3.3 kB 0 B
build/edit-site/style.css 3.3 kB 0 B
build/edit-widgets/index.js 17 kB 0 B
build/edit-widgets/style-rtl.css 2.79 kB 0 B
build/edit-widgets/style.css 2.79 kB 0 B
build/editor/editor-styles-rtl.css 492 B 0 B
build/editor/editor-styles.css 493 B 0 B
build/editor/index.js 45.3 kB 0 B
build/editor/style-rtl.css 3.8 kB 0 B
build/editor/style.css 3.8 kB 0 B
build/element/index.js 4.45 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 1.74 kB 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.54 kB 0 B
build/is-shallow-equal/index.js 711 B 0 B
build/keyboard-shortcuts/index.js 2.39 kB 0 B
build/keycodes/index.js 1.85 kB 0 B
build/list-reusable-blocks/index.js 3.02 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/media-utils/index.js 5.12 kB 0 B
build/notices/index.js 1.69 kB 0 B
build/nux/index.js 3.27 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.44 kB 0 B
build/primitives/index.js 1.34 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/rich-text/index.js 13.7 kB 0 B
build/server-side-render/index.js 2.61 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.24 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.74 kB 0 B
build/warning/index.js 1.13 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@jorgefilipecosta jorgefilipecosta force-pushed the update/use-color-palette-and-gradients-from-theme.json branch from 59094e8 to 9262497 Compare September 17, 2020 14:42
Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

Glad I waited before working on this :P it was on my radar.
Great work here, I didn't test yet.

@@ -37,64 +36,6 @@ export const PREFERENCES_DEFAULTS = {
*/
export const SETTINGS_DEFAULTS = {
alignWide: false,
colors: [
Copy link
Contributor

Choose a reason for hiding this comment

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

The removal here means someone using the block editor package without providing a color palette may not work properly, did we check on the playground? Maybe it's fine but it's an npm package breaking change we should probably mention on the changelog.

Copy link
Member Author

Choose a reason for hiding this comment

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

We are going to have the WordPress defaults that the server needs to be aware of ( to generate CSS vars for example). Having defaults on the block editor inscreses the maintainability efforts. I guess we can remove the block editor defaults, I added a braking change note.

"gradient": "linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)"
"name": "Midnight",
"gradient": "linear-gradient(135deg,rgb(2,3,129) 0%,rgb(40,116,252) 100%)",
"slug": "midnight"
Copy link
Contributor

Choose a reason for hiding this comment

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

How about i18n here? Is the idea to keep the "double registration" for now (theme.json and php)?

Copy link
Member Author

Choose a reason for hiding this comment

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

We have a previous history of extracting i18n strings from JSON files. I opened an issue for this task wp-cli/i18n-command#224.
My plan is simply have a function that returns the translatable paths from theme.json. This function can probably be used by wp-cli. We simply use that function and on the translatable paths, we map the value to the result of __( value ). Provided the strings were extracted it should work well.
For now, the themes use theme supports and the strings are translatable there. I proposed a temporary solution for i18n of the WordPress default settings, until we have the proper string extraction ready.

@@ -132,11 +132,8 @@ function gutenberg_edit_site_init( $hook ) {
'maxUploadFileSize' => $max_upload_size,
);

list( $color_palette, ) = (array) get_theme_support( 'editor-color-palette' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to offer the handling of get_theme_support and map it to the new setting like we do for the other theme support flags or is this something that is already handled.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is already being handled when loading the theme configuration we also load things for themes using theme support. https://github.com/WordPress/gutenberg/blob/9262497ffb5cbbf7b49deec90c0bf5e9631c760a/lib/global-styles.php#L250. We map the existing theme supports to the new theme.json structure.

@youknowriad
Copy link
Contributor

useEditorFeature definitely simplifies the client code a lot. It's a good API I think.

@jorgefilipecosta jorgefilipecosta force-pushed the update/use-color-palette-and-gradients-from-theme.json branch from 9262497 to d46fe2a Compare September 18, 2020 12:11
Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

I tested this and it's working great for me.

I'd love if we explore again the automatic generated of the styles needed for the palettes on the frontend (like we do now for the CSS vars).

@jorgefilipecosta jorgefilipecosta force-pushed the update/use-color-palette-and-gradients-from-theme.json branch from d46fe2a to fb66433 Compare September 18, 2020 15:51
@jorgefilipecosta jorgefilipecosta force-pushed the update/use-color-palette-and-gradients-from-theme.json branch 2 times, most recently from 452baca to 0f9151a Compare September 18, 2020 17:00
Base automatically changed from update/key-existing-preset-shape-on-theme-json to master September 18, 2020 17:03
@jorgefilipecosta jorgefilipecosta force-pushed the update/use-color-palette-and-gradients-from-theme.json branch from 0f9151a to 716d0ca Compare September 18, 2020 17:05
@jorgefilipecosta jorgefilipecosta merged commit 26e4d59 into master Sep 18, 2020
@jorgefilipecosta jorgefilipecosta deleted the update/use-color-palette-and-gradients-from-theme.json branch September 18, 2020 17:40
@github-actions github-actions bot added this to the Gutenberg 9.1 milestone Sep 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants