Skip to content

[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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

skjnldsv
Copy link
Contributor

@skjnldsv skjnldsv commented Mar 25, 2025

Require nextcloud/server#51702

On next only so we're compatible with 32 and above? 🤞

@skjnldsv skjnldsv requested a review from ShGKme March 25, 2025 16:29
@skjnldsv skjnldsv self-assigned this Mar 25, 2025
@skjnldsv skjnldsv added 3. to review Waiting for reviews technical debt labels Mar 25, 2025
@skjnldsv skjnldsv added this to the 9.0.0 milestone Mar 25, 2025
@ShGKme

This comment was marked as resolved.

@skjnldsv

This comment was marked as resolved.

@skjnldsv
Copy link
Contributor Author

/backport to master

@skjnldsv
Copy link
Contributor Author

Done @ShGKme

Comment on lines +23 to +26
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
Copy link
Contributor

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

Suggested change
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

Copy link
Contributor

Choose a reason for hiding this comment

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

Or

Suggested change
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

Copy link
Contributor

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?

Copy link
Contributor Author

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 🙈

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

Successfully merging this pull request may close these issues.

2 participants