Tokens/CSS vars
This is more of a “looking forward” section. The API contract we have for tokens is Paragon, any CSS vars that exist in the frontend outside of that aren’t part of that.
That being said, we do have a few examples of “application tokens” throughout the platform, and as of https://github.com/openedx/paragon/pull/4276 we have a way for theme authors to include those in their brand packages.
Rule of thumb: can we use a Paragon component for this?
Paragon components have theme support built-in, so by using those Instead of making a custom component in a frontend app with custom stylesheets, you get a “quick win” for themability.
CSS vars in frontend applications
There are multiple reasons someone would want to use CSS vars in a frontend application
Keeping styles DRY
Instead of repeating the same value in a lot of places in the application stylesheets, using a CSS var makes it easy to have a single source of truth. This has the side-effect of being something a brand package can override, but isn’t the goal of the CSS var.
Scoped themability
The example I like to use for this is --catalog-home-page-banner-background-color. It defaults to --pgn-color-gray-500, but changing --pgn-color-gray-500 would impact way more than just the home page banner background.
CSS vars can be changed at runtime
One form of pushback I could see for --catalog-home-page-banner-background-color is “but shouldn’t that just be handled by a slot?”
Slots offer build-time extensibility. Telling a site operator to rebuild the Catalog MFE to change the background color of the home page banner feels bad to me.
Rule of thumb (applicaton tokens): don’t add too many
In Paragon it makes sense to have pretty much everything set by tokens/css vars because it is the underlying design system. Being able to tweak all the little things and have those tweaks applied across the platform at runtime is great.
That pattern doesn’t make sense when adding vars to applications. If we had every margin-top as its own application token we’d quikcly get to a place where the entire DOM becomes an API we need to support, which just isn’t a maintainable place to be.
Rule of thumb (application tokens): meaningful tokens
If we’re adding an application specific CSS var with the intention of theme authors modifying it at runtime with brand packages, we should make sure we have a good reason to do so. Once we decide on which application tokens are “the API,” every token we add that falls into that category is something we need to maintain.
I don’t have a solid definition of “meaningful,” but things that come to mind are:
- Is this needed?
- Is this worth it?
- Is it going to stick around?
If a lot of operators want this extension point, and we expect to continue to have the thing it applies to for a while (read: the foreseeable future), and handling it with build-time extension points like slots doesn’t do the trick, it feels like it might be a meaningful thing to add.