mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #7026] feat(frontend): add a follow-system theme mode #6590
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6590
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/7026
Author: @ridersaying
Created: 10/29/2026
Status: 🔄 Open
Base:
main← Head:main📝 Commits (1)
97378bdfeat(frontend): add a follow-system theme mode📊 Changes
20 files changed (+393 additions, -82 deletions)
View changed files
📝
frontend/src/components/command-palette/CommandPalette.tsx(+16 -15)📝
frontend/src/hooks/useTheme.tsx(+130 -11)📝
frontend/src/layouts/AppSidebar.tsx(+24 -21)📝
frontend/src/pages/login/LoginPage.tsx(+18 -21)📝
frontend/src/test/storybook-theme.test.tsx(+3 -0)➕
frontend/src/test/theme-system.test.tsx(+132 -0)📝
internal/web/translation/ar-EG.json(+5 -1)📝
internal/web/translation/en-US.json(+5 -1)📝
internal/web/translation/es-ES.json(+5 -1)📝
internal/web/translation/fa-IR.json(+5 -1)📝
internal/web/translation/id-ID.json(+5 -1)📝
internal/web/translation/ja-JP.json(+5 -1)📝
internal/web/translation/pt-BR.json(+5 -1)📝
internal/web/translation/ru-RU.json(+5 -1)📝
internal/web/translation/sk-SK.json(+5 -1)📝
internal/web/translation/tr-TR.json(+5 -1)📝
internal/web/translation/uk-UA.json(+5 -1)📝
internal/web/translation/vi-VN.json(+5 -1)📝
internal/web/translation/zh-CN.json(+5 -1)📝
internal/web/translation/zh-TW.json(+5 -1)📄 Description
Summary
Adds a third theme mode,
system, so the panel can follow the OS light/dark preference instead of forcing an explicit choice. The theme switch now cycles light → dark → ultra dark → system, and insystemmode the panel repaints whenever the desktop scheme changes, without a reload.Why
The panel only offered light, dark and ultra dark, stored as a boolean in
dark-mode. Anyone running a scheduled dark mode (macOS auto appearance, GNOME night light, Windows auto dark) has to flip the switch twice a day by hand, and the panel never matches the rest of the desktop.I searched the issue tracker and the PR list first —
prefers-color-scheme, "auto theme", "theme follow system" and "system dark" return nothing, and no open or closed PR implements it. #6827 (token-based theme customisation) and #6949 (accent colours) are the nearest neighbours and neither touches the mode itself. So this is a new feature rather than a fix to something existing.Type of change
Areas affected
How was this tested?
Unit / component (jsdom)
npx vitest run --project components src/test/theme-system.test.tsx— 4 tests, each written to fail on a specific regression:honours the legacy dark-mode boolean when theme-mode was never written— a storeddark-mode=falsewith notheme-modemust open light, so existing users keep their theme through the upgrade.follows the OS scheme in system mode— flipping thematchMedialistener must repaint body class andcolor-schemewithout a remount.keeps an explicit mode pinned when the OS scheme changes— an explicit light/dark choice must ignore OS changes; this is the regression that would make the feature annoying rather than useful.cycles light → dark → ultra dark → system → light— pins the cycle order, including that ultra dark is dropped on the way out.src/test/storybook-theme.test.tsxneeded one change:localStorage.clear()between cases, because the provider now seeds from storage at mount instead of a module-level snapshot, so a toggle in one case leaked into the next.Real browser, against a built panel
The branch was built into a linux/amd64 binary and served a real panel; Chromium drove the login page with CDP colour-scheme emulation:
color-schemeRows 3–5 are the point of the change: same tab, same session, only the emulated OS scheme changing.
Three platforms
npm run typecheck,npm run lint,npm run format:checkandnpx vite buildwere run on macOS (Node 26), Windows 11 (Node 26) and Ubuntu (Node 24): all clean, no warnings. The full component suite (100 files, 501 tests) passes locally.Screenshots / recordings
The toggle sits next to the docs and donate buttons in the sidebar brand row and in the login toolbar, and shows a desktop icon in
systemmode; the command palette action (Ctrl/Cmd+K→ Theme) is titled with the current mode too.I have full-size captures of each state and can attach them here if you want them in the review — tell me and I will upload.
Breaking changes
None.
dark-mode(existing) andisUltraDarkThemeEnabledare still written on every change, so older panel builds, user scripts and anything reading the boolean keep working.theme-modeis new and optional; when absent, the stored boolean seeds it, so nobody's theme changes after the upgrade.useTheme()keeps its existing shape (isDark,isUltra,toggleTheme,toggleUltra,antdThemeConfig) and addsmode,systemDark,setMode,cycleTheme. Existing consumers (HostsPage,NodesPage,ApiDocsPage,Sparkline, …) needed no changes.menu.themeLight,menu.themeDark,menu.themeUltraDark,menu.themeSystem, translated in all 14 locales.i18n-dead-keys.test.tspasses, so no locale is missing them.Checklist
go build ./...passes locally, and the linux/amd64 binary built from this branch is running on a production panel.npm run lint,npm run typecheck, andnpm run buildpass.Note on the third item: no Go file is touched by this PR, so the Go test suite was not run.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.