From ccd430bf0c62f2a2a706a0c0f4d2bdfa2e62c8e7 Mon Sep 17 00:00:00 2001 From: Kee Jefferys Date: Tue, 24 Oct 2023 13:37:42 +1100 Subject: [PATCH] fix: commit untracked theme.ts --- ts/util/theme.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 ts/util/theme.ts diff --git a/ts/util/theme.ts b/ts/util/theme.ts new file mode 100644 index 000000000..e2fdd609b --- /dev/null +++ b/ts/util/theme.ts @@ -0,0 +1,18 @@ +import { ThemeStateType } from '../themes/constants/colors'; + +export function getOppositeTheme(themeName: string): ThemeStateType { + if (themeName.includes('dark')) { + return themeName.replace('dark', 'light') as ThemeStateType; + } + if (themeName.includes('light')) { + return themeName.replace('light', 'dark') as ThemeStateType; + } + // If neither 'dark' nor 'light' is in the theme name, return the original theme name. + return themeName as ThemeStateType; +} + +export function isThemeMismatched(themeName: string, prefersDark: boolean): boolean { + const isLightTheme = themeName.includes('light'); + const isDarkTheme = themeName.includes('dark'); + return (prefersDark && isLightTheme) || (!prefersDark && isDarkTheme); +}