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. 17
      packages/nc-gui-v2/composables/useTheme/index.ts

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

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

Loading…
Cancel
Save