theming
This page covers how to give your platform light and dark themes that all remotes follow, without each remote carrying theme code. The shell owns the choice, and remotes only read CSS variables.
What you get
The shell gets a provider, a theme picker, and a small script that applies the saved theme before the page paints. Remotes get a tokens object that points at the same variables. This feature is off by default.
Add it
What changed in the shell and each remote:
Three existing shell files are edited:
If testing is installed, the stored theme, the toggle and the tokens get tests.
Use it
Define the tokens once in the shell. Each token becomes a --mf-<token> variable on the page's root element.
A remote then uses them in CSS:
Or in TypeScript, with fallbacks for when the remote runs on its own:
Switching themes rewrites the variables on the root element, so every remote changes at once with no re-render and no event passed between them.
Configure it
There are no install options. Everything is in themes.ts, which is yours to edit:
How it works
The choice is saved in the shell's storage under shell:theme. Two things apply it on load. A script generated by noFlashScript sits first in the shell's head, so the stored colours are on the page before any bundle loads. Then apply-stored.ts runs as the first boot step and does the same before the first component renders.
Both use the same order: a stored name that matches one of your themes, then the system dark preference if followSystem is on, then defaultTheme.
Gotchas
- If your Content Security Policy blocks inline scripts, the head script is skipped. The boot step still applies the theme before the first render, but the page shows default colours until JavaScript has run.
- A stored value that is not one of your themes, such as
constructor, is ignored. - Token and theme names are lowercase letters, digits and dashes. Anything else throws when the theme is defined.
Reference
- tailwind, which maps its colours to the
--mf-color-*tokens - ui-shadcn, whose components are styled with Tailwind
- Shared singletons