Browse Source

feat: fallback to default theme if wrong theme provided

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/3368/head
mertmit 2 years ago
parent
commit
6fc82b70ed
  1. 19
      packages/nc-gui-v2/composables/useTheme/index.ts

19
packages/nc-gui-v2/composables/useTheme/index.ts

@ -1,5 +1,6 @@
import { ConfigProvider } from 'ant-design-vue' import { ConfigProvider } from 'ant-design-vue'
import type { Theme as AntTheme } from 'ant-design-vue/es/config-provider' import type { Theme as AntTheme } from 'ant-design-vue/es/config-provider'
import tinycolor from 'tinycolor2'
import { hexToRGB, themeV2Colors, useCssVar, useInjectionState, useProject } from '#imports' import { hexToRGB, themeV2Colors, useCssVar, useInjectionState, useProject } from '#imports'
interface ThemeConfig extends AntTheme { interface ThemeConfig extends AntTheme {
@ -50,14 +51,22 @@ const [setup, use] = useInjectionState((config?: Partial<ThemeConfig>) => {
/** set theme (persists in localstorage) */ /** set theme (persists in localstorage) */
function setTheme(theme: Partial<ThemeConfig>) { function setTheme(theme: Partial<ThemeConfig>) {
// convert hex colors to rgb values const themePrimary = tinycolor(theme.primaryColor)
if (theme.primaryColor) primaryColor.value = hexToRGB(theme.primaryColor) const themeAccent = tinycolor(theme.accentColor)
if (theme.accentColor) accentColor.value = hexToRGB(theme.accentColor)
currentTheme.value = theme as ThemeConfig // convert hex colors to rgb values
primaryColor.value = themePrimary.isValid()
? hexToRGB(themePrimary.toHex8String())
: hexToRGB(themeV2Colors['royal-blue'].DEFAULT)
accentColor.value = themeAccent.isValid() ? hexToRGB(themeAccent.toHex8String()) : hexToRGB(themeV2Colors.pink['500'])
currentTheme.value = {
primaryColor: themePrimary.toHex8String().toUpperCase(),
accentColor: themeAccent.toHex8String().toUpperCase(),
}
ConfigProvider.config({ ConfigProvider.config({
theme, theme: { ...currentTheme.value },
}) })
} }

Loading…
Cancel
Save