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

Duotone: Dynamic filters based on theme.json variables #33905

Open
MaggieCabrera opened this issue Aug 5, 2021 · 7 comments
Open

Duotone: Dynamic filters based on theme.json variables #33905

MaggieCabrera opened this issue Aug 5, 2021 · 7 comments
Labels
[Block] Cover Affects the Cover Block - used to display content laid over a background image [Block] Image Affects the Image Block Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Enhancement A suggestion for improvement.

Comments

@MaggieCabrera
Copy link
Contributor

What problem does this address?

The use case for this feature would be a theme that wants to apply a duotone filter based on the colors of the theme. In this example we can think about the background/text color combo such as here:

Columns in container

It would be great if we could define the preset filter in this way in theme.json:

"duotone": [
        {
            "colors": [ "var(--wp--custom--color--primary)", "var(--wp--custom--color--background)" ],
            "slug": "my-filter",
            "name": "My filter"
        }
    ],

So that when the user changes the background color of their site, the already existing images will mage the new background color too.

@MaggieCabrera MaggieCabrera added [Block] Cover Affects the Cover Block - used to display content laid over a background image [Block] Image Affects the Image Block [Type] Enhancement A suggestion for improvement. labels Aug 5, 2021
@carolinan
Copy link
Contributor

I was very surprised when I learnt that this did not already work, how can we assure that this is included in the MVP's of any new color features?

@carolinan
Copy link
Contributor

I have received another support question about why presets do not work with the duotones.
Any tips of where to start looking to solve this?

@carolinan carolinan added the Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json label Feb 10, 2022
@ndiego
Copy link
Member

ndiego commented Mar 7, 2022

Ran into this over the weekend. We really need a solution for this. Duotone could be so powerful if it accepted variables.

@mateuswetah
Copy link
Contributor

mateuswetah commented Jun 3, 2022

Hey guys, really hoping for this to be solved one day. I'm creating a FSE theme that adds a lot of patterns using duotone. It also has global styles, but the changes won't be reflected if the duotone configuration does not accept css variables 😢

@mateuswetah
Copy link
Contributor

Has anyone had improvements on this? I was hoping that the new ref variables could to the trick, but apparently not yet.

@ajlende
Copy link
Contributor

ajlende commented Nov 28, 2022

The new ref can reference either settings or styles, but it can only be used within the styles right now since the lookup is only done when styles are computed.

If WP_Theme_JSON is updated to apply the ref lookup when reading in the theme.json file, before styles are computed, something like this may be able to work.

{
	"settings": {
		"color": {
			"duotone": [
				{
					"colors": [
						{ "ref": "settings.color.palette[0].color" },
						{ "ref": "settings.color.palette[1].color" }
					],
					"name": "Base and primary",
					"slug": "base-and-primary"
				}
			],
			"palette": [
				{
					"color": "#1E1E1E",
					"name": "Base",
					"slug": "base"
				},
				{
					"color": "#3858E9",
					"name": "Primary",
					"slug": "primary"
				}
			]
		}
	}
	"styles": {
		"blocks": {
			"core/image": {
				"filter": {
					"duotone": "var(--wp--preset--duotone--base-and-primary)"
				}
			}
		}
	}
}

I think using ref instead of resolving CSS custom properties (as shown in the issue description) will be much easier for implementing this enhancement.

@hanneslsm
Copy link

Is there any progress on this issue? What needs to be done to move it forward?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Cover Affects the Cover Block - used to display content laid over a background image [Block] Image Affects the Image Block Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

6 participants