ui: theme picker in Settings, and ship the component gallery

The gallery at /theme-sample is now a normal route rather than a development
one, and Settings links to it, so a user can see what a theme actually looks
like before committing to it. Every new component belongs in the gallery: it is
how the design gets reviewed, and how a component that only looks wrong in one
of the four themes gets caught.

Settings gains a Theme section with the new ThemePicker, which explains what
each theme is for - notably that night mode filters videos, documents and maps
to red as well, not just the interface.

Theme names and picker options move to themes/names.ts so the component library
can read them without importing components/Theme.tsx, which still pulls in
Semantic UI. Theme.tsx re-exports them, so existing call sites are unchanged.
The navigation bar's compact picker now reads the same list, so the two cannot
drift apart.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Roland 2026-07-29 19:38:04 -06:00
parent 1bf8ea3da8
commit ea50ee2f16
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
10 changed files with 290 additions and 52 deletions

View file

@ -0,0 +1,43 @@
import React, {useContext} from 'react';
import {ThemeContext} from '../../contexts/contexts';
import {systemTheme, themeChoices} from '../../themes/names';
import {Icon} from './Icon';
/*
* The theme picker.
*
* Used on the Settings page. The navigation bar has its own compact menu; both
* read their options from `themeChoices` so they cannot drift apart.
*/
export interface ThemePickerProps {
/** Show each theme's description under its name. */
withDescriptions?: boolean;
}
export function ThemePicker({withDescriptions = true}: ThemePickerProps) {
const {savedTheme, setTheme} = useContext(ThemeContext);
// A user who has never chosen is following the system preference.
const selected = savedTheme ?? systemTheme;
return <div role='radiogroup' aria-label='Theme' className='wrolpi-theme-picker'>
{themeChoices.map(choice => {
const active = choice.value === selected;
return <button
key={choice.value}
type='button'
role='radio'
aria-checked={active}
className={`wrolpi-theme-option${active ? ' wrolpi-theme-option-active' : ''}`}
onClick={() => setTheme(choice.value)}
>
<span className='wrolpi-theme-option-name'>
<Icon name={choice.icon}/>
{choice.text}
</span>
{withDescriptions &&
<span className='wrolpi-theme-option-description'>{choice.description}</span>}
</button>
})}
</div>
}

View file

@ -18,6 +18,7 @@ export * from './Surfaces';
export * from './DataTable';
export * from './Inputs';
export * from './Overlays';
export * from './ThemePicker';
export * from './toast';
// Layout primitives are used as-is; they carry no colors of their own.

View file

@ -53,6 +53,63 @@ html[data-theme="night"] .wrolpi-button-danger:hover:not(:disabled) {
/* The icon inside inherits currentColor, so it follows without another rule. */
/* ----------------------------------------------------------- Theme picker */
.wrolpi-theme-picker {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
gap: 10px;
}
.wrolpi-theme-option {
display: flex;
flex-direction: column;
gap: 4px;
align-items: flex-start;
text-align: left;
padding: 10px 12px;
background: var(--panel);
color: var(--text);
border: 1px solid var(--border);
font: inherit;
cursor: pointer;
}
.wrolpi-theme-option:hover {
background: var(--head);
}
/* The selected theme is marked by a heavier border as well as color, so the
selection survives in monochrome themes. */
.wrolpi-theme-option-active {
border: 2px solid var(--blue);
padding: 9px 11px;
}
html[data-theme="night"] .wrolpi-theme-option-active,
html[data-theme="amber"] .wrolpi-theme-option-active {
border-color: var(--text);
}
.wrolpi-theme-option:focus-visible {
outline: 2px solid var(--blue);
outline-offset: 1px;
}
.wrolpi-theme-option-name {
display: inline-flex;
align-items: center;
gap: 7px;
font-weight: 600;
font-size: 13px;
}
.wrolpi-theme-option-description {
font-size: 12px;
color: var(--muted);
line-height: 1.4;
}
/* --------------------------------------------------------------- Switches */
/*
* Mantine's unchecked track is a gray from its own palette, which would put a

View file

@ -3,6 +3,7 @@ import {render, screen} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import {MantineProvider} from '@mantine/core';
import {IconMoodSmile} from '@tabler/icons-react';
import {ThemeContext} from '../../contexts/contexts';
import {cssVariablesResolver, mantineTheme, semanticColorNames} from '../../themes/mantine';
import {
Button,
@ -16,6 +17,7 @@ import {
resolveIconName,
Status,
Table,
ThemePicker,
Toggle,
} from './index';
@ -233,6 +235,57 @@ describe('Toggle', () => {
});
});
describe('ThemePicker', () => {
const renderPicker = (themeContext = {}) => {
const setTheme = jest.fn();
const value = {savedTheme: null, setTheme, ...themeContext};
render(
<MantineProvider theme={mantineTheme} cssVariablesResolver={cssVariablesResolver}>
<ThemeContext.Provider value={value}><ThemePicker/></ThemeContext.Provider>
</MantineProvider>
);
return setTheme;
};
it('offers every theme plus following the system', () => {
renderPicker();
const options = screen.getAllByRole('radio').map(o => o.textContent);
['System', 'Light', 'Dark', 'Night', 'Amber'].forEach(name => {
expect(options.some(text => text.startsWith(name))).toBe(true);
});
});
it('marks the saved theme as selected', () => {
renderPicker({savedTheme: 'night'});
const night = screen.getAllByRole('radio').find(o => o.textContent.startsWith('Night'));
expect(night).toHaveAttribute('aria-checked', 'true');
});
it('treats a user who has never chosen as following the system', () => {
renderPicker({savedTheme: null});
const system = screen.getAllByRole('radio').find(o => o.textContent.startsWith('System'));
expect(system).toHaveAttribute('aria-checked', 'true');
});
it('applies the theme a user picks', async () => {
const setTheme = renderPicker();
await userEvent.click(screen.getAllByRole('radio').find(o => o.textContent.startsWith('Amber')));
expect(setTheme).toHaveBeenCalledWith('amber');
});
it('explains what night mode is for', () => {
// Users need to know it filters media too, not just the interface.
renderPicker();
expect(screen.getByText(/night vision/i)).toBeInTheDocument();
});
});
describe('Confirm', () => {
it('names the action on its confirming button', async () => {
const onConfirm = jest.fn();