frontend: remove the stylix overlay and add hyperhive and Catppuccin light and dark themes
This commit is contained in:
parent
989d1d578c
commit
91e2d26133
6 changed files with 486 additions and 413 deletions
|
|
@ -53,6 +53,7 @@
|
|||
"./icons.js": "./src/icons.tsx",
|
||||
"./settings-storage.js": "./src/settings/settings-storage.ts",
|
||||
"./theme-apply.js": "./src/settings/theme-apply.ts",
|
||||
"./themes.js": "./src/settings/themes.ts",
|
||||
"./motion-apply.js": "./src/settings/motion-apply.ts",
|
||||
"./settings-menu.js": "./src/settings/SettingsMenu.tsx",
|
||||
"./hide-debug-setting.js": "./src/settings/HideDebugSetting.tsx",
|
||||
|
|
|
|||
|
|
@ -77,11 +77,11 @@
|
|||
/* Fixes badge with emoji having different size. */
|
||||
line-height: 1;
|
||||
}
|
||||
/* Blended with `--fg`, not the raw accent — a stylix-fed scheme can pick
|
||||
/* Blended with `--fg`, not the raw accent — a theme can pick
|
||||
any hue/lightness for `--green`/`--amber`/etc., and nothing guarantees
|
||||
an arbitrary accent clears 4.5:1 against `--purple-dim` the way the two
|
||||
bundled palettes were hand-tuned to (see colors.css's comment above
|
||||
`--latte-base08..0F`). `--fg` is the one color the base16 contract
|
||||
an arbitrary accent clears 4.5:1 against `--purple-dim` the way the
|
||||
hyperhive palettes were hand-tuned to (see colors.css's comment above
|
||||
`--hh-light-base08..0F`). `--fg` is the one color the base16 contract
|
||||
already guarantees is legible on every surface in the theme, so mixing
|
||||
toward it gives every accent a contrast floor without trying to
|
||||
compute/fix an operator's own theme (mara, on the low-contrast-badges
|
||||
|
|
|
|||
|
|
@ -1,25 +1,83 @@
|
|||
/* base16 palette — THE THEME CONTRACT.
|
||||
|
||||
These 16 slots are the entire swap interface. A theme generator (e.g.
|
||||
one fed a stylix base16 scheme, which is natively base00–base0F)
|
||||
overrides *only this file*; `theme.css` derives every semantic var
|
||||
(`--bg`, `--purple`, …) from these slots, so the whole UI re-themes
|
||||
with nothing else to regenerate.
|
||||
These 16 slots are the entire palette interface: `theme.css` derives every
|
||||
semantic var (`--bg`, `--purple`, …) from them, so a theme is 16 colours and
|
||||
nothing else to write. See docs/4-implementation/web-ui/css-vars.md.
|
||||
|
||||
Kept as its own standalone stylesheet (not @import-ed into theme.css)
|
||||
so a swap replaces just this file — `theme.css` and the page bundles
|
||||
stay untouched. Every page links this BEFORE `theme.css`. See
|
||||
docs/4-implementation/web-ui/css-vars.md.
|
||||
Kept as its own standalone stylesheet (not @import-ed into theme.css). Every
|
||||
page links this BEFORE `theme.css`.
|
||||
|
||||
Two raw palettes, one declaration each — `--mocha-baseNN` (dark,
|
||||
Catppuccin Mocha) and `--latte-baseNN` (light, Catppuccin-Latte-
|
||||
derived; base08-0F are darkened from stock Latte, see the comment
|
||||
above those declarations for why). The four blocks below this one
|
||||
never restate a hex value — each just points the active `--baseNN`
|
||||
slot at one of these two raw palettes via `var()`, so "which theme is
|
||||
active" and "what a theme's colours are" can't drift apart the way a
|
||||
hand-duplicated copy could. */
|
||||
Five themes, each light or dark, declared once as raw `--<theme>-baseNN`
|
||||
palettes: `hh-light` and `hh-dark` (the hyperhive themes: Catppuccin's
|
||||
neutrals with the hyperhive accents), `latte` and `mocha` (Catppuccin
|
||||
Latte and Mocha as published, mauve accent), and `mara` (Mocha with the
|
||||
accents mara picked). The blocks below the palettes
|
||||
never restate a hex value: each points the active `--baseNN` slots at one
|
||||
raw palette via `var()`, so "which theme is active" and "what a theme's
|
||||
colours are" can't drift apart. The registry of theme ids and labels is
|
||||
`settings/themes.ts`; `data-theme` on <html> (set by `settings/theme-apply.ts`)
|
||||
names the active one. With none set, hyperhive dark applies, and hyperhive
|
||||
light under a light OS preference ("auto"). */
|
||||
:root {
|
||||
--hh-light-base00: #eff1f5; /* default bg */
|
||||
--hh-light-base01: #e6e9ef; /* lighter bg (elevated surfaces) */
|
||||
--hh-light-base02: #ccd0da; /* selection / surface — borders */
|
||||
--hh-light-base03: #bcc0cc; /* comments / dim surface */
|
||||
--hh-light-base04: #acb0be; /* dark foreground */
|
||||
--hh-light-base05: #4c4f69; /* default foreground */
|
||||
--hh-light-base06: #dc8a78; /* light foreground */
|
||||
--hh-light-base07: #7287fd; /* lightest */
|
||||
--hh-light-base08: #9c0b2a; /* red */
|
||||
--hh-light-base09: #883201; /* orange / peach */
|
||||
--hh-light-base0A: #6d450e; /* yellow */
|
||||
--hh-light-base0B: #235818; /* green */
|
||||
--hh-light-base0C: #025374; /* cyan */
|
||||
--hh-light-base0D: #0843b8; /* blue */
|
||||
--hh-light-base0E: #6311ce; /* magenta / mauve */
|
||||
--hh-light-base0F: #8f166e; /* extra accent — pink */
|
||||
/* base08-0F: darkened from stock Catppuccin Latte's accents (same hue and
|
||||
saturation, lower HSL lightness). The stock ones fail as badge text on
|
||||
base03 (1.4:1 to 3:1, need 4.5:1) and as plain text on base00 (2.3:1 to
|
||||
4.8:1): Latte's accents are tuned for its near-white base, not a mid-gray
|
||||
surface. `latte` below keeps the stock hexes. */
|
||||
|
||||
--hh-dark-base00: #1e1e2e; /* default bg */
|
||||
--hh-dark-base01: #181825; /* lighter bg (elevated surfaces) */
|
||||
--hh-dark-base02: #313244; /* selection / surface — borders */
|
||||
--hh-dark-base03: #45475a; /* comments / dim surface */
|
||||
--hh-dark-base04: #585b70; /* dark foreground */
|
||||
--hh-dark-base05: #cdd6f4; /* default foreground */
|
||||
--hh-dark-base06: #f5e0dc; /* light foreground */
|
||||
--hh-dark-base07: #b4befe; /* lightest */
|
||||
--hh-dark-base08: #f89db1; /* red */
|
||||
--hh-dark-base09: #fe9f6a; /* orange / peach */
|
||||
--hh-dark-base0A: #e9ab56; /* yellow */
|
||||
--hh-dark-base0B: #61ce4b; /* green */
|
||||
--hh-dark-base0C: #39c3fc; /* cyan */
|
||||
--hh-dark-base0D: #96b8fa; /* blue */
|
||||
--hh-dark-base0E: #cba8f8; /* magenta / mauve */
|
||||
--hh-dark-base0F: #f09cd9; /* extra accent — pink */
|
||||
/* hh-dark's base00-07 are Mocha's. base08-0F keep the hue and saturation of
|
||||
hh-light's accents at the HSL lightness where each reaches a 6.2:1 contrast
|
||||
against base02, about what Mocha's own accents have. */
|
||||
|
||||
--latte-base00: #eff1f5; /* default bg */
|
||||
--latte-base01: #e6e9ef; /* lighter bg (elevated surfaces) */
|
||||
--latte-base02: #ccd0da; /* selection / surface — borders */
|
||||
--latte-base03: #bcc0cc; /* comments / dim surface */
|
||||
--latte-base04: #acb0be; /* dark foreground */
|
||||
--latte-base05: #4c4f69; /* default foreground */
|
||||
--latte-base06: #dc8a78; /* light foreground */
|
||||
--latte-base07: #7287fd; /* lightest */
|
||||
--latte-base08: #d20f39; /* red */
|
||||
--latte-base09: #fe640b; /* orange / peach */
|
||||
--latte-base0A: #df8e1d; /* yellow */
|
||||
--latte-base0B: #40a02b; /* green */
|
||||
--latte-base0C: #04a5e5; /* cyan */
|
||||
--latte-base0D: #1e66f5; /* blue */
|
||||
--latte-base0E: #8839ef; /* magenta / mauve */
|
||||
--latte-base0F: #ea76cb; /* extra accent — pink */
|
||||
|
||||
--mocha-base00: #1e1e2e; /* default bg */
|
||||
--mocha-base01: #181825; /* lighter bg (elevated surfaces) */
|
||||
--mocha-base02: #313244; /* selection / surface — borders */
|
||||
|
|
@ -32,128 +90,118 @@
|
|||
--mocha-base09: #fab387; /* orange / peach */
|
||||
--mocha-base0A: #f9e2af; /* yellow */
|
||||
--mocha-base0B: #a6e3a1; /* green */
|
||||
--mocha-base0C: #89dceb; /* cyan (our sky — note: Catppuccin's base0C is teal) */
|
||||
--mocha-base0C: #89dceb; /* cyan */
|
||||
--mocha-base0D: #89b4fa; /* blue */
|
||||
--mocha-base0E: #cba6f7; /* magenta / mauve */
|
||||
--mocha-base0F: #f5c2e7; /* extra accent — pink */
|
||||
|
||||
--latte-base00: #eff1f5; /* default bg */
|
||||
--latte-base01: #e6e9ef; /* lighter bg (elevated surfaces) */
|
||||
--latte-base02: #ccd0da; /* selection / surface — borders */
|
||||
--latte-base03: #bcc0cc; /* comments / dim surface */
|
||||
--latte-base04: #acb0be; /* dark foreground */
|
||||
--latte-base05: #4c4f69; /* default foreground */
|
||||
--latte-base06: #dc8a78; /* light foreground */
|
||||
--latte-base07: #7287fd; /* lightest */
|
||||
/* base08-0F: darkened from stock Catppuccin Latte's own accent hexes
|
||||
(same hue/saturation, lower HSL lightness), not a literal upstream
|
||||
port like base00-07 above. A review round computed real WCAG
|
||||
contrast ratios and found the literal Latte accents fail badly as
|
||||
`Badge`/chip fill-text (green/amber/red/yellow on
|
||||
`--purple-dim`/base03: 1.4:1-3:1, need 4.5:1) and even as plain
|
||||
text on `--bg`/base00 in the agent/dashboard packages that also
|
||||
consume this same file (2.3:1-4.8:1). Root cause: Latte's own
|
||||
accent colors are calibrated against Latte's near-white
|
||||
`base`/`crust`, not against a mid-gray `surface1` — the Mocha
|
||||
palette doesn't have this problem because Mocha's pastel accents
|
||||
are already *light*, so they contrast fine against a *dark*
|
||||
surface1; Latte's saturated-but-mid-brightness accents don't have
|
||||
the equivalent headroom against Latte's own (much lighter)
|
||||
surface1. Each value below was picked by holding the stock Latte
|
||||
hue+saturation fixed and binary-searching HSL lightness down to
|
||||
the point real contrast against base03 clears 4.5:1 with a small
|
||||
margin (also verified against base00: all land above 7:1 there) —
|
||||
same hue identity, same base16 role, just dark/saturated enough to
|
||||
actually be legible as filled-chip or plain text either way.
|
||||
Yellow and peach read closer to olive/brown than a bright
|
||||
yellow/orange once darkened this far — an inherent property of
|
||||
darkening a warm hue in sRGB (Bezold-Brücke shift), not a mapping
|
||||
mistake; boosting saturation further didn't rescue it (verified). */
|
||||
--latte-base08: #9c0b2a; /* red */
|
||||
--latte-base09: #883201; /* orange / peach */
|
||||
--latte-base0A: #6d450e; /* yellow */
|
||||
--latte-base0B: #235818; /* green */
|
||||
--latte-base0C: #025374; /* cyan (our sky — note: Catppuccin's base0C is teal) */
|
||||
--latte-base0D: #0843b8; /* blue */
|
||||
--latte-base0E: #6311ce; /* magenta / mauve */
|
||||
--latte-base0F: #8f166e; /* extra accent — pink */
|
||||
--mara-base00: #1e1e2e; /* default bg */
|
||||
--mara-base01: #313244; /* lighter bg (elevated surfaces) */
|
||||
--mara-base02: #45475a; /* selection / surface — borders */
|
||||
--mara-base03: #6c7086; /* comments / dim surface */
|
||||
--mara-base04: #a6adc8; /* dark foreground */
|
||||
--mara-base05: #cdd6f4; /* default foreground */
|
||||
--mara-base06: #f5e0dc; /* light foreground */
|
||||
--mara-base07: #b4befe; /* lightest */
|
||||
--mara-base08: #f38ba8; /* red */
|
||||
--mara-base09: #6f9dff; /* orange / peach */
|
||||
--mara-base0A: #d162a4; /* yellow */
|
||||
--mara-base0B: #a8c9ff; /* green */
|
||||
--mara-base0C: #a30262; /* cyan */
|
||||
--mara-base0D: #89b4fa; /* blue */
|
||||
--mara-base0E: #cba6f7; /* magenta / mauve */
|
||||
--mara-base0F: #f2cdcd; /* extra accent — pink */
|
||||
/* mara: Catppuccin Mocha with the accents mara picked (base09-base0C). */
|
||||
}
|
||||
|
||||
/* Default activation: Mocha, unless the media query below or a
|
||||
per-user override (further below) says otherwise. */
|
||||
--base00: var(--mocha-base00);
|
||||
--base01: var(--mocha-base01);
|
||||
--base02: var(--mocha-base02);
|
||||
--base03: var(--mocha-base03);
|
||||
--base04: var(--mocha-base04);
|
||||
--base05: var(--mocha-base05);
|
||||
--base06: var(--mocha-base06);
|
||||
--base07: var(--mocha-base07);
|
||||
--base08: var(--mocha-base08);
|
||||
--base09: var(--mocha-base09);
|
||||
--base0A: var(--mocha-base0A);
|
||||
--base0B: var(--mocha-base0B);
|
||||
--base0C: var(--mocha-base0C);
|
||||
--base0D: var(--mocha-base0D);
|
||||
--base0E: var(--mocha-base0E);
|
||||
--base0F: var(--mocha-base0F);
|
||||
/* The browser's own controls, scrollbars and dialog backdrops follow the
|
||||
palette, so a forced theme does not leave them on the OS's. */
|
||||
/* hyperhive dark: the default, and the dark half of "auto". */
|
||||
:root,
|
||||
:root[data-theme="hyperhive-dark"] {
|
||||
--base00: var(--hh-dark-base00);
|
||||
--base01: var(--hh-dark-base01);
|
||||
--base02: var(--hh-dark-base02);
|
||||
--base03: var(--hh-dark-base03);
|
||||
--base04: var(--hh-dark-base04);
|
||||
--base05: var(--hh-dark-base05);
|
||||
--base06: var(--hh-dark-base06);
|
||||
--base07: var(--hh-dark-base07);
|
||||
--base08: var(--hh-dark-base08);
|
||||
--base09: var(--hh-dark-base09);
|
||||
--base0A: var(--hh-dark-base0A);
|
||||
--base0B: var(--hh-dark-base0B);
|
||||
--base0C: var(--hh-dark-base0C);
|
||||
--base0D: var(--hh-dark-base0D);
|
||||
--base0E: var(--hh-dark-base0E);
|
||||
--base0F: var(--hh-dark-base0F);
|
||||
/* A dark pick over a light OS preference: the media query's shares must not
|
||||
carry over, so a dark palette sets its own, the defaults of theme.css. */
|
||||
--muted-share: 58%;
|
||||
--subtext0-share: 77.7%;
|
||||
--code-bg-share: 58%;
|
||||
--palette-glass-clear: initial;
|
||||
--palette-glass-filter: initial;
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
/* OS/browser-level light-mode default. This is a *default*, not a user
|
||||
preference store: it only applies when nothing more specific has
|
||||
already decided the palette. A stylix-generated colors.css
|
||||
(nix/host-modules/hive-c0re/theme.nix) replaces this entire file
|
||||
wholesale — a fixed, unconditional `:root` block with no media query
|
||||
in it at all — so a stylix-themed deployment is naturally unaffected
|
||||
by, and never fights, this block. Some people need light for
|
||||
low-vision/contrast reasons, others need dark for photosensitivity,
|
||||
so respect the OS/browser signal by default the same way
|
||||
`prefers-reduced-motion` already is elsewhere — rather than always
|
||||
forcing the bundled dark palette on a client with no stylix session
|
||||
of its own (e.g. a phone browser hitting swarm-ui directly). */
|
||||
/* "auto" under a light OS preference. An explicit theme below outranks it:
|
||||
an attribute selector always beats the plain `:root`. */
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
--base00: var(--latte-base00);
|
||||
--base01: var(--latte-base01);
|
||||
--base02: var(--latte-base02);
|
||||
--base03: var(--latte-base03);
|
||||
--base04: var(--latte-base04);
|
||||
--base05: var(--latte-base05);
|
||||
--base06: var(--latte-base06);
|
||||
--base07: var(--latte-base07);
|
||||
--base08: var(--latte-base08);
|
||||
--base09: var(--latte-base09);
|
||||
--base0A: var(--latte-base0A);
|
||||
--base0B: var(--latte-base0B);
|
||||
--base0C: var(--latte-base0C);
|
||||
--base0D: var(--latte-base0D);
|
||||
--base0E: var(--latte-base0E);
|
||||
--base0F: var(--latte-base0F);
|
||||
/* Dimmed text on the light palette: see `--muted-share` in theme.css. */
|
||||
--base00: var(--hh-light-base00);
|
||||
--base01: var(--hh-light-base01);
|
||||
--base02: var(--hh-light-base02);
|
||||
--base03: var(--hh-light-base03);
|
||||
--base04: var(--hh-light-base04);
|
||||
--base05: var(--hh-light-base05);
|
||||
--base06: var(--hh-light-base06);
|
||||
--base07: var(--hh-light-base07);
|
||||
--base08: var(--hh-light-base08);
|
||||
--base09: var(--hh-light-base09);
|
||||
--base0A: var(--hh-light-base0A);
|
||||
--base0B: var(--hh-light-base0B);
|
||||
--base0C: var(--hh-light-base0C);
|
||||
--base0D: var(--hh-light-base0D);
|
||||
--base0E: var(--hh-light-base0E);
|
||||
--base0F: var(--hh-light-base0F);
|
||||
/* Dimmed text on a light palette: see `--muted-share` in theme.css. */
|
||||
--muted-share: 85%;
|
||||
--subtext0-share: 93%;
|
||||
--code-bg-share: 95%;
|
||||
/* No frosted glass on the light palette: see `--glass-clear` in theme.css. */
|
||||
/* No frosted glass on a light palette: see `--glass-clear` in theme.css. */
|
||||
--palette-glass-clear: 0;
|
||||
--palette-glass-filter: none;
|
||||
color-scheme: light;
|
||||
}
|
||||
}
|
||||
|
||||
/* Per-user override (`SettingsMenu` and `settings/theme-apply.ts`
|
||||
set `data-theme` on `<html>`; unset/`"system"` removes the
|
||||
attribute and lets the media query above decide, same as before this
|
||||
existed). `:root[data-theme='light']` has higher specificity than
|
||||
the plain `:root` inside the media query above (an attribute
|
||||
selector always outranks none), so this wins regardless of the
|
||||
actual OS preference or source order — no `!important`, no inline
|
||||
style, and critically no second copy of either palette's hex values:
|
||||
both blocks below just re-point at the same `--mocha-baseNN` /
|
||||
`--latte-baseNN` custom properties declared once at the top of this
|
||||
file. */
|
||||
:root[data-theme="light"] {
|
||||
:root[data-theme="hyperhive-light"] {
|
||||
--base00: var(--hh-light-base00);
|
||||
--base01: var(--hh-light-base01);
|
||||
--base02: var(--hh-light-base02);
|
||||
--base03: var(--hh-light-base03);
|
||||
--base04: var(--hh-light-base04);
|
||||
--base05: var(--hh-light-base05);
|
||||
--base06: var(--hh-light-base06);
|
||||
--base07: var(--hh-light-base07);
|
||||
--base08: var(--hh-light-base08);
|
||||
--base09: var(--hh-light-base09);
|
||||
--base0A: var(--hh-light-base0A);
|
||||
--base0B: var(--hh-light-base0B);
|
||||
--base0C: var(--hh-light-base0C);
|
||||
--base0D: var(--hh-light-base0D);
|
||||
--base0E: var(--hh-light-base0E);
|
||||
--base0F: var(--hh-light-base0F);
|
||||
/* Dimmed text on a light palette: see `--muted-share` in theme.css. */
|
||||
--muted-share: 85%;
|
||||
--subtext0-share: 93%;
|
||||
--code-bg-share: 95%;
|
||||
/* No frosted glass on a light palette: see `--glass-clear` in theme.css. */
|
||||
--palette-glass-clear: 0;
|
||||
--palette-glass-filter: none;
|
||||
color-scheme: light;
|
||||
}
|
||||
|
||||
:root[data-theme="catppuccin-latte-mauve"] {
|
||||
--base00: var(--latte-base00);
|
||||
--base01: var(--latte-base01);
|
||||
--base02: var(--latte-base02);
|
||||
|
|
@ -170,15 +218,17 @@
|
|||
--base0D: var(--latte-base0D);
|
||||
--base0E: var(--latte-base0E);
|
||||
--base0F: var(--latte-base0F);
|
||||
/* Dimmed text on the light palette: see `--muted-share` in theme.css. */
|
||||
/* Dimmed text on a light palette: see `--muted-share` in theme.css. */
|
||||
--muted-share: 85%;
|
||||
--subtext0-share: 93%;
|
||||
--code-bg-share: 95%;
|
||||
/* No frosted glass on a light palette: see `--glass-clear` in theme.css. */
|
||||
--palette-glass-clear: 0;
|
||||
--palette-glass-filter: none;
|
||||
color-scheme: light;
|
||||
}
|
||||
:root[data-theme="dark"] {
|
||||
|
||||
:root[data-theme="catppuccin-mocha-mauve"] {
|
||||
--base00: var(--mocha-base00);
|
||||
--base01: var(--mocha-base01);
|
||||
--base02: var(--mocha-base02);
|
||||
|
|
@ -196,7 +246,34 @@
|
|||
--base0E: var(--mocha-base0E);
|
||||
--base0F: var(--mocha-base0F);
|
||||
/* A dark pick over a light OS preference: the media query's shares must not
|
||||
carry over, so the dark palette sets its own, the defaults of theme.css. */
|
||||
carry over, so a dark palette sets its own, the defaults of theme.css. */
|
||||
--muted-share: 58%;
|
||||
--subtext0-share: 77.7%;
|
||||
--code-bg-share: 58%;
|
||||
--palette-glass-clear: initial;
|
||||
--palette-glass-filter: initial;
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
:root[data-theme="catppuccin-mocha-mara"] {
|
||||
--base00: var(--mara-base00);
|
||||
--base01: var(--mara-base01);
|
||||
--base02: var(--mara-base02);
|
||||
--base03: var(--mara-base03);
|
||||
--base04: var(--mara-base04);
|
||||
--base05: var(--mara-base05);
|
||||
--base06: var(--mara-base06);
|
||||
--base07: var(--mara-base07);
|
||||
--base08: var(--mara-base08);
|
||||
--base09: var(--mara-base09);
|
||||
--base0A: var(--mara-base0A);
|
||||
--base0B: var(--mara-base0B);
|
||||
--base0C: var(--mara-base0C);
|
||||
--base0D: var(--mara-base0D);
|
||||
--base0E: var(--mara-base0E);
|
||||
--base0F: var(--mara-base0F);
|
||||
/* A dark pick over a light OS preference: the media query's shares must not
|
||||
carry over, so a dark palette sets its own, the defaults of theme.css. */
|
||||
--muted-share: 58%;
|
||||
--subtext0-share: 77.7%;
|
||||
--code-bg-share: 58%;
|
||||
|
|
|
|||
|
|
@ -28,11 +28,15 @@ import type { ComponentChildren } from "preact";
|
|||
import { IconButton } from "../icon-button/IconButton.js";
|
||||
import { GearIcon } from "../icons.js";
|
||||
import { useDismiss } from "../use-dismiss.js";
|
||||
import { useThemeOverride, type ThemeOverride } from "./theme-apply.js";
|
||||
import { useThemeOverride } from "./theme-apply.js";
|
||||
import { AUTO_THEME, THEMES } from "./themes.js";
|
||||
import { useMotionOverride, type MotionOverride } from "./motion-apply.js";
|
||||
import "./SettingsMenu.css";
|
||||
|
||||
const THEME_OPTIONS: ThemeOverride[] = ["system", "light", "dark"];
|
||||
const THEME_OPTIONS = [
|
||||
{ id: AUTO_THEME, label: "auto" },
|
||||
...THEMES.map((t) => ({ id: t.id, label: t.label })),
|
||||
];
|
||||
const MOTION_OPTIONS: MotionOverride[] = ["system", "allow", "reduce"];
|
||||
|
||||
export interface SettingsMenuProps {
|
||||
|
|
@ -85,13 +89,11 @@ export function SettingsMenu({
|
|||
<span>theme</span>
|
||||
<select
|
||||
value={theme}
|
||||
onChange={(e) =>
|
||||
setTheme((e.target as HTMLSelectElement).value as ThemeOverride)
|
||||
}
|
||||
onChange={(e) => setTheme((e.target as HTMLSelectElement).value)}
|
||||
>
|
||||
{THEME_OPTIONS.map((o) => (
|
||||
<option key={o} value={o}>
|
||||
{o}
|
||||
<option key={o.id} value={o.id}>
|
||||
{o.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
|
|
|||
|
|
@ -1,46 +1,46 @@
|
|||
// Applies a stored theme override by setting `data-theme="light"|"dark"`
|
||||
// on `<html>`, cleared when the override is "system" (letting the
|
||||
// `prefers-color-scheme` media query in `./colors.css` resume control).
|
||||
// No palette values live here — `colors.css`'s own
|
||||
// `:root[data-theme='light']` / `:root[data-theme='dark']` blocks are
|
||||
// what actually apply the colours.
|
||||
// Applies the stored theme choice by setting `data-theme="<theme id>"` on
|
||||
// `<html>`, cleared for `auto` (so the `prefers-color-scheme` media query in
|
||||
// `../colors.css` picks hyperhive light or dark). No palette values live
|
||||
// here: `colors.css`'s `:root[data-theme="<id>"]` blocks apply the colours,
|
||||
// and `./themes.ts` lists the ids.
|
||||
//
|
||||
// Callers own their own storage key (kept in their own small constant,
|
||||
// not derived here) so two pages never silently share one browser-local
|
||||
// setting by accident. `fallback` defaults to `'dark'`: `prefers-color-
|
||||
// scheme` has no real "unset" value the way `prefers-reduced-motion`
|
||||
// does, so a browser with no explicit dark-mode toggle reports `light`
|
||||
// — `'system'` as a default silently reads as light-by-default for most
|
||||
// first-time visitors (mara: "light mode seems to be default"). Still
|
||||
// fully overridable per caller if a page ever wants a different default.
|
||||
// Callers own their own storage key (kept in their own small constant, not
|
||||
// derived here) so two pages never silently share one browser-local setting
|
||||
// by accident. The stored value is read through `themeChoice`, so a value
|
||||
// from before themes existed (`system`, `light`, `dark`) still works. The
|
||||
// default is hyperhive dark: `prefers-color-scheme` has no real "unset" value
|
||||
// the way `prefers-reduced-motion` does, so a browser with no explicit
|
||||
// dark-mode toggle reports `light`, and `auto` as a default read as
|
||||
// light-by-default for most first-time visitors (mara: "light mode seems to be
|
||||
// default").
|
||||
import { useEffect } from "preact/hooks";
|
||||
import { useLocalSetting } from "./settings-storage.js";
|
||||
import { AUTO_THEME, DEFAULT_THEME, themeChoice } from "./themes.js";
|
||||
|
||||
export type ThemeOverride = "system" | "light" | "dark";
|
||||
|
||||
/** `[choice, setChoice]`: `auto` or a theme id from `./themes.ts`. */
|
||||
export function useThemeOverride(
|
||||
key: string,
|
||||
fallback: ThemeOverride = "dark",
|
||||
) {
|
||||
return useLocalSetting<ThemeOverride>(key, fallback);
|
||||
fallback: string = DEFAULT_THEME,
|
||||
): [string, (choice: string) => void] {
|
||||
const [stored, setStored] = useLocalSetting<string>(key, fallback);
|
||||
return [themeChoice(stored, fallback), setStored];
|
||||
}
|
||||
|
||||
// Mounted once, high in the tree — one mount point applies the override
|
||||
// regardless of what else is rendering, and `useLocalSetting`'s
|
||||
// same-tab subscription means `SettingsMenu` changing the value re-runs
|
||||
// this effect without either component needing to know about the other
|
||||
// directly.
|
||||
// Mounted once, high in the tree — one mount point applies the choice
|
||||
// regardless of what else is rendering, and `useLocalSetting`'s same-tab
|
||||
// subscription means `SettingsMenu` changing the value re-runs this effect
|
||||
// without either component needing to know about the other directly.
|
||||
export function useApplyThemeOverride(
|
||||
key: string,
|
||||
fallback: ThemeOverride = "dark",
|
||||
fallback: string = DEFAULT_THEME,
|
||||
): void {
|
||||
const [override] = useThemeOverride(key, fallback);
|
||||
const [choice] = useThemeOverride(key, fallback);
|
||||
useEffect(() => {
|
||||
const root = document.documentElement;
|
||||
if (override === "system") {
|
||||
if (choice === AUTO_THEME) {
|
||||
delete root.dataset.theme;
|
||||
} else {
|
||||
root.dataset.theme = override;
|
||||
root.dataset.theme = choice;
|
||||
}
|
||||
}, [override]);
|
||||
}, [choice]);
|
||||
}
|
||||
|
|
|
|||
54
frontend/packages/shared/src/settings/themes.ts
Normal file
54
frontend/packages/shared/src/settings/themes.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
// The themes a user can pick, apart from how they are applied. The palettes are
|
||||
// in `../colors.css`, one `:root[data-theme="<id>"]` block per id here; a new
|
||||
// theme is one entry here and one palette there. Each theme is light or dark.
|
||||
// `auto` is not a theme: it leaves `data-theme` off, and the OS preference
|
||||
// picks hyperhive light or hyperhive dark.
|
||||
|
||||
export type ThemeScheme = "light" | "dark";
|
||||
|
||||
export interface ThemeDef {
|
||||
id: string;
|
||||
label: string;
|
||||
scheme: ThemeScheme;
|
||||
}
|
||||
|
||||
export const THEMES: readonly ThemeDef[] = [
|
||||
{ id: "hyperhive-light", label: "hyperhive light", scheme: "light" },
|
||||
{ id: "hyperhive-dark", label: "hyperhive dark", scheme: "dark" },
|
||||
{
|
||||
id: "catppuccin-latte-mauve",
|
||||
label: "catppuccin latte mauve",
|
||||
scheme: "light",
|
||||
},
|
||||
{
|
||||
id: "catppuccin-mocha-mauve",
|
||||
label: "catppuccin mocha mauve",
|
||||
scheme: "dark",
|
||||
},
|
||||
{
|
||||
id: "catppuccin-mocha-mara",
|
||||
label: "catppuccin mocha mara",
|
||||
scheme: "dark",
|
||||
},
|
||||
];
|
||||
|
||||
/** The stored choice that follows the OS preference. */
|
||||
export const AUTO_THEME = "auto";
|
||||
|
||||
/** What a page uses until the user has picked. */
|
||||
export const DEFAULT_THEME = "hyperhive-dark";
|
||||
|
||||
/**
|
||||
* The choice a stored value stands for. The values from before themes existed
|
||||
* map to their successors (`system` to `auto`, `light` and `dark` to the
|
||||
* hyperhive themes); anything unknown is `fallback`.
|
||||
*/
|
||||
export function themeChoice(
|
||||
stored: unknown,
|
||||
fallback: string = DEFAULT_THEME,
|
||||
): string {
|
||||
if (stored === AUTO_THEME || stored === "system") return AUTO_THEME;
|
||||
if (stored === "light") return "hyperhive-light";
|
||||
if (stored === "dark") return "hyperhive-dark";
|
||||
return THEMES.some((t) => t.id === stored) ? (stored as string) : fallback;
|
||||
}
|
||||
Loading…
Reference in a new issue