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

Rendering duotone presets in pattern preview #41249

Merged
merged 15 commits into from
Jun 22, 2022

Conversation

matiasbenedetto
Copy link
Contributor

What?

Fixing duotone rendering in the pattern selection panel.

Why?

This is necessary to make the pattern preview accurate.

How?

In this PR we render the duotone svg filters default and theme filter inside the pattern preview iframe.

Previously we were rendering just the custom duotone applied to the current block but if the block has a filter applied globally using theme.json, the duotone doesn't work because the preset filters were not rendered.

Testing Instructions

  1. Use a theme that supports duotone for example Skatepark
  2. Create a new post or page
  3. Open the add pattern panel
  4. See the patterns that include blocks without a custom duotone applied but with duotone presets in theme.json for example "Full-width image with aside caption" from Skatepark.

Screenshots or screencast

Before: After:
image image
image image

Copy link
Contributor

@ajlende ajlende left a comment

Choose a reason for hiding this comment

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

Just a couple minor things. This is looking great!

@ajlende ajlende added [Type] Bug An existing feature does not function as intended [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. labels May 24, 2022
Copy link
Contributor

@ajlende ajlende left a comment

Choose a reason for hiding this comment

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

Looking good! Give it a rebase/merge to see if that fixes the failing tests—they don't look related to the changes here

@matiasbenedetto matiasbenedetto force-pushed the fix/35331-bis branch 4 times, most recently from 26993bf to 2e0f098 Compare June 8, 2022 17:57
@matiasbenedetto
Copy link
Contributor Author

I found the problem that is causing the test failures. It is related to the import of this component import { PresetDuotoneFilter } from '../../hooks/duotone';. When we import that component from the file packages/block-editor/src/hooks/duotone.js the filters are called and I think we should not do that.

addFilter(
	'blocks.registerBlockType',
	'core/editor/duotone/add-attributes',
	addDuotoneAttributes
);
addFilter(
	'editor.BlockEdit',
	'core/editor/duotone/with-editor-controls',
	withDuotoneControls
);
addFilter(
	'editor.BlockListBlock',
	'core/editor/duotone/with-styles',
	withDuotoneStyles
);

For that reason, I'm considering moving the definition of thePresetFilter component to another file.

@ajlende
Copy link
Contributor

ajlende commented Jun 9, 2022

@matiasbenedetto This change would be making the API public, and I want to make sure the API is a little more friendly before we do that. I'm planning on changing the API for InlineDuotone and DuotoneFilter in #39564: values will be replaced with colors (string[]) so getValuesFromColors can be inlined into DuotoneFilter.

For now can we export them as __unstable to indicate that they are for internal use only right now? This should also stop the documentation from generating.

I think DuotoneFilter with the new API and DuotoneStylesheet could become the two exported things eventually. I think that's probably the smallest subset of components to expose since they need to be used separately sometimes. PresetDuotoneFilter could be in use-global-styles-output.js and InlineDuotone could be in duotone.js like before.

@matiasbenedetto
Copy link
Contributor Author

matiasbenedetto commented Jun 9, 2022

@matiasbenedetto This change would be making the API public, and I want to make sure the API is a little more friendly before we do that. I'm planning on changing the API for InlineDuotone and DuotoneFilter in #39564: values will be replaced with colors (string[]) so getValuesFromColors can be inlined into DuotoneFilter.

Thanks for the context!

For now can we export them as __unstable to indicate that they are for internal use only right now?

Yep, done.

This should also stop the documentation from generating.

Good, I deleted the additions to the docs. By the way, the docs are not autogenerated but there is a check before commit that fails if the docs are not there. Despite I exported the components as __unstable the linter complained that we need to update the docs.

PresetDuotoneFilter could be in use-global-styles-output.js

This component is also used in packages/block-editor/src/components/block-preview/auto.js, and at a glance packages/edit-site/src/components/global-styles/use-global-styles-output.js doesn't seem to be the best place for it. Do you think we should move it from the current location (packages/block-editor/src/components/duotone/components.js)?

and InlineDuotone could be in duotone.js like before.

Done!

@matiasbenedetto matiasbenedetto requested a review from ajlende June 13, 2022 21:07
@matiasbenedetto
Copy link
Contributor Author

Updated with the latest changes from #39564

@ajlende ajlende merged commit 4315382 into WordPress:trunk Jun 22, 2022
@github-actions github-actions bot added this to the Gutenberg 13.6 milestone Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants