feat: add dark mode support to luci-theme-openwrt#8127
feat: add dark mode support to luci-theme-openwrt#8127miaohf wants to merge 3 commits intoopenwrt:masterfrom
Conversation
- Add CSS variables for theming - Add dark mode toggle button in header - Support automatic system preference detection - Save user preference to localStorage Signed-off-by: Miao,Haifeng <miaohf@sina.com> Signed-off-by: miaohf <miaohf@sina.com>
d4f3bbc to
7610677
Compare
|
comment message updated. |
|
@miaohf: Good job, thanks! |
That is actually pretty funny for a guy who has started computing in the era of "only dark mode available", as computer monitors were only CRTs with black background and green or yellow dots on the 80x24 monitor screen. |
| isDark = prefersDark; | ||
| } | ||
|
|
||
| this.updateDarkModeUI(isDark, icon); |
There was a problem hiding this comment.
let isDark = savedMode === null ? media.matches : (savedMode === 'true');
const setMode = (dark, save=false) => {
document.documentElement.setAttribute('data-darkmode', dark);
if (save)
localStorage.setItem('luci-darkmode', dark);
this.updateDarkModeUI(dark, icon);
};
setMode(isDark);|
|
||
| // Get saved preference or detect system preference | ||
| const savedMode = localStorage.getItem('luci-darkmode'); | ||
| const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches; |
There was a problem hiding this comment.
const media = window.matchMedia('(prefers-color-scheme: dark)');| if (localStorage.getItem('luci-darkmode') === null) { | ||
| this.updateDarkModeUI(e.matches, icon); | ||
| } | ||
| }); |
There was a problem hiding this comment.
toggle.addEventListener('click', () => {
const next = document.documentElement.getAttribute('data-darkmode') !== 'true';
setMode(next, true);
});
// Change when user has not set a preference
media.addEventListener('change', e => {
if (localStorage.getItem('luci-darkmode') === null)
setMode(e.matches);
});|
:) |
|
1 - remove the merge commit - just rebase on master |
| [data-darkmode="true"] .cbi-section-node { | ||
| background: var(--bg-section); | ||
| border-color: var(--border-section); | ||
| } |
There was a problem hiding this comment.
Why switch both on [dark-mode="true] and --bg-section? Similar comment on all the other items where this is in


Signed-off-by: <my@email.address>row (viagit commit --signoff)<package name>: titlefirst line subject for packagesPKG_VERSIONin the MakefileDescription
Add dark mode support to luci-theme-openwrt theme.
Features
Implementation
<head>to prevent flash of light modeFiles Changed
cascade.css- Added CSS variables and dark mode style overridesheader.ut- Added dark mode toggle button and early initialization scriptmenu-openwrt.js- Added dark mode toggle logic and localStorage handlingREADME.md- Added documentation for dark mode featureScreenshots
Dark Mode:
Light Mode:
[
]
Toggle Button:
Testing