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

Allow JS/TS versions of theme.json #60471

Open
mikeybinns opened this issue Apr 4, 2024 · 3 comments
Open

Allow JS/TS versions of theme.json #60471

mikeybinns opened this issue Apr 4, 2024 · 3 comments
Labels
[Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Enhancement A suggestion for improvement.

Comments

@mikeybinns
Copy link
Contributor

mikeybinns commented Apr 4, 2024

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 and stylelint.

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.

@mikeybinns mikeybinns added the [Type] Enhancement A suggestion for improvement. label Apr 4, 2024
@Mamaduka Mamaduka added the [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. label Apr 4, 2024
@Mamaduka
Copy link
Member

Mamaduka commented Apr 4, 2024

Somewhat related to issue #35099.

@Mamaduka
Copy link
Member

Mamaduka commented Apr 5, 2024

I don't think it is viable for the core to support theme.js|ts.

Why?

  • These file formats will need to be converted into something that PHP can parse out of the box. IIRC, this was the reason for choosing the JSON format.
  • JS/TS will require a build step to handle the conversion. The distributed WP core doesn't come with one. A lot of people are avoiding native block development just for this reason.

That being said, I think people can incorporate different file format support into their theme dev toolkits.

@mikeybinns
Copy link
Contributor Author

Sure I understand that.

Is there potential for having a core supported helper package for it, even if it's not supported out of the box? I'm envisioning a package which provides typescript types for the configs, and an already configured build process which takes a default export from a js/ts file and converts it into a json file.

If not, that's fine as well, I could create a community one, just think as a wordpress package, it would be easier to keep it up to date with changes to the theme.json schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

2 participants