-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: add dark mode support to luci-theme-openwrt #8127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |


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