Skip to content

feat: Implement dynamic theme switching and dark mode support#3323

Open
DSingh0304 wants to merge 24 commits intoapache:masterfrom
DSingh0304:proposal/dark-mode
Open

feat: Implement dynamic theme switching and dark mode support#3323
DSingh0304 wants to merge 24 commits intoapache:masterfrom
DSingh0304:proposal/dark-mode

Conversation

@DSingh0304
Copy link
Contributor

@DSingh0304 DSingh0304 commented Mar 10, 2026

Why submit this pull request?

  • Bugfix
  • New feature provided
  • Improve performance
  • Backport patches

What changes will this PR take into?

Add dark mode theme support to the APISIX Dashboard, allowing users to switch between light, dark, and system preferred color schemes via a segmented control (☀️ Light / 🌙 Dark / 🖥️ Auto) in the header.

Changes

  • FOUC prevention: Added an inline <script> in index.html that reads the persisted color scheme from localStorage and sets data-mantine-color-scheme on <html> before CSS parses prevents a flash of the wrong theme on page load
  • Mantine: Set defaultColorScheme="auto" on MantineProvider so the dashboard respects the user's OS preference by default
  • Ant Design: Used Mantine's useComputedColorScheme('light') to resolve the actual scheme (since Ant Design does not handle 'auto' internally), then conditionally applied theme.darkAlgorithm on ConfigProvider keeps ProTable in sync with the Mantine shell
  • Monaco Editor: Added imperative monaco.editor.setTheme() via useEffect + onMount ref, since Monaco does not re-theme on React prop changes after initial mount
  • Theme toggle: Added a ThemeToggle segmented control component in the header with three options: Light / Dark / Auto
  • Smooth transitions: Added a temporary CSS transition class on body during theme switches (removed after 200ms to avoid impacting Lighthouse performance)
  • E2E tests: Added tests for auto mode resolution (using Playwright's emulateMedia), theme persistence across page reloads, and cycling through all theme modes

Technical notes

  • No separate Jotai atom was needed Mantine manages color scheme persistence internally via localStorage (mantine-color-scheme-value)
  • forceColorScheme was intentionally avoided it overrides system preference and would make auto mode a silent no op
  • Custom CSS in global.css already uses Mantine CSS variables (--mantine-color-*), which auto-adapt no manual overrides were needed
  • This change is purely additive no structural or architectural changes

Related issues

resolve #3322

Screenshot
image

Checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

@DSingh0304 DSingh0304 changed the title Implement dynamic theme switching and dark mode support feat: Implement dynamic theme switching and dark mode support Mar 10, 2026
@DSingh0304
Copy link
Contributor Author

Hi @Baoyuantop, I have implemented the dark mode support for the Dashboard as discussed in the community. The PR is ready for your review whenever you have a moment. I would appreciate any feedback you have.
Thanks.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds end-to-end dark mode support across the dashboard UI by enabling Mantine color-scheme persistence, providing a header toggle, and aligning third-party UI theming (AntD + Monaco) with the active scheme.

Changes:

  • Enable automatic (OS-driven) color scheme by default in MantineProvider and bootstrap scheme early in index.html.
  • Add a header theme segmented control with a short transition window for smoother switching.
  • Propagate scheme changes to Ant Design (theme algorithms) and Monaco editor (vs-light/vs-dark), plus add Playwright coverage.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/styles/global.css Adds a global transition rule during theme switching.
src/main.tsx Sets Mantine default color scheme to auto.
src/config/antdConfigProvider.tsx Switches AntD theme algorithm based on computed color scheme.
src/components/Header/ThemeToggle.tsx New theme toggle control with transition handling.
src/components/Header/index.tsx Places the new theme toggle into the header actions.
src/components/form/Editor.tsx Makes Monaco theme follow the computed color scheme (incl. imperative update).
index.html Adds an early script to set data-mantine-color-scheme before React mounts.
e2e/tests/dark-mode.spec.ts Adds Playwright tests for theme switching and persistence.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

DSingh0304 and others added 7 commits March 12, 2026 10:01
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

DSingh0304 and others added 2 commits March 13, 2026 09:34
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@DSingh0304 DSingh0304 requested a review from Copilot March 18, 2026 15:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

DSingh0304 and others added 2 commits March 18, 2026 20:51
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@DSingh0304
Copy link
Contributor Author

DSingh0304 commented Mar 18, 2026

Hi @Baoyuantop I have addressed all the comments of copilot and made the changes. Can you please review this feature whenever you get time. Thank You!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feat: Dark Mode Support for APISIX Dashboard

2 participants