Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script>
// Apply a stored Light or Dark v2 choice before first paint, so it never
// flashes the OS theme. Keep the key in step with src/v2/utils/theme.ts.
try {
var v2Theme = window.localStorage.getItem('v2.theme');
if (v2Theme === 'light' || v2Theme === 'dark') {
document.documentElement.setAttribute('data-v2-theme', v2Theme);
}
} catch (e) {
// Storage can be blocked; the OS theme then applies.
}
</script>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="/signup-source.js"></script>
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
"communityRedirect": {
"title": "Opening Community",
"text": "Checking your access…"
},
"theme": {
"label": "Appearance",
"auto": "Auto",
"light": "Light",
"dark": "Dark"
}
},
"agentSkills": {
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
"communityRedirect": {
"title": "正在打开社区",
"text": "正在检查你的访问权限…"
},
"theme": {
"label": "外观",
"auto": "自动",
"light": "浅色",
"dark": "深色"
}
},
"agentSkills": {
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/v2/V2App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import '@fontsource/ibm-plex-sans/500.css';
import '@fontsource/ibm-plex-sans/600.css';
import '@fontsource/ibm-plex-mono/500.css';
import './v2.css';
import { applyV2Theme, getV2Theme } from './utils/theme';

// TASK-145 — inside the shell, only the surfaces the composer path needs stay
// in this chunk (V2Layout, the auth gate, the feature frame). Everything else
Expand Down Expand Up @@ -178,6 +179,10 @@ const V2LegacyChatRedirect: React.FC = () => {
const V2App: React.FC = () => {
// The daily digest's 08:00 is the person's own (TASK-257 Phase 2b).
useTimeZoneCapture();
React.useEffect(() => {
applyV2Theme(getV2Theme());
}, []);

React.useEffect(() => {
try {
sessionStorage.setItem('commonly.v2.active', '1');
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/v2/__tests__/v2-layout-invariants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const cssVariable = (css: string, name: string): string | undefined => (

const activeAccentBackgroundSelectors = (css: string, classNames: Set<string>): string[] => (
[...new Set(Array.from(css.matchAll(/([^{}]+)\{([^{}]*)\}/g)).flatMap(([, rawSelector, body]) => {
if (!/background\s*:\s*var\(--v2-accent\)/.test(body)) return [];
if (!/background\s*:\s*var\(--v2-accent(?:-fill)?\)/.test(body)) return [];
return rawSelector
.replace(/\/\*[\s\S]*?\*\//g, '')
.split(',')
Expand Down Expand Up @@ -435,15 +435,15 @@ describe('v2 layout invariants (CSS rule presence)', () => {
expect(shared).toContain('font-size: 12px');
expect(cancel).toContain('color: var(--v2-text-tertiary)');
expect(submit).toContain('background: var(--v2-ink)');
expect(submit).toContain('color: var(--v2-bg)');
expect(submit).toContain('color: var(--v2-on-ink)');
expect(disabled).toContain('background: var(--v2-border-strong)');
expect(phone).not.toBe('');
expect(ruleBody(v2, '.v2-root button.v2-pods__create-submit', { within: phone })).toContain('min-height: 40px');
});

test('the selected pod keeps the sidebar’s one cobalt block treatment', () => {
const selected = selectorRuleBody(v2, '.v2-root button.v2-pods__row--selected');
expect(selected).toContain('background: var(--v2-accent)');
expect(selected).toContain('background: var(--v2-accent-fill)');
expect(selected).toContain('font-weight: 600');
expect(podsSidebar).not.toContain('v2-pods__item--active');
expect(podsSidebar).not.toContain('v2-pods__item-dot');
Expand Down Expand Up @@ -1237,7 +1237,7 @@ describe('v2 layout invariants (CSS rule presence)', () => {
expect(billingPanel).not.toContain('free in beta');
expect(billingPanel).not.toContain('included during beta');
const badge = ruleBody(v2, '.v2-settings__section .v2-billing__badge');
expect(badge).toContain('background: #ffffff');
expect(badge).toContain('background: var(--v2-surface)');
expect(badge).toContain('font-family: var(--v2-font-mono)');
expect(ruleBody(v2, '.v2-settings__section .v2-billing__badge--pro')).toContain('background: var(--v2-accent)');
});
Expand Down Expand Up @@ -1406,7 +1406,7 @@ describe('v2 layout invariants (CSS rule presence)', () => {
expect(v2).not.toContain('.v2-thread-card__reply');
expect(ruleBody(v2, '.v2-thread .v2-msg__mention')).toContain('background: #e8ecfb');
expect(ruleBody(v2, '.v2-thread .v2-avatar--flat-agent')).toContain('var(--v2-accent)');
expect(ruleBody(v2, '.v2-thread .v2-avatar--flat-human')).toContain('var(--v2-surface-tint)');
expect(ruleBody(v2, '.v2-thread .v2-avatar--flat-human')).toContain('background: #f2f4f7');
});

test('Your Team (direction C): three-column card grid, state-coloured marks, cobalt ring for needs-you, ink Hire, no green, old tiers gone', () => {
Expand Down Expand Up @@ -2530,7 +2530,7 @@ describe('v2 layout invariants (CSS rule presence)', () => {
expect(ruleBody(v2, '.v2-authenticated-shell .v2-pane--main')).toContain('height: calc(100% - 16px)');
// Phones: the card goes flush — both selectors, or the banner variant keeps the desktop height.
expect(v2).toMatch(/@media \(max-width: 760px\) \{[\s\S]*?\.v2-pane--main,\n\s*\.v2-authenticated-shell \.v2-pane--main \{[\s\S]*?border-radius: 0/);
expect(ruleBody(v2, '.v2-feature')).toContain('background: #ffffff');
expect(ruleBody(v2, '.v2-feature')).toContain('background: var(--v2-surface)');
});

test('the radius ladder is 4 / 4 / 6 in both files (Signal: hard edges)', () => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/v2/components/V2DevicesPanel.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.v2-devices__heading { display: flex; justify-content: space-between; gap: 16px; align-items: start; margin-bottom: 18px; }
.v2-devices h2 { margin: 0; font-size: 18px; color: var(--v2-text-primary); }
.v2-devices p { margin: 5px 0 0; color: var(--v2-text-secondary); }
.v2-devices button { border: 1px solid var(--v2-border-strong); border-radius: 7px; padding: 7px 10px; background: #fff; color: var(--v2-text-primary); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
.v2-devices button { border: 1px solid var(--v2-border-strong); border-radius: 7px; padding: 7px 10px; background: var(--v2-surface); color: var(--v2-text-primary); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
.v2-devices__list { display: grid; gap: 10px; }
.v2-devices__item { display: flex; justify-content: space-between; gap: 14px; align-items: center; padding: 13px; border: 1px solid var(--v2-border-soft); border-radius: 9px; }
.v2-devices__item strong, .v2-devices__item span { display: block; }
Expand Down
50 changes: 36 additions & 14 deletions frontend/src/v2/components/V2SettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import V2Avatar from './V2Avatar';
import V2AvatarCropDialog from './V2AvatarCropDialog';
import { nextPaperAvatarPreset } from '../utils/avatarPresets';
import { LANGUAGE_REGISTRY } from '../../i18n';
import { V2_THEMES, V2ThemePref, getV2Theme, setV2Theme } from '../utils/theme';

type TokenStatus = {
hasToken?: boolean;
Expand Down Expand Up @@ -474,22 +475,43 @@ const V2ApiTokenSection: React.FC = () => {
const V2LanguageSection: React.FC = () => {
const { i18n, t } = useTranslation();
const active = i18n.resolvedLanguage || i18n.language || 'en';
const [theme, setTheme] = useState<V2ThemePref>(() => getV2Theme());
const chooseTheme = (pref: V2ThemePref) => {
setTheme(pref);
setV2Theme(pref);
};

return (
<div className="v2-settings__language" role="radiogroup" aria-label={t('common.language.label')}>
{LANGUAGE_REGISTRY.map((language) => (
<button
key={language.code}
type="button"
className={`v2-settings__language-option${active === language.code ? ' v2-settings__language-option--active' : ''}`}
role="radio"
aria-checked={active === language.code}
onClick={() => void i18n.changeLanguage(language.code)}
>
{language.label}
</button>
))}
</div>
<>
<div className="v2-settings__language" role="radiogroup" aria-label={t('common.language.label')}>
{LANGUAGE_REGISTRY.map((language) => (
<button
key={language.code}
type="button"
className={`v2-settings__language-option${active === language.code ? ' v2-settings__language-option--active' : ''}`}
role="radio"
aria-checked={active === language.code}
onClick={() => void i18n.changeLanguage(language.code)}
>
{language.label}
</button>
))}
</div>
<div className="v2-settings__language" role="radiogroup" aria-label={t('common.theme.label')}>
{V2_THEMES.map((pref) => (
<button
key={pref}
type="button"
className={`v2-settings__language-option${theme === pref ? ' v2-settings__language-option--active' : ''}`}
role="radio"
aria-checked={theme === pref}
onClick={() => chooseTheme(pref)}
>
{t(`common.theme.${pref}`)}
</button>
))}
</div>
</>
);
};

Expand Down
59 changes: 59 additions & 0 deletions frontend/src/v2/utils/__tests__/theme.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import fs from 'fs';
import path from 'path';
import { applyV2Theme, getV2Theme, setV2Theme, V2_THEME_KEY } from '../theme';

const v2css = fs.readFileSync(path.join(__dirname, '../../v2.css'), 'utf8');

describe('v2 appearance preference (D216)', () => {
beforeEach(() => {
window.localStorage.clear();
document.documentElement.removeAttribute('data-v2-theme');
});

test('defaults to auto when nothing is stored', () => {
expect(getV2Theme()).toBe('auto');
});

test('ignores a stored value that is not a known preference', () => {
window.localStorage.setItem(V2_THEME_KEY, 'midnight');
expect(getV2Theme()).toBe('auto');
});

test('setV2Theme stores the choice and sets the html attribute the CSS reads', () => {
setV2Theme('dark');
expect(window.localStorage.getItem(V2_THEME_KEY)).toBe('dark');
expect(document.documentElement.getAttribute('data-v2-theme')).toBe('dark');
expect(getV2Theme()).toBe('dark');
});

test('applyV2Theme on load restores a stored light choice without writing storage', () => {
window.localStorage.setItem(V2_THEME_KEY, 'light');
applyV2Theme(getV2Theme());
expect(document.documentElement.getAttribute('data-v2-theme')).toBe('light');
});

test('v2.css carries the D216 dark set for both explicit dark and auto', () => {
expect(v2css).toContain(':root[data-v2-theme="dark"] .v2-root {');
expect(v2css).toContain('@media (prefers-color-scheme: dark) {\n :root:not([data-v2-theme="light"]) .v2-root {');
expect(v2css).toMatch(/:root\[data-v2-theme="dark"\] \.v2-root \{[\s\S]*?--v2-text-primary: #e8ebf1;/);
});

test('the explicit and auto dark blocks declare the same tokens (ux-lead ruling, 4)', () => {
const explicit = v2css.match(/:root\[data-v2-theme="dark"\] \.v2-root \{([\s\S]*?)\n\}/);
const auto = v2css.match(/:root:not\(\[data-v2-theme="light"\]\) \.v2-root \{([\s\S]*?)\n \}/);
expect(explicit).not.toBeNull();
expect(auto).not.toBeNull();
const decls = (body: string) =>
body.split(';').map((d) => d.trim()).filter((d) => d.startsWith('--') || d.startsWith('color-scheme'));
expect(decls(auto![1])).toEqual(decls(explicit![1]));
expect(decls(explicit![1])).toContain('--v2-focus-ring: 0 0 0 2px var(--v2-bg), 0 0 0 4px #8aa2ff');
});

test('index.html applies a stored Light or Dark choice before first paint (code-gate HOLD, rhea)', () => {
const html = fs.readFileSync(path.join(__dirname, '../../../../index.html'), 'utf8');
const head = html.slice(0, html.indexOf('</head>'));
expect(head).toContain(`getItem('${V2_THEME_KEY}')`);
expect(head).toContain("v2Theme === 'light' || v2Theme === 'dark'");
expect(head).toContain("setAttribute('data-v2-theme', v2Theme)");
});
});
29 changes: 29 additions & 0 deletions frontend/src/v2/utils/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// D216 appearance preference for v2. 'auto' follows the OS (the default when
// nothing is stored); 'light' and 'dark' force a set. The choice lives on the
// <html> element as data-v2-theme, and the CSS in v2.css reads it.
export type V2ThemePref = 'auto' | 'light' | 'dark';

export const V2_THEME_KEY = 'v2.theme';
export const V2_THEMES: readonly V2ThemePref[] = ['auto', 'light', 'dark'];

export function getV2Theme(): V2ThemePref {
try {
const stored = window.localStorage.getItem(V2_THEME_KEY);
return (V2_THEMES as readonly string[]).includes(stored || '') ? (stored as V2ThemePref) : 'auto';
} catch {
return 'auto';
}
}

export function applyV2Theme(pref: V2ThemePref): void {
document.documentElement.setAttribute('data-v2-theme', pref);
}

export function setV2Theme(pref: V2ThemePref): void {
try {
window.localStorage.setItem(V2_THEME_KEY, pref);
} catch {
// Storage can be blocked; the choice still applies for this page view.
}
applyV2Theme(pref);
}
Loading
Loading