Skip to main content

Plugin theme

A widget plugin draws in a sandboxed frame that shares none of the app's styles. This page describes the few styles that the frame has of its own, and the theme trait through which the host tells the plugin about the app's colors.

The frame has three styles of its own. The elements html, body and #root have no margin, they fill the frame, and they hide overflow. The element <meta name="color-scheme"> is dark or light, and the frame's color-scheme follows the app's theme when it changes. Each file that the manifest's entry.styles names is added to the frame as a style element.

The theme trait​

The host gives the module a theme trait and updates it whenever the theme changes. The trait is an object with these fields:

FieldValue
modeThe current mode, which is "dark" or "light".
tokensAn object of color values, keyed by the token names below, together with font-family. A color is a six-digit hex value, except a color with transparency, which the host gives as the stylesheet writes it.
localeThe browser's language, for example en-US.
decimalsThe number of decimals to show, which is 2.

When the host builds the trait, it reads each token from the computed style of the app's body, so a value is the color that the app shows in the current theme. A token that the app does not define is left out of the object. The value of font-family is the computed font family of the body.

The table lists the tokens with the values that the stylesheets declare:

TokenRead fromLightDark
background--background#ffffff#0b2432
foreground--foreground#1a3248#e7f2f8
card--card#f4f9fc#123244
card-foreground--card-foreground#1a3248#e7f2f8
border--border#b7cdd8#355867
accent--accent#f4f9fc#1a4154
accent-foreground--accent-foreground#1a3248#e7f2f8
brand-main--brand-main#0086bf#0086bf
brand-lighter--brand-lighter#00b5e2#00b5e2
brand-darker--brand-darker#005e8a#005e8a
alert-error--alert-error#b91c1c#ef5555
alert-success--alert-success#15803d#59cf6d
alert-warning--alert-warning#ba6509#f18a1a
alert-informative--alert-informative#065592#3892d9

The tokens brand-main, brand-lighter and brand-darker follow --color-main-100, --color-main-50 and --color-main-200, as Brand color, font and text size describes. The host resolves a value that is not hexadecimal to hex before it gives it to the module. That applies, for example, to a color-mix() that a theme gives to a brand step, so a stylesheet that changes the brand color changes these tokens too.

Nothing applies the tokens to the plugin's elements, and the frame defines no custom properties of its own. The module reads theme.tokens and theme.mode, and its own stylesheet decides what to draw. Style a plugin widget for both themes shows one way to do that.