Skip to content

Commit 27c53cd

Browse files
committed
fix(projects): fix update theme color
1 parent b7f0749 commit 27c53cd

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/color-palette/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { getColorName } from './name';
33
import type { ColorPalette, ColorPaletteFamily, ColorPaletteItem, ColorPaletteNumber } from './type';
44
import defaultPalettes from './json/palette.json';
55

6+
// to do: there is a bug in the code below, when the color is '#1c5cff', the colorPaletteFamily is not similar to the provided color
67
/**
78
* Get color palette by provided color and color name
89
*

src/store/modules/theme/index.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { computed, effectScope, onScopeDispose, ref, toRefs, watch } from 'vue';
22
import type { Ref } from 'vue';
33
import { defineStore } from 'pinia';
44
import { useEventListener, usePreferredColorScheme } from '@vueuse/core';
5+
import { getColorPalette } from '@sa/color-palette';
56
import { SetupStoreId } from '@/enum';
67
import { localStg } from '@/utils/storage';
78
import { addThemeVarsToHtml, createThemeToken, getNaiveTheme, initThemeSettings, toggleCssDarkMode } from './shared';
@@ -79,10 +80,15 @@ export const useThemeStore = defineStore(SetupStoreId.Theme, () => {
7980
* @param color Theme color
8081
*/
8182
function updateThemeColors(key: App.Theme.ThemeColorKey, color: string) {
83+
// get a color palette by provided color and color name, and use the suitable color
84+
const colorPalette = getColorPalette(color, key);
85+
86+
const mainColor = colorPalette.main.hexcode;
87+
8288
if (key === 'primary') {
83-
settings.value.themeColor = color;
89+
settings.value.themeColor = mainColor;
8490
} else {
85-
settings.value.otherColor[key] = color;
91+
settings.value.otherColor[key] = mainColor;
8692
}
8793
}
8894

0 commit comments

Comments
 (0)