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

Should we allow creating your own CSS variables via Global Styles? #25393

Closed
oandregal opened this issue Sep 17, 2020 · 5 comments · Fixed by #25446
Closed

Should we allow creating your own CSS variables via Global Styles? #25393

oandregal opened this issue Sep 17, 2020 · 5 comments · Fixed by #25446
Assignees
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Status] In Progress Tracking issues with work in progress [Type] Question Questions about the design or development of the editor.

Comments

@oandregal
Copy link
Member

oandregal commented Sep 17, 2020

Context (slack thread).

Before #25301 the theme.json shape was like this:

{
  "global": {
    "presets": {
      "color": [
        { "slug": "nice-blue", "value": "some nice blue" }
      ],
      "font-size": [],
      "gradient": []
    },
    "styles": {},
    "features": {}
  }
}

The CSS variables we generate for presets follow this pattern --wp--preset--{category}--{slug} (ex: --wp--preset--color--nice-blue). The old mechanism took all categories within presets and created the proper variables without checking whether it was one of the three categories we had (color, gradient, font size) --- this was a bug. However, people used this to add their own things, like line-height presets (example 1, example 2).

After #25301 this is no longer possible, as we keep a curated list of presets. This is the current shape, for reference:

{
  "global": {
    "settings": {
      "color": {
        "gradients": [ ],
        "palette": [ ],
      },
      "typography": {
        "fontSizes": [ ],
      }
    }
  }
}

People raised that they were missing some CSS variables and proposed to add some back.


Given that theme.json pushes theme authors to write the less CSS possible (ideally, none), this bears the question: should we formalize the old mechanism by which it's possible to generate theme-only CSS variables that can be used in the styles?

@oandregal oandregal added the [Type] Question Questions about the design or development of the editor. label Sep 17, 2020
@oandregal
Copy link
Member Author

cc for thoughts: @aristath @kjellr as you were using this, @jorgefilipecosta @youknowriad @mtias

@oandregal
Copy link
Member Author

oandregal commented Sep 17, 2020

An alternative could be to add presets for the style properties we support that don't have presets yet (line-height (example), padding example) but don't surface them visually, as that resulted problematic in the previous attempts we tried. Would this be useful/enough?

Food for thought: the examples I saw were fundamentally used for typography, where you need a mix of font-size, line-height, etc to get good results. If people wanted to create a typographic scale (font base + scale) a system to create their own CSS variables would be handy, and having a curated list of things will prove not enough.

@oandregal oandregal added the Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json label Sep 17, 2020
@aristath
Copy link
Member

If people wanted to create a typographic scale (font base + scale) a system to create their own CSS variables would be handy, and having a curated list of things will prove not enough.

Agreed. It would be really convenient for theme-authors to have a single source of truth for all their default vars, and the theme.json is the logical choice.
Perhaps we could introduce customVars inside the JSON file where they can add the variables they need?

@kjellr
Copy link
Contributor

kjellr commented Sep 17, 2020

If people wanted to create a typographic scale (font base + scale) a system to create their own CSS variables would be handy, and having a curated list of things will prove not enough.

Themes are inevitably going to want to add additional variables, and I agree with @aristath that they should be declared in a single document. Putting them in some sort of "custom" section would be totally fine, and would make it clear that they aren't going to be surfaced in the UI somewhere.

@paaljoachim
Copy link
Contributor

We could also add a Custom CSS section to the global styles area.
Somewhat similar to the Additional CSS section in the customizer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Status] In Progress Tracking issues with work in progress [Type] Question Questions about the design or development of the editor.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants