Allow JS/TS versions of theme.json #60471
Labels
[Feature] Themes
Questions or issues with incorporating or styling blocks in a theme.
[Type] Enhancement
A suggestion for improvement.
What problem does this address?
JSON is limited the the values you can put in. It doesn't allow any automatic/ calculated generation of properties, you must put values in at write time.
What is your proposed solution?
Having an option to create a JavaScript (
theme.js
) or TypeScript file (theme.ts
) would allow theme creators to generate properties. This is already a common practice when configuring tools e.g.eslint
andstylelint
.This could be combined with a package to export helper functions for generating properties.
For example, I want to generate a spacing scale which is currently possible with the theme.json, but I am limited to the naming scheme that WP has provided for the CSS variable names.
Another example is colours, what if I wanted to define a palette of colours, and then also defined opacity options for those colours.
These are simple examples, but having a JS/TS version would make this file much more extensible for theme developers.
And to be clear, I'm not saying we should get rid of theme.json, but add this as an alternate option alongside it.
In case of naming conflicts, we could add a PHP config option to change the file name, and potentially have a
theme supports
option for it, and theme.json should take precedence if it is there to avoid issues with existing setups with a theme.js file in the root.The text was updated successfully, but these errors were encountered: