Browse Source

Merge pull request #4057 from nocodb/feat/default-theme

refactor(nc-gui): add default nocodb theme color to picker
pull/4061/head
mertmit 2 years ago committed by GitHub
parent
commit
f1bf4c81de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      packages/nc-gui/composables/useTheme/index.ts
  2. 9
      packages/nc-gui/pages/[projectType]/[projectId]/index.vue
  3. 2
      packages/nc-gui/utils/colorsUtils.ts

10
packages/nc-gui/composables/useTheme/index.ts

@ -6,12 +6,13 @@ import type { ThemeConfig } from '~/lib'
export const useTheme = createGlobalState((config?: Partial<ThemeConfig>) => { export const useTheme = createGlobalState((config?: Partial<ThemeConfig>) => {
const primaryColor = useCssVar('--color-primary', typeof document !== 'undefined' ? document.documentElement : null) const primaryColor = useCssVar('--color-primary', typeof document !== 'undefined' ? document.documentElement : null)
const accentColor = useCssVar('--color-accent', typeof document !== 'undefined' ? document.documentElement : null) const accentColor = useCssVar('--color-accent', typeof document !== 'undefined' ? document.documentElement : null)
const defaultTheme = {
/** current theme config */
const currentTheme = ref({
primaryColor: themeV2Colors['royal-blue'].DEFAULT, primaryColor: themeV2Colors['royal-blue'].DEFAULT,
accentColor: themeV2Colors.pink['500'], accentColor: themeV2Colors.pink['500'],
}) }
/** current theme config */
const currentTheme = ref(defaultTheme)
/** set initial config */ /** set initial config */
setTheme(config ?? currentTheme.value) setTheme(config ?? currentTheme.value)
@ -40,5 +41,6 @@ export const useTheme = createGlobalState((config?: Partial<ThemeConfig>) => {
return { return {
theme: currentTheme, theme: currentTheme,
setTheme, setTheme,
defaultTheme,
} }
}) })

9
packages/nc-gui/pages/[projectType]/[projectId]/index.vue

@ -29,7 +29,7 @@ definePageMeta({
hideHeader: true, hideHeader: true,
}) })
const { theme } = useTheme() const { theme, defaultTheme } = useTheme()
const { t } = useI18n() const { t } = useI18n()
@ -71,9 +71,13 @@ function toggleDialog(value?: boolean, key?: string) {
openDialogKey.value = key openDialogKey.value = key
} }
const handleThemeColor = async (mode: 'swatch' | 'primary' | 'accent', color: string) => { const handleThemeColor = async (mode: 'swatch' | 'primary' | 'accent', color?: string) => {
switch (mode) { switch (mode) {
case 'swatch': { case 'swatch': {
if (color === defaultTheme.primaryColor) {
return await saveTheme(defaultTheme)
}
const tcolor = tinycolor(color) const tcolor = tinycolor(color)
if (tcolor.isValid()) { if (tcolor.isValid()) {
const complement = tcolor.complement() const complement = tcolor.complement()
@ -338,6 +342,7 @@ onBeforeUnmount(reset)
:colors="projectThemeColors" :colors="projectThemeColors"
:row-size="9" :row-size="9"
:advanced="false" :advanced="false"
class="rounded-t"
@input="handleThemeColor('swatch', $event)" @input="handleThemeColor('swatch', $event)"
/> />

2
packages/nc-gui/utils/colorsUtils.ts

@ -85,6 +85,7 @@ export const hexToRGB = (hex: string) => {
} }
export const projectThemeColors = [ export const projectThemeColors = [
themeV2Colors['royal-blue'].DEFAULT,
'#2D7FF9', '#2D7FF9',
'#18BFFF', '#18BFFF',
'#60DAD5', '#60DAD5',
@ -93,7 +94,6 @@ export const projectThemeColors = [
'#F57134', '#F57134',
'#1BAF2C', '#1BAF2C',
'#8B46FF', '#8B46FF',
'#666666',
'#1B51A2', '#1B51A2',
'#146C8E', '#146C8E',
'#24716E', '#24716E',

Loading…
Cancel
Save