From f7d68ee7dad498b0c83330463da2257adcce2de5 Mon Sep 17 00:00:00 2001 From: Alexey Zinoviev Date: Sat, 29 Jul 2023 13:20:40 +0400 Subject: [PATCH] uber-642: use system theme as the default value for application theme (#3534) Signed-off-by: Alexey Zinoviev --- packages/theme/src/index.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/theme/src/index.ts b/packages/theme/src/index.ts index 915aa1bf65..fe50f64036 100644 --- a/packages/theme/src/index.ts +++ b/packages/theme/src/index.ts @@ -27,10 +27,18 @@ export const setDefaultLanguage = (language: string): void => { } } +function isSystemThemeDark (): boolean { + return window.matchMedia('(prefers-color-scheme: dark)').matches +} + +function getDefaultTheme (): string { + return isSystemThemeDark() ? 'theme-dark' : 'theme-light' +} + /** * @public */ -export const getCurrentTheme = (): string => localStorage.getItem('theme') ?? 'theme-dark' +export const getCurrentTheme = (): string => localStorage.getItem('theme') ?? getDefaultTheme() /** * @public */