UX Theme records, Next Experience (Polaris) Themes Part 2
This is Part 2. You should start with Part 1.
How do the UX Theme records work?
Any theme is made up of a few different things.
- The UX theme
- 1 or more UX styles (which may be core or variant)
- UX theme styles
- Assets
UX Theme
The UX Theme
record is the overall container. This one is simple.
UX Style
The UX Style
contains the JSON that stores the CSS variables. If it is Core
it will always apply and be part of the “default” theme. If it is a “variant” it will be selectable as an alternate colors set.
UX Theme Style
The UX Theme Style
is the m2m record that links the theme and style. It also has two important fields. First is “Audience”, which controls who has access to that style. For example, you could have a variant only available to certain users or even force a core theme to apply for certain users. Second is “Weight”, which controls when something should apply. The weight works the same way as many other places in the platform. A weight of 0 will always apply, unless something with a higher weight overrides it. Unlike elsewhere in the platform weight does not work at the record level. Rather when the theme is resolved into values it is a variable by variable comparison of weight.
This is not official information, it is what I have observed by experimenting.
This means that if there are 2 styles that both define the same variable, the one with the largest weight will apply. As an example if you make a core theme with a weight of 100 and a variant with a weight of 10, nothing defined in the variant that is also defined in core will apply.
I plan to talk more about how I structure my themes in another article, but here is a practical example. There are a lot of variables that need to be mapped to something in order to not just use a default value. If you want your login page to match your instance theme you need to set up those mappings. I mapped those out in a UX Style that I could reuse across multiple themes, and I give it a weight of 0. When I make a La Jolla inspired theme, the login page was… ugly. So in my La Jolla Style I added some of the login page variables, and gave that style a larger weight. This way the login page looks “good” and if someone decides to change the Core style to one of the variants everything will still work and look good.