Theming
The user picks the theme, the mode and the variant; the app offers the choice, remembers it, and never overrides it.
Put a ThemeMenu where the user can reach it from any screen, and let the store do the rest.
The theme is the user's: they pick it for their eyes, their room and their screen, and an app that
fixes one, or quietly bends one, takes that away.
The Settings demo's Appearance rows, on the site's own theme store. A pick in Theme repaints the
whole page, this text included; its mode row sets Auto, Light or Dark, and a theme's ▾ opens its
variants under it, the picked theme's open already. Terminal theme repaints only the test
output under it, from the pull request demo's failing run, unless it is left to follow. Edit…,
or Custom themes… in either menu, opens the ThemeEditor, which repaints the page with the
draft as you edit it.
What the user chooses#
| Choice | Values | Where |
|---|---|---|
| Style | The styles the app offers; there is no choice when it offers one | ThemeMenu's Style row |
| Theme | The themes the app passes the store, such as @orz/themes' built-ins | ThemeMenu |
| Mode | Auto (follows the system), Light, Dark; one-palette themes have one. Use AMOLED draws the dark side in true black, wherever the mode shows it, Auto's nights included | ThemeMenu's mode row, Use AMOLED behind its ▾ |
| Variant | Per theme, such as Tessera's accents or Catppuccin's flavours | Under its theme in ThemeMenu, once the row's ▾ opens them; the picked theme's are open already |
| Terminal theme | Any theme, a terminal-only one, or following the UI | ThemeMenu slot="terminal" |
| Custom themes | A theme based on another with overrides, or made from scratch | ThemeEditor |
The store saves the pick under the app's storageKey, follows the system's light and dark when the
mode is Auto, and follows a pick made in another tab.
The built-in themes#
@orz/themes ships these, each a module of its own; builtinThemes lists them all. A side
with a name of its own shows it, and the variants a side adds follow it. Style is the
style a theme is drawn for.
| Theme | Import | Style | Light | Dark |
|---|---|---|---|---|
| Tessera | defaultTheme (default) | Default | ✓; Blue, Indigo, Violet, Teal, Green, Amber, Vermilion, Crimson | ✓; Blue, Indigo, Violet, Teal, Green, Amber, Vermilion, Crimson |
| Warm Ink | warmInk (warm-ink) | Default | ✓ | ✓ |
| Kabushiki | kabushiki | Default | ✓; Ai, Enji, Tokiwa, Kaki, Edomurasaki | ✓; Ai, Enji, Tokiwa, Kaki, Edomurasaki |
| Picotera | picotera | Default | Pico | Tera |
| Solarized | solarized | Default | ✓ | ✓ |
| Visual Studio | vs | Default | ✓ | ✓ |
| GitHub | github | Default | ✓ | ✓ |
| Catppuccin | catppuccin | Default | Latte; Mocha (Gray), Frappé (Gray), Macchiato (Gray) | Mocha; Frappé, Macchiato, Mocha (Gray), Frappé (Gray), Macchiato (Gray) |
| Gruvbox | gruvbox | Default | ✓ | ✓ |
| Prohibitorum | prohibitorum | Default | ✓; Nord, Sand, Matcha, Sakura, Lavender, Lagoon, Citrus | ✓; Nord, Sand, Matcha, Sakura, Lavender, Lagoon, Citrus |
| Dracula | dracula | Default | ✓ | |
| Nord | nord | Default | ✓ | |
| Tokyo Night | tokyoNight (tokyo-night) | Default | ✓ | |
| One Dark | oneDark (one-dark) | Default | ✓ | |
| Monokai | monokai | Default | ✓ | |
| Afterglow | afterglow | Default | ✓ | |
| Windows Standard | windowsStandard (windows-standard) | Raymond | ✓ |
Every dark side can be shown in AMOLED, which makes the background true black.
Setting it up#
Start creates the store. Three things make it feel native:
- Pass the themes you offer.
createThemeStore({ themes })takes the list, so the bundle carries only those; the first is the default for a new user. - Paint before the first frame.
themePaintGuardScript({ storageKey })in an inline<script>in<head>paints the saved theme before the bundle loads, so a reload in a dark theme never flashes white. - Give a terminal its own slot with
terminalThemeswhen the app shows terminal output, so someone who likes a light UI can keep a dark terminal.
Themes belong to styles#
A theme lists the styles it is drawn for, as the table above has them, and the menu shows only the active style's themes. A custom theme belongs to the styles of the theme it starts from, and one made from scratch to the style it was made under. Styles says what a style draws, and how an app offers more than one.
What the app does not do#
Draw every colour from a token, and read useTheme() or useTerminalTheme() when a script needs
the colours, such as a canvas or xterm.js. Both re-render when the pick changes.
Style by theme id with [data-theme="dracula"], or read a colour from CSS once and keep it. The
first breaks in every theme you did not test; the second keeps the old colour after a switch.
Both bars are drawn on a canvas, the way a chart or xterm.js draws. Pick another theme or terminal theme above: the first redraws in it, and the second keeps the colours it read when the page loaded.
- No fixed theme for a screen. A dark-only editor or a light-only print view takes the choice away in the place the user spends the most time.
- No
dark:for colour. A token already flips with the mode. Keepdark:for what a token cannot say, such as swapping a screenshot for its dark twin, and know that it sees only light and dark, not which theme. - No brand override of the palette. The store's rule has plain
:rootspecificity, so a later stylesheet can retune a token for every theme. Do that only to fix a token, and check it in every theme the app offers, because it now applies to all of them.
A part of the page in a look of its own#
A part that shows a look other than the user's, a theme's preview, a window in a tour or a wall
of demos each in a theme, gets a theme store of its own, on a wrapper element.
createThemeStore({ root, themes, styles, persistPref: false }) paints that element alone, and
everything inside it is drawn in the store's theme and style whatever the page wears: its tokens,
its dark: classes and its style's look, and a window nested inside takes its own store's in turn.
The wrapper is drawn as the page is, its background, text and font from its own theme, and a menu or
a dialog opened inside it wears its look too, though it opens over the whole page. Build the box
inside the wrapper, from a Pane or a Frame: classes on the wrapper itself answer to the page
around it.
Keep the user's own look on everything they work in. A look of its own is for showing a look, not for choosing one on the user's behalf.
Wrap the part in an element, give that element its own store and a ThemeProvider over it, and
set the look with the store's setPref.
Put .dark, data-style or a palette's tokens on an element by hand. Its tokens, its dark:
classes and the menus opened from it then each follow a different look.
A surface on someone else's page#
A widget or an extension that draws inside another site's page imports @orz/ui/theme.css rather
than styles.css, so it brings the tokens without restyling the host, and creates its store with
root set to its own element: the store then paints that element alone, two stores on one page
never repaint each other, and the host's own .dark stops at the widget's edge.
On each platform#
- Pointer. The menu sits in the top bar, at the trailing edge, as on this site.
- Touch. Auto is the default mode, so a phone that switches to dark at sunset takes the app with it. Use AMOLED makes the dark background true black, which an OLED phone shows by turning those pixels off.