fix(projects): fix update theme color
This commit is contained in:
parent
b7f0749170
commit
27c53cd688
@ -3,6 +3,7 @@ import { getColorName } from './name';
|
|||||||
import type { ColorPalette, ColorPaletteFamily, ColorPaletteItem, ColorPaletteNumber } from './type';
|
import type { ColorPalette, ColorPaletteFamily, ColorPaletteItem, ColorPaletteNumber } from './type';
|
||||||
import defaultPalettes from './json/palette.json';
|
import defaultPalettes from './json/palette.json';
|
||||||
|
|
||||||
|
// to do: there is a bug in the code below, when the color is '#1c5cff', the colorPaletteFamily is not similar to the provided color
|
||||||
/**
|
/**
|
||||||
* Get color palette by provided color and color name
|
* Get color palette by provided color and color name
|
||||||
*
|
*
|
||||||
|
@ -2,6 +2,7 @@ import { computed, effectScope, onScopeDispose, ref, toRefs, watch } from 'vue';
|
|||||||
import type { Ref } from 'vue';
|
import type { Ref } from 'vue';
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { useEventListener, usePreferredColorScheme } from '@vueuse/core';
|
import { useEventListener, usePreferredColorScheme } from '@vueuse/core';
|
||||||
|
import { getColorPalette } from '@sa/color-palette';
|
||||||
import { SetupStoreId } from '@/enum';
|
import { SetupStoreId } from '@/enum';
|
||||||
import { localStg } from '@/utils/storage';
|
import { localStg } from '@/utils/storage';
|
||||||
import { addThemeVarsToHtml, createThemeToken, getNaiveTheme, initThemeSettings, toggleCssDarkMode } from './shared';
|
import { addThemeVarsToHtml, createThemeToken, getNaiveTheme, initThemeSettings, toggleCssDarkMode } from './shared';
|
||||||
@ -79,10 +80,15 @@ export const useThemeStore = defineStore(SetupStoreId.Theme, () => {
|
|||||||
* @param color Theme color
|
* @param color Theme color
|
||||||
*/
|
*/
|
||||||
function updateThemeColors(key: App.Theme.ThemeColorKey, color: string) {
|
function updateThemeColors(key: App.Theme.ThemeColorKey, color: string) {
|
||||||
|
// get a color palette by provided color and color name, and use the suitable color
|
||||||
|
const colorPalette = getColorPalette(color, key);
|
||||||
|
|
||||||
|
const mainColor = colorPalette.main.hexcode;
|
||||||
|
|
||||||
if (key === 'primary') {
|
if (key === 'primary') {
|
||||||
settings.value.themeColor = color;
|
settings.value.themeColor = mainColor;
|
||||||
} else {
|
} else {
|
||||||
settings.value.otherColor[key] = color;
|
settings.value.otherColor[key] = mainColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user