Skip to content

Commit

Permalink
fix(projects): fix update theme color
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Apr 15, 2024
1 parent b7f0749 commit 27c53cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/color-palette/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getColorName } from './name';
import type { ColorPalette, ColorPaletteFamily, ColorPaletteItem, ColorPaletteNumber } from './type';
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
*
Expand Down
10 changes: 8 additions & 2 deletions src/store/modules/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { computed, effectScope, onScopeDispose, ref, toRefs, watch } from 'vue';
import type { Ref } from 'vue';
import { defineStore } from 'pinia';
import { useEventListener, usePreferredColorScheme } from '@vueuse/core';
import { getColorPalette } from '@sa/color-palette';
import { SetupStoreId } from '@/enum';
import { localStg } from '@/utils/storage';
import { addThemeVarsToHtml, createThemeToken, getNaiveTheme, initThemeSettings, toggleCssDarkMode } from './shared';
Expand Down Expand Up @@ -79,10 +80,15 @@ export const useThemeStore = defineStore(SetupStoreId.Theme, () => {
* @param color Theme color
*/
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') {
settings.value.themeColor = color;
settings.value.themeColor = mainColor;
} else {
settings.value.otherColor[key] = color;
settings.value.otherColor[key] = mainColor;
}
}

Expand Down

0 comments on commit 27c53cd

Please sign in to comment.