This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support customize theme (#259)
* chore: test themeOverrides * chore: test useThemeVars * Revert "chore: test useThemeVars" This reverts commit 2596afa. * generate colors * chore: unocss colors * chore: set cssVar * chore: 颜色生成 * chore: 获取css变量值 * chore: theme store * chore: remove theme logics * chore: apply theme overrides * chore: generate colors * chore: 添加注释 * chore: 将组件库相关逻辑抽离到app.vue中 * chore: update ThemeColorConfig * chore: remove @ant-design/colors
- Loading branch information
Showing
10 changed files
with
246 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { defineStore } from 'pinia' | ||
import { ThemeEnum } from '@vben/constants' | ||
|
||
interface ThemeColorConfig { | ||
primaryColor: string //主题色 | ||
infoColor: string //信息色 | ||
successColor: string //成功色 | ||
warningColor: string //警告色 | ||
errorColor: string //错误色 | ||
textBaseColor: string //文本色 | ||
bgBaseColor: string //背景色 | ||
} | ||
|
||
interface ThemeStoreState { | ||
themeConfig: ThemeColorConfig | ||
theme: ThemeEnum | ||
} | ||
|
||
export const useThemeStore = defineStore({ | ||
id: 'APP_THEME', | ||
state: (): ThemeStoreState => ({ | ||
themeConfig: { | ||
primaryColor: '#2a64d4', | ||
infoColor: '#2080F0', | ||
successColor: '#52c41a', | ||
warningColor: '#faad14', | ||
errorColor: '#D03050', | ||
textBaseColor: '#000000', | ||
bgBaseColor: '#ffffff', | ||
}, | ||
theme: ThemeEnum.LIGHT, | ||
}), | ||
getters: { | ||
getThemeConfig(state) { | ||
return state.themeConfig | ||
}, | ||
getTheme(state) { | ||
return state.theme | ||
}, | ||
}, | ||
actions: { | ||
setTheme(value: ThemeEnum) { | ||
this.theme = value | ||
}, | ||
setThemeConfig(config: Partial<ThemeColorConfig>) { | ||
this.themeConfig = { ...this.themeConfig, ...config } | ||
}, | ||
}, | ||
persist: true, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,10 @@ | ||
<script lang="ts" setup name="VbenConfig"> | ||
import { maps } from '#/index' | ||
import { computed, unref } from 'vue' | ||
import { useAppTheme } from '@vben/hooks' | ||
import { ThemeEnum } from '@vben/constants' | ||
const Config = maps.get('Config') | ||
const darkTheme = maps.get('DarkTheme') | ||
const props = defineProps({ | ||
// Customize the configuration theme mode | ||
themeMode: { | ||
type: String, | ||
default: 'dark' | ||
}, | ||
// Whether to inherit the theme | ||
inherit: { | ||
type: Boolean, | ||
default: true | ||
} | ||
}) | ||
const { isDark } = useAppTheme() | ||
const appTheme = computed(() => { | ||
if (!props.inherit){ | ||
return props.themeMode === ThemeEnum.DARK ? darkTheme : null | ||
} | ||
return unref(isDark) ? darkTheme : null | ||
}) | ||
const Config = maps.get('Config') | ||
</script> | ||
<template> | ||
<Config v-bind="$attrs" abstract :theme="appTheme"> <slot></slot></Config> | ||
<Config abstract v-bind="$attrs"> <slot></slot></Config> | ||
</template> | ||
|
||
<style scoped></style> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.