mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-29 11:26:25 -05:00
ui: the navbar measures its foreground instead of assuming one
The bar's background is the one surface a user picks -- twelve colour names, which each theme resolves to twelve of its own colours. Forty-eight backgrounds, and the links and status icons were drawn on all of them in a single token, `--btn-text`, which is near-black in three of the four themes. Night's `--brown` is #451212. A near-black glyph on it is 1.33:1. Nine of night's twelve colours and seven of amber's sat below 4.5:1, and twelve of the forty-eight below 3:1 -- icons the same colour as the bar behind them. So the foreground is measured against the background the theme actually resolved, choosing between that theme's own `--btn-text`, `--black` and `--white`. Its own, not literal ones: a white pixel in night mode undoes the dark adaptation the theme exists to protect, so night's "white" is #ff8a8a. Measuring at runtime rather than shipping an `--on-red` token per colour also means the custom YAML themes still ahead get this for free. Nothing is below 3:1 any more and the worst case is 3.27:1, up from 1.33:1. No combination is worse than it was. Ten of the forty-eight are still under 4.5:1 and no foreground will lift them: a monochrome theme resolves all twelve names onto one ramp, and a mid-tone of a hue cannot carry text of that same hue. That shortfall is in the palette, so /theme-sample now draws all twelve bars with the measured ratio printed beside each one, calling out the ten -- it is a decision to make while looking at them. The WCAG primitives move to themes/contrast so theme code can measure a colour without importing Common.js, which pulls in half the component library. Common.js forwards `contrastRatio` with a delegating function rather than a bare re-export: six specs mock it with `{...jest.requireActual('./Common')}`, the spread invokes every getter, and those spreads run re-entrantly while the module is still evaluating -- a re-export getter fires before its import binding exists and takes the whole suite down. Tested: navColors.test.js measures all forty-eight against the palette parsed out of tokens.css, and holds Nav.js to the call by source since neither bar is reachable from a test that could measure it. ui-layout.cy.js measures the painted result in a real browser in all four themes and holds it against the number the component reports. Reverting to the fixed foreground reddens four jest cases and three cypress ones. 1115 jest / 62 suites, 177 in ui-layout.cy.js, clean npm run build.
This commit is contained in:
parent
bbe3cac9a8
commit
bbb267aa83
8 changed files with 690 additions and 66 deletions
|
|
@ -19,6 +19,7 @@ import {useReorganizationStatus} from "../contexts/FileWorkerStatusContext";
|
|||
import {SearchIconButton} from "./Search";
|
||||
import {HELP_VIEWER_URI, NAME, semanticUIColorMap} from "./Vars";
|
||||
import {useOverflowNav} from "../hooks/useOverflowNav";
|
||||
import {defaultNavColor, navBarStyle, useNavColors} from "../themes/navColors";
|
||||
import _ from "lodash";
|
||||
|
||||
function updateFavicon(colorName) {
|
||||
|
|
@ -141,7 +142,7 @@ function NavIconWrapper({children}) {
|
|||
function useNavColorSetting() {
|
||||
// Use localstorage to avoid flickering navbar color on startup.
|
||||
const {settings} = React.useContext(SettingsContext);
|
||||
const [navColor, setNavColor] = useLocalStorage('nav_color', 'violet');
|
||||
const [navColor, setNavColor] = useLocalStorage('nav_color', defaultNavColor);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!_.isEmpty(settings)) {
|
||||
|
|
@ -163,7 +164,12 @@ export function NavBar() {
|
|||
const wrolModeEnabled = useWROLMode();
|
||||
const {status} = React.useContext(StatusContext);
|
||||
const navColor = useNavColorSetting();
|
||||
const wrolpiIcon = <img src='/icon.svg' height='32px' width='32px' alt='WROLPi Home Icon'/>;
|
||||
/*
|
||||
* The bar's foreground is measured against the background the theme resolved for the
|
||||
* user's colour, not taken from a single token. See themes/navColors.
|
||||
*/
|
||||
const navColors = useNavColors(navColor);
|
||||
const wrolpiIcon =<img src='/icon.svg' height='32px' width='32px' alt='WROLPi Home Icon'/>;
|
||||
const name = <i>{NAME || wrolpiIcon}</i>;
|
||||
const topNavText = wrolModeEnabled ? <>{name} <Icon name='lock'/></> : name;
|
||||
|
||||
|
|
@ -362,15 +368,7 @@ export function NavBar() {
|
|||
|
||||
return <>
|
||||
<Media between={['mobile', 'tablet']}>
|
||||
<nav className='wrolpi-navbar' id='global_navbar'
|
||||
style={{
|
||||
background: `var(--${navColor})`,
|
||||
color: 'var(--btn-text)',
|
||||
// The hotspot glyph stacks two icons, and the corner one paints a disc
|
||||
// of its surface behind itself. The bar's colour is the user's choice,
|
||||
// so it has to be handed down rather than looked up from a token.
|
||||
'--icon-stack-bg': `var(--${navColor})`,
|
||||
}}>
|
||||
<nav className='wrolpi-navbar' id='global_navbar' style={navBarStyle(navColors)}>
|
||||
{homeLink}
|
||||
<div className='wrolpi-navbar-right'>
|
||||
{icons}
|
||||
|
|
@ -380,12 +378,12 @@ export function NavBar() {
|
|||
</nav>
|
||||
</Media>
|
||||
<Media greaterThanOrEqual='tablet'>
|
||||
<DesktopNav navColor={navColor} homeLink={homeLink} icons={icons}/>
|
||||
<DesktopNav navColors={navColors} homeLink={homeLink} icons={icons}/>
|
||||
</Media>
|
||||
</>
|
||||
}
|
||||
|
||||
function DesktopNav({navColor, homeLink, icons}) {
|
||||
function DesktopNav({navColors, homeLink, icons}) {
|
||||
const containerRef = React.useRef(null);
|
||||
const homeRef = React.useRef(null);
|
||||
const rightMenuRef = React.useRef(null);
|
||||
|
|
@ -400,15 +398,7 @@ function DesktopNav({navColor, homeLink, icons}) {
|
|||
|
||||
return (
|
||||
<div ref={containerRef}>
|
||||
<nav className='wrolpi-navbar' id='global_navbar'
|
||||
style={{
|
||||
background: `var(--${navColor})`,
|
||||
color: 'var(--btn-text)',
|
||||
// The hotspot glyph stacks two icons, and the corner one paints a disc
|
||||
// of its surface behind itself. The bar's colour is the user's choice,
|
||||
// so it has to be handed down rather than looked up from a token.
|
||||
'--icon-stack-bg': `var(--${navColor})`,
|
||||
}}>
|
||||
<nav className='wrolpi-navbar' id='global_navbar' style={navBarStyle(navColors)}>
|
||||
<span ref={homeRef} style={{display: 'contents'}}>{homeLink}</span>
|
||||
{(isReady ? visibleLinks : allLinks).map((link, idx) => (
|
||||
<span
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue