@@ -147,8 +144,8 @@ export default function LoginPage() {
shape="circle"
size="large"
className="toolbar-btn"
- aria-label={t('menu.theme')}
- title={t('menu.theme')}
+ aria-label={themeLabel}
+ title={themeLabel}
icon={themeIcon}
onClick={cycleTheme}
/>
diff --git a/frontend/src/pages/sub/SubHeader.tsx b/frontend/src/pages/sub/SubHeader.tsx
index fdc26a978..a58f75bce 100644
--- a/frontend/src/pages/sub/SubHeader.tsx
+++ b/frontend/src/pages/sub/SubHeader.tsx
@@ -2,6 +2,7 @@ import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { Button, Menu, Popover, Space } from 'antd';
import {
+ DesktopOutlined,
MoonFilled,
MoonOutlined,
SunOutlined,
@@ -10,7 +11,7 @@ import {
} from '@ant-design/icons';
import { LanguageManager } from '@/utils';
-import { pauseAnimationsUntilLeave, useTheme } from '@/hooks/useTheme';
+import { pauseAnimationsUntilLeave, themeModeKey, useTheme } from '@/hooks/useTheme';
interface SubHeaderProps {
title: string;
@@ -22,19 +23,11 @@ interface SubHeaderProps {
export default function SubHeader({ title, sId, email, lang, onLangChange }: SubHeaderProps) {
const { t } = useTranslation();
- const { isDark, isUltra, toggleTheme, toggleUltra } = useTheme();
+ const { mode, isDark, isUltra, cycleTheme: advanceTheme } = useTheme();
const cycleTheme = () => {
pauseAnimationsUntilLeave('sub-theme-cycle');
- if (!isDark) {
- toggleTheme();
- if (isUltra) toggleUltra();
- } else if (!isUltra) {
- toggleUltra();
- } else {
- toggleUltra();
- toggleTheme();
- }
+ advanceTheme();
};
const langMenuItems = useMemo(
@@ -53,13 +46,17 @@ export default function SubHeader({ title, sId, email, lang, onLangChange }: Sub
[],
);
- const themeIcon = !isDark ? (
-
- ) : !isUltra ? (
-
- ) : (
-
- );
+ const themeIcon =
+ mode === 'system' ? (
+
+ ) : !isDark ? (
+
+ ) : !isUltra ? (
+
+ ) : (
+
+ );
+ const themeLabel = `${t('menu.theme')}: ${t(themeModeKey(mode, isUltra))}`;
const initial = Array.from(title)[0]?.toUpperCase();
return (
@@ -83,8 +80,8 @@ export default function SubHeader({ title, sId, email, lang, onLangChange }: Sub
shape="circle"
size="large"
className="toolbar-btn"
- aria-label={t('menu.theme')}
- title={t('menu.theme')}
+ aria-label={themeLabel}
+ title={themeLabel}
icon={themeIcon}
onClick={cycleTheme}
/>
diff --git a/frontend/src/test/storybook-theme.test.tsx b/frontend/src/test/storybook-theme.test.tsx
index 275545c4e..e84892bc9 100644
--- a/frontend/src/test/storybook-theme.test.tsx
+++ b/frontend/src/test/storybook-theme.test.tsx
@@ -15,28 +15,32 @@ function StorybookTheme({ theme }: { theme: 'light' | 'dark' }) {
}
function ThemeToggle() {
- const { toggleTheme } = useTheme();
- return ;
+ const { cycleTheme } = useTheme();
+ return ;
}
afterEach(() => {
document.body.className = '';
document.documentElement.removeAttribute('data-theme');
document.documentElement.style.colorScheme = '';
+ // The provider seeds itself from storage at mount, so a toggle in one test
+ // would otherwise be inherited by the next.
+ localStorage.clear();
});
// Without color-scheme the browser paints native scrollbars light inside dark
// modals, e.g. the Edit Client body.
test('native scrollbars follow the panel theme', () => {
+ localStorage.setItem('theme-mode', 'light');
const { getByRole } = render(
,
);
- expect(document.documentElement.style.colorScheme).toBe('dark');
+ expect(document.documentElement.style.colorScheme).toBe('light');
fireEvent.click(getByRole('button'));
- expect(document.documentElement.style.colorScheme).toBe('light');
+ expect(document.documentElement.style.colorScheme).toBe('dark');
});
test('native scrollbars follow the Storybook theme', () => {
diff --git a/frontend/src/test/theme-system.test.tsx b/frontend/src/test/theme-system.test.tsx
new file mode 100644
index 000000000..b5094c879
--- /dev/null
+++ b/frontend/src/test/theme-system.test.tsx
@@ -0,0 +1,126 @@
+import { act, fireEvent, render } from '@testing-library/react';
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+
+import { ThemeProvider, useTheme } from '@/hooks/useTheme';
+
+// `system` must survive two things nothing else exercises: the OS flipping its
+// scheme while the tab stays open, and the legacy `dark-mode` boolean.
+
+type SchemeListener = (event: { matches: boolean }) => void;
+
+let systemDark = true;
+let listeners: SchemeListener[] = [];
+
+function installMatchMedia() {
+ window.matchMedia = ((query: string) => ({
+ matches: query.includes('prefers-color-scheme') ? systemDark : false,
+ media: query,
+ onchange: null,
+ addListener: () => {},
+ removeListener: () => {},
+ addEventListener: (_type: string, listener: SchemeListener) => {
+ listeners.push(listener);
+ },
+ removeEventListener: (_type: string, listener: SchemeListener) => {
+ listeners = listeners.filter((l) => l !== listener);
+ },
+ dispatchEvent: () => false,
+ })) as unknown as typeof window.matchMedia;
+}
+
+function flipSystemScheme(dark: boolean) {
+ systemDark = dark;
+ act(() => {
+ listeners.forEach((listener) => listener({ matches: dark }));
+ });
+}
+
+function Harness() {
+ const { mode, isDark, isUltra, cycleTheme } = useTheme();
+ return (
+
+ {mode}
+ {String(isDark)}
+ {String(isUltra)}
+
+
+ );
+}
+
+function renderHarness() {
+ const utils = render(
+
+
+ ,
+ );
+ return {
+ ...utils,
+ mode: () => utils.getByTestId('mode').textContent,
+ dark: () => utils.getByTestId('dark').textContent,
+ ultra: () => utils.getByTestId('ultra').textContent,
+ };
+}
+
+beforeEach(() => {
+ systemDark = true;
+ listeners = [];
+ installMatchMedia();
+ localStorage.clear();
+});
+
+afterEach(() => {
+ document.body.className = '';
+ document.documentElement.style.colorScheme = '';
+ document.documentElement.removeAttribute('data-theme');
+});
+
+describe('theme mode', () => {
+ it('honours the legacy dark-mode boolean when theme-mode was never written', () => {
+ localStorage.setItem('dark-mode', 'false');
+
+ const ui = renderHarness();
+
+ expect(ui.mode()).toBe('light');
+ expect(document.body.classList.contains('light')).toBe(true);
+ });
+
+ it('follows the OS scheme in system mode', () => {
+ localStorage.setItem('theme-mode', 'system');
+ const ui = renderHarness();
+
+ expect(ui.mode()).toBe('system');
+ expect(ui.dark()).toBe('true');
+ expect(document.body.classList.contains('dark')).toBe(true);
+
+ flipSystemScheme(false);
+
+ expect(ui.dark()).toBe('false');
+ expect(document.body.classList.contains('light')).toBe(true);
+ expect(document.documentElement.style.colorScheme).toBe('light');
+ });
+
+ it('keeps an explicit mode pinned when the OS scheme changes', () => {
+ const ui = renderHarness();
+ expect(ui.mode()).toBe('dark');
+
+ flipSystemScheme(false);
+
+ expect(ui.mode()).toBe('dark');
+ expect(ui.dark()).toBe('true');
+ expect(document.body.classList.contains('dark')).toBe(true);
+ });
+
+ it('cycles light → dark → ultra dark → system → light', () => {
+ const ui = renderHarness();
+ const seen: string[] = [];
+
+ for (let i = 0; i < 4; i += 1) {
+ fireEvent.click(ui.getByText('cycle'));
+ seen.push(`${ui.mode()}:${ui.ultra()}`);
+ }
+
+ expect(seen).toEqual(['dark:true', 'system:false', 'light:false', 'dark:false']);
+ });
+});
diff --git a/internal/web/translation/ar-EG.json b/internal/web/translation/ar-EG.json
index 0ca119013..2036f8f32 100644
--- a/internal/web/translation/ar-EG.json
+++ b/internal/web/translation/ar-EG.json
@@ -128,7 +128,11 @@
"openMenu": "فتح القائمة",
"pinSidebar": "تثبيت الشريط الجانبي",
"unpinSidebar": "إلغاء تثبيت الشريط الجانبي",
- "subFormats": "Sub Formats"
+ "subFormats": "Sub Formats",
+ "themeLight": "فاتح",
+ "themeDark": "داكن",
+ "themeUltraDark": "داكن فائق",
+ "themeSystem": "النظام"
},
"pages": {
"login": {
diff --git a/internal/web/translation/en-US.json b/internal/web/translation/en-US.json
index 579cb0cc1..678c20b49 100644
--- a/internal/web/translation/en-US.json
+++ b/internal/web/translation/en-US.json
@@ -128,7 +128,11 @@
"openMenu": "Open menu",
"pinSidebar": "Pin sidebar",
"unpinSidebar": "Unpin sidebar",
- "subFormats": "Sub Formats"
+ "subFormats": "Sub Formats",
+ "themeLight": "Light",
+ "themeDark": "Dark",
+ "themeUltraDark": "Ultra Dark",
+ "themeSystem": "System"
},
"pages": {
"login": {
diff --git a/internal/web/translation/es-ES.json b/internal/web/translation/es-ES.json
index 0c3d41291..76b5e24fd 100644
--- a/internal/web/translation/es-ES.json
+++ b/internal/web/translation/es-ES.json
@@ -128,7 +128,11 @@
"openMenu": "Abrir menú",
"pinSidebar": "Fijar barra lateral",
"unpinSidebar": "Desfijar barra lateral",
- "subFormats": "Sub Formats"
+ "subFormats": "Sub Formats",
+ "themeLight": "Claro",
+ "themeDark": "Oscuro",
+ "themeUltraDark": "Ultra oscuro",
+ "themeSystem": "Sistema"
},
"pages": {
"login": {
diff --git a/internal/web/translation/fa-IR.json b/internal/web/translation/fa-IR.json
index c310b72e1..885c43043 100644
--- a/internal/web/translation/fa-IR.json
+++ b/internal/web/translation/fa-IR.json
@@ -128,7 +128,11 @@
"openMenu": "باز کردن منو",
"pinSidebar": "ثابت کردن نوار کناری",
"unpinSidebar": "برداشتن تثبیت نوار کناری",
- "subFormats": "Sub Formats"
+ "subFormats": "Sub Formats",
+ "themeLight": "روشن",
+ "themeDark": "تیره",
+ "themeUltraDark": "تیره فوقالعاده",
+ "themeSystem": "سیستم"
},
"pages": {
"login": {
diff --git a/internal/web/translation/id-ID.json b/internal/web/translation/id-ID.json
index 916ca3d15..109d4bb5d 100644
--- a/internal/web/translation/id-ID.json
+++ b/internal/web/translation/id-ID.json
@@ -128,7 +128,11 @@
"openMenu": "Buka menu",
"pinSidebar": "Sematkan bilah sisi",
"unpinSidebar": "Lepas sematan bilah sisi",
- "subFormats": "Sub Formats"
+ "subFormats": "Sub Formats",
+ "themeLight": "Terang",
+ "themeDark": "Gelap",
+ "themeUltraDark": "Gelap Ultra",
+ "themeSystem": "Sistem"
},
"pages": {
"login": {
diff --git a/internal/web/translation/ja-JP.json b/internal/web/translation/ja-JP.json
index c295c4940..0534b1c17 100644
--- a/internal/web/translation/ja-JP.json
+++ b/internal/web/translation/ja-JP.json
@@ -128,7 +128,11 @@
"openMenu": "メニューを開く",
"pinSidebar": "サイドバーを固定",
"unpinSidebar": "サイドバーの固定を解除",
- "subFormats": "Sub Formats"
+ "subFormats": "Sub Formats",
+ "themeLight": "ライト",
+ "themeDark": "ダーク",
+ "themeUltraDark": "ウルトラダーク",
+ "themeSystem": "システム"
},
"pages": {
"login": {
diff --git a/internal/web/translation/pt-BR.json b/internal/web/translation/pt-BR.json
index a80d672a7..8d5e68319 100644
--- a/internal/web/translation/pt-BR.json
+++ b/internal/web/translation/pt-BR.json
@@ -128,7 +128,11 @@
"openMenu": "Abrir menu",
"pinSidebar": "Fixar barra lateral",
"unpinSidebar": "Desafixar barra lateral",
- "subFormats": "Sub Formats"
+ "subFormats": "Sub Formats",
+ "themeLight": "Claro",
+ "themeDark": "Escuro",
+ "themeUltraDark": "Ultra escuro",
+ "themeSystem": "Sistema"
},
"pages": {
"login": {
diff --git a/internal/web/translation/ru-RU.json b/internal/web/translation/ru-RU.json
index c1cea6397..893570dab 100644
--- a/internal/web/translation/ru-RU.json
+++ b/internal/web/translation/ru-RU.json
@@ -128,7 +128,11 @@
"openMenu": "Открыть меню",
"pinSidebar": "Закрепить боковую панель",
"unpinSidebar": "Открепить боковую панель",
- "subFormats": "Форматы подписки"
+ "subFormats": "Форматы подписки",
+ "themeLight": "Светлая",
+ "themeDark": "Тёмная",
+ "themeUltraDark": "Ультратёмная",
+ "themeSystem": "Системная"
},
"pages": {
"login": {
diff --git a/internal/web/translation/sk-SK.json b/internal/web/translation/sk-SK.json
index ff8bfa89e..9247be491 100644
--- a/internal/web/translation/sk-SK.json
+++ b/internal/web/translation/sk-SK.json
@@ -128,7 +128,11 @@
"openMenu": "Otvoriť menu",
"pinSidebar": "Pripnúť bočné menu",
"unpinSidebar": "Odopnúť bočné menu",
- "subFormats": "Formáty odberu"
+ "subFormats": "Formáty odberu",
+ "themeLight": "Svetlá",
+ "themeDark": "Tmavá",
+ "themeUltraDark": "Ultra tmavá",
+ "themeSystem": "Systém"
},
"pages": {
"login": {
diff --git a/internal/web/translation/tr-TR.json b/internal/web/translation/tr-TR.json
index 21fa5d97d..f8d9a504f 100644
--- a/internal/web/translation/tr-TR.json
+++ b/internal/web/translation/tr-TR.json
@@ -128,7 +128,11 @@
"openMenu": "Menüyü aç",
"pinSidebar": "Kenar çubuğunu sabitle",
"unpinSidebar": "Kenar çubuğu sabitlemesini kaldır",
- "subFormats": "Abonelik Formatları"
+ "subFormats": "Abonelik Formatları",
+ "themeLight": "Açık",
+ "themeDark": "Koyu",
+ "themeUltraDark": "Ultra koyu",
+ "themeSystem": "Sistem"
},
"pages": {
"login": {
diff --git a/internal/web/translation/uk-UA.json b/internal/web/translation/uk-UA.json
index c49937c02..146daa82a 100644
--- a/internal/web/translation/uk-UA.json
+++ b/internal/web/translation/uk-UA.json
@@ -128,7 +128,11 @@
"openMenu": "Відкрити меню",
"pinSidebar": "Закріпити бічну панель",
"unpinSidebar": "Відкріпити бічну панель",
- "subFormats": "Формати підписки"
+ "subFormats": "Формати підписки",
+ "themeLight": "Світла",
+ "themeDark": "Темна",
+ "themeUltraDark": "Ультратемна",
+ "themeSystem": "Системна"
},
"pages": {
"login": {
diff --git a/internal/web/translation/vi-VN.json b/internal/web/translation/vi-VN.json
index 42fcebafd..3a339bf80 100644
--- a/internal/web/translation/vi-VN.json
+++ b/internal/web/translation/vi-VN.json
@@ -128,7 +128,11 @@
"openMenu": "Mở menu",
"pinSidebar": "Ghim thanh bên",
"unpinSidebar": "Bỏ ghim thanh bên",
- "subFormats": "Sub Formats"
+ "subFormats": "Sub Formats",
+ "themeLight": "Sáng",
+ "themeDark": "Tối",
+ "themeUltraDark": "Siêu tối",
+ "themeSystem": "Hệ thống"
},
"pages": {
"login": {
diff --git a/internal/web/translation/zh-CN.json b/internal/web/translation/zh-CN.json
index 7a5e0c15c..aef65688f 100644
--- a/internal/web/translation/zh-CN.json
+++ b/internal/web/translation/zh-CN.json
@@ -128,7 +128,11 @@
"openMenu": "打开菜单",
"pinSidebar": "固定侧边栏",
"unpinSidebar": "取消固定侧边栏",
- "subFormats": "Sub Formats"
+ "subFormats": "Sub Formats",
+ "themeLight": "浅色",
+ "themeDark": "深色",
+ "themeUltraDark": "极致深色",
+ "themeSystem": "跟随系统"
},
"pages": {
"login": {
diff --git a/internal/web/translation/zh-TW.json b/internal/web/translation/zh-TW.json
index f50598777..23ed88c0d 100644
--- a/internal/web/translation/zh-TW.json
+++ b/internal/web/translation/zh-TW.json
@@ -128,7 +128,11 @@
"openMenu": "開啟選單",
"pinSidebar": "固定側邊欄",
"unpinSidebar": "取消固定側邊欄",
- "subFormats": "Sub Formats"
+ "subFormats": "Sub Formats",
+ "themeLight": "淺色",
+ "themeDark": "深色",
+ "themeUltraDark": "極致深色",
+ "themeSystem": "跟隨系統"
},
"pages": {
"login": {