ui: media filtering is a per-theme setting, not a night-mode hardcode
Some checks are pending
Controller Tests / controller-tests (push) Waiting to run
Jest Tests / jest-tests (push) Waiting to run

Filtering media was keyed on `data-theme="night"`, which made it a property of
the theme that no user could turn off.  Some people want their media tinted to
match the interface; some want to see the actual image.

A theme now declares a filter and whether it starts on, and the user decides:

  night   night-red    on by default.  An unfiltered thumbnail undoes dark
                       adaptation, which is the whole point of the mode.
  amber   amber-mono   off by default.  Amber is a look, not a night-vision
                       aid, so media keeps its real colors until asked for.
  light   -            no filter offered, so no toggle is shown.
  dark    -

The choice is stored per theme, so wanting amber's tint says nothing about
wanting night's.  The toggle lives in the theme picker, which puts it on the
Settings page and in the gallery at once.

Mechanically the rules now key on a `data-media-filter` attribute rather than
`data-theme`: a rule keyed on the theme could not be turned off.  index.html
stamps that attribute before first paint alongside data-theme -- without it,
night mode paints a screen of unfiltered thumbnails while the bundle arrives
over a hotspot, costing the user the adaptation the theme exists to protect.
Tests cover both the attribute rule and the fact that the inline script's
duplicated ids and defaults still agree with names.ts.

The amber matrix is the same luminance collapse tinted to #ff9500 (red full,
green 0.584, blue zero) with a gentler gamma than night's: amber carries far
more luminance and clips to a flat wash otherwise.

The gallery gains a Media filtering section showing the WROLPi logo filtered,
beside an unfiltered copy that opts out with `night-unfiltered`.  That copy is
behind a click on purpose -- an unfiltered image is a bright patch, and night
mode should not spring one on someone reading in the dark.

ui-design.md gains the media filtering contract it never got in Phase 0,
including the note that a Phase 3 custom theme names an existing filter id and
cannot ship its own matrix, since that would be code rather than data.
This commit is contained in:
Roland 2026-07-30 08:51:28 -06:00 • committed by lrnselfreliance
parent 973a61af28
commit efe84d17f1
13 changed files with 546 additions and 39 deletions

View file

@ -2,6 +2,7 @@ import React, {useContext} from 'react';
import {ThemeContext} from '../../contexts/contexts';
import {systemTheme, themeChoices} from '../../themes/names';
import {Icon} from './Icon';
import {Toggle} from './Inputs';
/*
* The theme picker.
@ -15,29 +16,52 @@ export interface ThemePickerProps {
withDescriptions?: boolean;
}
/**
* The media filter toggle for the current theme.
*
* Rendered only by themes that offer a filter, because there is nothing to say
* about it otherwise — light and dark have no monochrome media treatment.
*/
export function MediaFilterToggle() {
const {mediaFilter, mediaFilterEnabled, setMediaFilterEnabled} = useContext(ThemeContext);
if (!mediaFilter) return null;
return <div className='wrolpi-media-filter-setting'>
<Toggle
label={mediaFilter.label}
description={mediaFilter.description}
checked={mediaFilterEnabled}
onChange={event => setMediaFilterEnabled(event.currentTarget.checked)}
/>
</div>
}
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>
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>
<MediaFilterToggle/>
</>
}

View file

@ -110,6 +110,13 @@ html[data-theme="amber"] .wrolpi-theme-option-active {
line-height: 1.4;
}
/* Separated from the theme grid: it configures the chosen theme, it is not a choice. */
.wrolpi-media-filter-setting {
margin-top: 14px;
padding-top: 12px;
border-top: 1px solid var(--border);
}
/* ---------------------------------------------------------------- Modals */
/*
* Actions sit below the body, separated by a hairline rather than a raised bar.

View file

@ -322,7 +322,13 @@ describe('Toggle', () => {
describe('ThemePicker', () => {
const renderPicker = (themeContext = {}) => {
const setTheme = jest.fn();
const value = {savedTheme: null, setTheme, ...themeContext};
const value = {
savedTheme: null,
setTheme,
mediaFilterEnabled: false,
setMediaFilterEnabled: jest.fn(),
...themeContext,
};
render(
<MantineProvider theme={mantineTheme} cssVariablesResolver={cssVariablesResolver}>
<ThemeContext.Provider value={value}><ThemePicker/></ThemeContext.Provider>
@ -368,6 +374,39 @@ describe('ThemePicker', () => {
expect(screen.getByText(/night vision/i)).toBeInTheDocument();
});
it('offers the media filter toggle in a theme that has one', () => {
renderPicker({
theme: 'night',
mediaFilter: {id: 'night-red', defaultOn: true, label: 'Filter media to red',
description: 'Videos, images, documents, and maps are remapped to red.'},
mediaFilterEnabled: true,
});
expect(screen.getByRole('switch', {name: /filter media to red/i})).toBeChecked();
});
it('offers no toggle in a theme with no filter to offer', () => {
// Light and dark have no monochrome media treatment, so there is nothing to say.
renderPicker({theme: 'light', mediaFilter: undefined, mediaFilterEnabled: false});
expect(screen.queryByRole('switch')).not.toBeInTheDocument();
});
it('turns the filter off when the user flips the toggle', async () => {
const setMediaFilterEnabled = jest.fn();
renderPicker({
theme: 'night',
mediaFilter: {id: 'night-red', defaultOn: true, label: 'Filter media to red',
description: 'Videos, images, documents, and maps are remapped to red.'},
mediaFilterEnabled: true,
setMediaFilterEnabled,
});
await userEvent.click(screen.getByRole('switch', {name: /filter media to red/i}));
expect(setMediaFilterEnabled).toHaveBeenCalledWith(false);
});
});
describe('Confirm', () => {