-
Notifications
You must be signed in to change notification settings - Fork 93
[next] feat: use nextcloud-theme-dark
var for dark theme computation
#6648
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: main
Are you sure you want to change the base?
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Signed-off-by: John Molakvoæ <[email protected]>
3af1c88
to
4942940
Compare
/backport to master |
Done @ShGKme |
const darkModeSystemPreference = window?.matchMedia?.('(prefers-color-scheme: dark)')?.matches | ||
const darkModeAccountSetting = document.body.getAttribute('data-themes')?.includes('dark') | ||
const darkModeElementOverride = el.closest('[data-theme-dark]') !== null | ||
return darkModeElementOverride || darkModeAccountSetting || darkModeSystemPreference || false |
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.
To do lazy checks and not perform x3 DOM API calls
const darkModeSystemPreference = window?.matchMedia?.('(prefers-color-scheme: dark)')?.matches | |
const darkModeAccountSetting = document.body.getAttribute('data-themes')?.includes('dark') | |
const darkModeElementOverride = el.closest('[data-theme-dark]') !== null | |
return darkModeElementOverride || darkModeAccountSetting || darkModeSystemPreference || false | |
if (el.closest('[data-theme-dark]') !== null) { | |
return true | |
} | |
if (document.body.getAttribute('data-themes')?.includes('dark')) { | |
return true | |
} | |
if (window.matchMedia('(prefers-color-scheme: dark)')?.matches) { | |
return true | |
} | |
return false |
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.
Or
const darkModeSystemPreference = window?.matchMedia?.('(prefers-color-scheme: dark)')?.matches | |
const darkModeAccountSetting = document.body.getAttribute('data-themes')?.includes('dark') | |
const darkModeElementOverride = el.closest('[data-theme-dark]') !== null | |
return darkModeElementOverride || darkModeAccountSetting || darkModeSystemPreference || false | |
const darkModeSystemPreference = () => window.matchMedia('(prefers-color-scheme: dark)')?.matches | |
const darkModeAccountSetting = () => document.body.getAttribute('data-themes')?.includes('dark') | |
const darkModeElementOverride = () => el.closest('[data-theme-dark]') !== null | |
return darkModeElementOverride() || darkModeAccountSetting() || darkModeSystemPreference() || false |
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.
// 1. first priority is the data-theme-dark attribute on a parent element
// 2. second priority is the data-themes attribute on the body, aka the user setting
Could you provide with the example where we need 2 and 1 was not enough?
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.
@ShGKme future proof. The Theming engine have been initially designed so other themes could be added or even provided on the appstore.
The [data-theme-dark]
wasn't even properly discussed 🙈
Require nextcloud/server#51702
On next only so we're compatible with 32 and above? 🤞