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

Custom CSS variables #64433

Open
asafm7 opened this issue Aug 12, 2024 · 10 comments
Open

Custom CSS variables #64433

asafm7 opened this issue Aug 12, 2024 · 10 comments
Labels
[Type] Enhancement A suggestion for improvement.

Comments

@asafm7
Copy link

asafm7 commented Aug 12, 2024

Consider introducing custom CSS variables to be used across the editor and in external CSS files using the var() function.

Similar to the global colors' functionality.

@asafm7 asafm7 added the [Type] Enhancement A suggestion for improvement. label Aug 12, 2024
@carolinan
Copy link
Contributor

Hi,
Can you please add more context?
Is this related to extending the editor, or for use in components in the project itself?
CSS variables are used extensively already.

@asafm7
Copy link
Author

asafm7 commented Aug 12, 2024

Thanks, @carolinan.

For example, in the editor, in the global styles section, being able to define a var called Global Border Radius with a value of 12px.

Then, everywhere in the editor where a border radius can be set, it will be possible to use the global variable. This way, if, for example, a decision is made to change the design from 12px to 8px it can be done from one place.

This will also allow external CSS files to use the variable, making the design easier to maintain in this regard as well.

Just like when a Primary color is changed, it is reflected on all places set to use it (including external CSS).

Maybe the variable's type is better defined by a unit (px, em etc.) rather than a property (border-radius, font-size etc.)

Please let me know if this is clearer.

Thanks again.

@carolinan
Copy link
Contributor

carolinan commented Aug 12, 2024

How is this different from the existing global styles system?
I personal don't think that having input fields for entering custom CSS variables would be useful for the majority of users.
But I also believe that what you are describing is also already possible using the global styles.
I don't think there is anything that is preventing using the preset css variables in third party CSS files.

@asafm7
Copy link
Author

asafm7 commented Aug 12, 2024

@carolinan, using the current global styles it is possible to set global styles on a block level, but not on a cross-block level.

If, for example, my design uses "soft corners" (that is, with a specific border-radius where possible) and I want it to be applied to many elements: images, buttons, embeds etc. - how can it be done using the current options?

@carolinan
Copy link
Contributor

carolinan commented Aug 12, 2024

By using the "custom" setting in theme.json then adding that custom variable to the border radius of each block and element.
Or by creating style variations that you can apply to multiple blocks.

If this is specific to borders please see #64041

@kspilarski kspilarski added Backport from WordPress Core Pull request that needs to be backported to a Gutenberg release from WordPress Core and removed Backport from WordPress Core Pull request that needs to be backported to a Gutenberg release from WordPress Core labels Aug 12, 2024
@asafm7
Copy link
Author

asafm7 commented Aug 12, 2024

Thanks, @carolinan.

I've tried adding a custom setting, but it isn't reflected in the UI.

So, if I understand correctly (correct me if I don't), what you mean is maintaining a custom code override for each relevant block.

This feels like complicating things, rather than simplifying them.

What I mean is making the custom variables available in the code.

Just like we have:
image

Meaning, the ability to choose a custom color or a preset color.

We can have:
image

I also went over the ticket you referred to and I'm now sure exactly what I mean. The tickets mention a scale (small, medium, large) rather than individual presets which aren't necessarily scale related.

@carolinan
Copy link
Contributor

That it is not reflected in the UI is also already reported as a separate issue.
For feature requests and bug reports to be actionable, they need to be limited in scope and specific.

@asafm7
Copy link
Author

asafm7 commented Aug 12, 2024

Thanks, @carolinan.

That it is not reflected in the UI is also already reported as a separate issue.

Can you maybe refer to this ticket?

Thanks again.

@carolinan
Copy link
Contributor

I found it here :) #37752

@asafm7
Copy link
Author

asafm7 commented Aug 12, 2024

Great. Thank you 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

3 participants