Sky control: menu semantics, plates under bare-sky text, pinned colours
Some checks failed
Build pull request / Build pull request (pull_request) Has been cancelled

The menu is role=menu with menuitemradio items (aria-checked), the button carries
aria-expanded, focus goes to the checked item on open and back to the button on
close. Over the scene the estate title bar and any non-bubble message sit on the
sign-in card's plate (--sky-bubble) instead of bare sky. skyTheme.test.ts pins the
ink colours and WCAG ratios of the picked themes, measured with the ink clamped
into the sky range as skyState.test.ts does; the pass/fail set is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Void 2026-11-09 22:19:58 +00:00
commit d9554470ba
5 changed files with 113 additions and 35 deletions

View file

@ -2,6 +2,7 @@ import React, { MouseEventHandler, ReactNode, useCallback, useMemo, useRef } fro
import { useNavigate } from 'react-router-dom';
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
import { Avatar, Box, Chip, Icon, IconButton, Icons, Spinner, Text, color, config } from 'folds';
import classNames from 'classnames';
import { PageNav, PageNavContent, PageNavHeader } from '../../components/page';
import {
NavButton,
@ -42,6 +43,7 @@ import { EstateRoom, EstateTier } from './buildEstate';
import { activateEstateRoom, awaitMyJoin } from './joinEstateRoom';
import { useEstate, useEstateRootId } from './useEstate';
import * as css from './EstateNavigator.css';
import { SkyPlate } from '../scene/skyPlate.css';
import { SkyStateControl } from '../scene/SkyStateControl';
/** How long a tap waits for the client store to hold the room it just joined. */
@ -290,7 +292,7 @@ export function EstateNavigator() {
return (
<PageNav>
<PageNavHeader>
<Box alignItems="Center" grow="Yes" gap="300" className={css.Targets}>
<Box alignItems="Center" grow="Yes" gap="300" className={classNames(css.Targets, SkyPlate)}>
<Box grow="Yes">
<Text size="H4" truncate>
{title}

View file

@ -32,7 +32,8 @@ export function SkyStateControl() {
content={
<FocusTrap
focusTrapOptions={{
initialFocus: false,
initialFocus: '[aria-checked="true"]',
returnFocusOnDeactivate: true,
onDeactivate: () => setCords(undefined),
clickOutsideDeactivates: true,
isKeyForward: (evt: KeyboardEvent) => evt.key === 'ArrowDown',
@ -40,7 +41,7 @@ export function SkyStateControl() {
escapeDeactivates: stopPropagation,
}}
>
<Menu>
<Menu role="menu" aria-label="Sky">
<Box direction="Column" gap="100" style={{ padding: config.space.S100 }}>
{SKY_STATES.map((s) => (
<MenuItem
@ -48,7 +49,8 @@ export function SkyStateControl() {
size="300"
variant="Surface"
radii="300"
aria-pressed={state === s}
role="menuitemradio"
aria-checked={state === s}
onClick={() => {
setSkyState(s);
setCords(undefined);
@ -70,7 +72,7 @@ export function SkyStateControl() {
aria-label={`Sky: ${LABEL[state]}`}
title={`Sky: ${LABEL[state]}`}
aria-haspopup="menu"
aria-pressed={!!cords}
aria-expanded={!!cords}
onClick={open}
>
<Icon src={Icons.Bulb} size="200" />

View file

@ -0,0 +1,32 @@
import { globalStyle, style } from '@vanilla-extract/css';
import { config } from 'folds';
import { MessageBase, BubbleContent } from '../../components/message/layout/layout.css';
import { SKY_PLATE_FALLBACK } from './skyPlate';
// Over the scene (html[data-scene]) the signed-in shell is clear, so text outside a chat bubble
// would sit on bare sky, which a sky state can make light, dark or both (dusk): no ink clears
// 4.5:1 on all of that (skyTheme.test.ts). Such text gets a plate instead, never a halo.
const scene = ':root[data-scene]';
const fill = `var(--sky-bubble, ${SKY_PLATE_FALLBACK.fill})`;
const text = `var(--sky-bubble-text, ${SKY_PLATE_FALLBACK.text})`;
const plate = {
backgroundColor: fill,
color: text,
borderRadius: config.radii.R400,
} as const;
/** A title-bar group whose controls and title sit on the plate. */
export const SkyPlate = style({});
globalStyle(`${scene} ${SkyPlate}`, { ...plate, padding: `0 ${config.space.S100}` });
// Controls in the plate take its ink; their themed ink was chosen for the clear shell.
globalStyle(`${scene} ${SkyPlate} button`, { color: 'inherit' });
// A message that is not a bubble (Modern, Compact) is plain text on the scene: plate the row.
globalStyle(`${scene} ${MessageBase}:not(:has(.${BubbleContent}))`, plate);
// Links on a plate read against the plate. The Midnight and Noonday themes set their own
// --tc-link for it; the rest take the fallback, as the sign-in card does.
globalStyle(`${scene} body:not(.gamecult-theme) ${SkyPlate}, ${scene} body:not(.gamecult-theme) ${MessageBase}`, {
vars: { '--tc-link': SKY_PLATE_FALLBACK.link },
});

View file

@ -0,0 +1,9 @@
// The plate: the opaque surface text sits on wherever the shell is clear over the background
// scene and a sky state can make the sky behind it anything. It is the sign-in card's colour
// (--sky-bubble, set by the Midnight and Noonday themes in sky.css.ts), so what was checked for
// the card holds here. The other themes take these fallbacks.
export const SKY_PLATE_FALLBACK = {
fill: '#0d1a26',
text: '#b7c7d9',
link: '#99c7ff',
} as const;

View file

@ -1,18 +1,34 @@
import { describe, expect, it } from 'vitest';
import { baked } from '../../../sky/baked';
import { AA, contrast, luminance } from '../../../sky/skyTokens.js';
import { SKY_STATES, skyBackdrop, type SkyState } from './skyState';
import { SKY_PLATE_FALLBACK } from './skyPlate';
import { SKY_STATES, skyBackdrop, type SkyBackdrop, type SkyState } from './skyState';
import { skyThemeId } from './skyTheme';
const SKY = { 'midnight-sky': baked.midnight, 'noonday-sky': baked.noonday } as const;
const ratio = (a: number, b: number) => (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);
const fixed = (['day', 'dusk', 'night'] as const).flatMap((s) => {
const id = skyThemeId(s);
return id ? [[s, id] as const] : [];
});
// WCAG contrast of an ink against the sky it is worst on, measured as skyState.test.ts does: the
// sky can show any luminance between its darkest and lightest, and contrast is lowest where the
// backdrop is closest to the ink, which is the ink's own luminance clamped into that range.
const against = (ink: string, bg: number) => {
const li = luminance(ink);
const [hi, lo] = li > bg ? [li, bg] : [bg, li];
return (hi + 0.05) / (lo + 0.05);
};
const ratio = (ink: string, b: SkyBackdrop) =>
against(ink, Math.min(b.lightest, Math.max(b.darkest, luminance(ink))));
const r2 = (n: number) => n.toFixed(2);
describe('skyThemeId', () => {
it('leaves the theme alone in auto and picks one for every fixed state', () => {
expect(skyThemeId('auto')).toBeUndefined();
SKY_STATES.filter((s) => s !== 'auto').forEach((s) => {
expect(skyThemeId(s)).toBeDefined();
});
expect(SKY_STATES.filter((s) => s !== 'auto').map((s) => skyThemeId(s))).not.toContain(
undefined
);
});
it('lights day and dusk with dark ink and night with light ink', () => {
@ -22,38 +38,55 @@ describe('skyThemeId', () => {
});
});
describe('contrast of the theme a state picks', () => {
const picked = SKY_STATES.flatMap((s) => {
const id = skyThemeId(s);
return id ? [[s, SKY[id]] as const] : [];
describe('ink of the theme a state picks, on bare sky', () => {
// [state, text ratio, link ratio]; a theme's own ink is not chosen for bare sky, so only day
// and night text pass (Nibu's measurement, skyState.test.ts). Links never rest on bare sky.
const cells: [SkyState, string, string, string, string][] = [
['day', 'noonday-sky', '#342d25', '7.62', '#2a4f27'],
['dusk', 'noonday-sky', '#342d25', '1.00', '#2a4f27'],
['night', 'midnight-sky', '#aeccff', '5.05', '#609385'],
];
it.each(cells)('%s with %s: ink %s measures %s', (state, id, ink, want, link) => {
const sky = SKY[id as keyof typeof SKY];
expect(sky.tokens.Background.OnContainer).toBe(ink);
expect(sky.link).toBe(link);
expect(r2(ratio(ink, skyBackdrop(state)))).toBe(want);
});
it.each(picked)('%s: every container carries its text at AA', (_state, sky) => {
Object.values(sky.tokens).forEach((group) => {
expect(contrast(group.OnContainer, group.Container)).toBeGreaterThanOrEqual(AA);
});
});
it.each(picked)('%s: links read at AA on the background surface', (_state, sky) => {
expect(contrast(sky.link, sky.tokens.Background.Container)).toBeGreaterThanOrEqual(AA);
});
// Bare sky has no surface under it. Text may sit there only where the ink clears AA against
// both the darkest and the lightest sky the state can show; anywhere else it needs a surface.
const onBareSky = (state: SkyState): number => {
const id = skyThemeId(state);
if (!id) return 0;
const ink = luminance(SKY[id].tokens.Background.OnContainer);
const { darkest, lightest } = skyBackdrop(state);
return Math.min(ratio(ink, darkest), ratio(ink, lightest));
};
it('day and night text on bare sky clears AA', () => {
expect(onBareSky('day')).toBeGreaterThanOrEqual(AA);
expect(onBareSky('night')).toBeGreaterThanOrEqual(AA);
});
it('dusk text on bare sky does not, so dusk text stays on surfaces', () => {
expect(onBareSky('dusk')).toBeLessThan(AA);
it('only the cells that clear AA on bare sky carry text there', () => {
const passing = fixed.filter(
([s, id]) => ratio(SKY[id].tokens.Background.OnContainer, skyBackdrop(s)) >= AA
);
expect(passing.map(([s]) => s)).toEqual(['day', 'night']);
});
});
describe('the plate, where text cannot rest on bare sky', () => {
// Each theme's plate: fill, ink, link and the WCAG ratios of ink and link on the fill.
const plates = [
['midnight-sky', baked.midnight, '12.17', '5.68'],
['noonday-sky', baked.noonday, '6.70', '4.62'],
] as const;
it.each(plates)('%s: ink and link on the fill', (_id, sky, inkRatio, linkRatio) => {
expect(r2(contrast(sky.bubbles.OtherText, sky.bubbles.Other))).toBe(inkRatio);
expect(r2(contrast(sky.link, sky.bubbles.Other))).toBe(linkRatio);
expect(contrast(sky.bubbles.OtherText, sky.bubbles.Other)).toBeGreaterThanOrEqual(AA);
expect(contrast(sky.link, sky.bubbles.Other)).toBeGreaterThanOrEqual(AA);
});
it('the other themes take fallback colours that clear AA', () => {
const { fill, text, link } = SKY_PLATE_FALLBACK;
expect(r2(contrast(text, fill))).toBe('10.21');
expect(r2(contrast(link, fill))).toBe('10.03');
});
it('every container of the picked themes carries its text at AA', () => {
fixed.forEach(([, id]) => {
Object.values(SKY[id].tokens).forEach((g) => {
expect(contrast(g.OnContainer, g.Container)).toBeGreaterThanOrEqual(AA);
});
});
});
});