mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-04 21:59:58 -05:00
ui: theme tokens and a four-theme runtime
Every color now resolves through CSS custom properties on html[data-theme=...], so a theme is a table of values rather than code. Four themes ship: light, dark, night (red hues only, to preserve dark adaptation off-grid) and amber (monochrome amber terminal). Fonts are exposed as two roles, --font-body and --font-mono, which a theme assigns a bundled face to; amber uses the mono face. Faces must be self-hosted, never fetched from a CDN, so the app keeps working offline. Night mode also filters media that cannot consume tokens - video, images, PDFs, embedded pages, canvases - through an SVG color matrix that maps luminance onto the red channel. Tag such an element with `.media`; a filter on an app-level ancestor would create a containing block and break fixed positioning. ThemeProvider persists the choice and index.html stamps data-theme from localStorage before the bundle loads, so the first paint already matches the saved theme on a slow connection. The OS preference is followed only while "system" is selected; night and amber are explicit choices. The nav toggle becomes a five-item picker. Semantic components still render themselves, so only the shell is token-driven for now; the inverted props stay in place until each component is migrated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
616424b223
commit
806727023d
12 changed files with 669 additions and 92 deletions
|
|
@ -9,6 +9,7 @@ import {
|
|||
Container,
|
||||
Dimmer,
|
||||
DimmerDimmable,
|
||||
Dropdown,
|
||||
GridColumn,
|
||||
GridRow,
|
||||
Icon as SIcon,
|
||||
|
|
@ -25,6 +26,7 @@ import {useBluetooth, useDesktop, useHotspot, useSearchDirectories, useSearchOrd
|
|||
import {Media, SettingsContext, StatusContext, ThemeContext} from "../contexts/contexts";
|
||||
import {
|
||||
Accordion,
|
||||
amberTheme,
|
||||
Breadcrumb,
|
||||
Button,
|
||||
Card as ThemedCard,
|
||||
|
|
@ -37,9 +39,11 @@ import {
|
|||
Loader,
|
||||
Menu,
|
||||
Modal,
|
||||
nightTheme,
|
||||
Popup,
|
||||
Segment,
|
||||
Statistic
|
||||
Statistic,
|
||||
systemTheme
|
||||
} from "./Theme";
|
||||
import {FilePreviewContext} from "./FilePreview";
|
||||
import _ from "lodash";
|
||||
|
|
@ -1378,20 +1382,37 @@ export function LoadStatistic({label, value, cores, ...props}) {
|
|||
{...props}/>;
|
||||
}
|
||||
|
||||
export function DarkModeToggle() {
|
||||
const {savedTheme, cycleSavedTheme} = useContext(ThemeContext);
|
||||
let iconName = 'lightbulb outline';
|
||||
if (savedTheme === darkTheme) {
|
||||
iconName = 'moon';
|
||||
} else if (savedTheme === lightTheme) {
|
||||
iconName = 'sun';
|
||||
}
|
||||
// Theme picker entries. `night` and `amber` are only reachable here; neither is ever applied
|
||||
// automatically. See ui-design.md.
|
||||
const themeChoices = [
|
||||
{value: systemTheme, text: 'System', icon: 'lightbulb outline'},
|
||||
{value: lightTheme, text: 'Light', icon: 'sun'},
|
||||
{value: darkTheme, text: 'Dark', icon: 'moon'},
|
||||
{value: nightTheme, text: 'Night', icon: 'eye'},
|
||||
{value: amberTheme, text: 'Amber', icon: 'terminal'},
|
||||
];
|
||||
|
||||
return <Icon
|
||||
name={iconName}
|
||||
onClick={cycleSavedTheme}
|
||||
style={{cursor: 'pointer', marginRight: '0.8em'}}
|
||||
/>
|
||||
export function DarkModeToggle() {
|
||||
const {savedTheme, setTheme} = useContext(ThemeContext);
|
||||
const active = themeChoices.find(i => i.value === savedTheme) || themeChoices[0];
|
||||
|
||||
return <Dropdown
|
||||
item
|
||||
icon={<Icon name={active.icon} style={{margin: 0}}/>}
|
||||
title={`Theme: ${active.text}`}
|
||||
style={{padding: 0, marginRight: '0.8em'}}
|
||||
>
|
||||
<Dropdown.Menu>
|
||||
<Dropdown.Header content='Theme'/>
|
||||
{themeChoices.map(choice => <Dropdown.Item
|
||||
key={choice.value}
|
||||
icon={choice.icon}
|
||||
text={choice.text}
|
||||
active={choice.value === active.value}
|
||||
onClick={() => setTheme(choice.value)}
|
||||
/>)}
|
||||
</Dropdown.Menu>
|
||||
</Dropdown>
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue