Skip to content

Commit 9730473

Browse files
skjnldsvShGKme
andcommitted
chore: cleaner code syntax
Co-authored-by: Grigorii K. Shartsev <me@shgk.me> Signed-off-by: John Molakvoæ <skjnldsv@users.noreply.github.com>
1 parent ce3ce40 commit 9730473

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

src/functions/isDarkTheme/index.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,19 @@ export function checkIfDarkTheme(el: HTMLElement = document.body): boolean {
2020
// 2. second priority is the data-themes attribute on the body, aka the user setting
2121
// 3. third priority is the system preference
2222
// 4. lastly is the default light theme
23-
const darkModeSystemPreference = window?.matchMedia?.('(prefers-color-scheme: dark)')?.matches
24-
const darkModeAccountSetting = document.body.getAttribute('data-themes')?.includes('dark')
25-
const darkModeElementOverride = el.closest('[data-theme-dark]') !== null
26-
return darkModeElementOverride || darkModeAccountSetting || darkModeSystemPreference || false
23+
if (el.closest('[data-theme-dark]') !== null) {
24+
return true
25+
}
26+
27+
if (document.body.getAttribute('data-themes')?.includes('dark')) {
28+
return true
29+
}
30+
31+
if (window.matchMedia('(prefers-color-scheme: dark)')?.matches) {
32+
return true
33+
}
34+
35+
return false
2736
}
2837

2938
/**

0 commit comments

Comments
 (0)