Skip to content

Commit

Permalink
feat(projects): add switch for customize darkmode transition
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Jun 20, 2023
1 parent d3ebe95 commit 6e0cce4
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/components/common/dark-mode-switch.vue
Expand Up @@ -13,6 +13,8 @@ defineOptions({ name: 'DarkModeSwitch' });
interface Props {
/** 暗黑模式 */
dark?: boolean;
/** 自定义暗黑模式动画过渡 */
customizeTransition?: boolean;
}
const props = withDefaults(defineProps<Props>(), {
Expand All @@ -38,7 +40,7 @@ async function handleSwitch(event: MouseEvent) {
const x = event.clientX;
const y = event.clientY;
if (!document.startViewTransition) {
if (!props.customizeTransition || !document.startViewTransition) {
darkMode.value = !darkMode.value;
return;
}
Expand Down
7 changes: 6 additions & 1 deletion src/layouts/common/global-header/components/theme-mode.vue
@@ -1,6 +1,11 @@
<template>
<hover-container class="w-40px" :inverted="theme.header.inverted" tooltip-content="主题模式">
<dark-mode-switch :dark="theme.darkMode" class="wh-full" @update:dark="theme.setDarkMode" />
<dark-mode-switch
:dark="theme.darkMode"
:customize-transition="theme.isCustomizeDarkModeTransition"
class="wh-full"
@update:dark="theme.setDarkMode"
/>
</hover-container>
</template>

Expand Down
10 changes: 10 additions & 0 deletions src/layouts/common/setting-drawer/components/dark-mode/index.vue
Expand Up @@ -21,6 +21,16 @@
</template>
</n-switch>
</setting-menu>
<setting-menu label="自定义暗黑主题动画过渡">
<n-switch :value="theme.isCustomizeDarkModeTransition" @update:value="theme.setIsCustomizeDarkModeTransition">
<template #checked>
<icon-ic-baseline-do-not-disturb class="text-14px text-white" />
</template>
<template #unchecked>
<icon-ic-round-hdr-auto class="text-14px text-white" />
</template>
</n-switch>
</setting-menu>
<setting-menu label="侧边栏深色">
<n-switch :value="theme.sider.inverted" @update:value="theme.setSiderInverted" />
</setting-menu>
Expand Down
1 change: 1 addition & 0 deletions src/settings/theme.json
@@ -1,6 +1,7 @@
{
"darkMode": false,
"followSystemTheme": true,
"isCustomizeDarkModeTransition": false,
"layout": {
"minWidth": 900,
"mode": "vertical",
Expand Down
1 change: 1 addition & 0 deletions src/settings/theme.ts
Expand Up @@ -37,6 +37,7 @@ const themeColorList = [
const defaultThemeSetting: Theme.Setting = {
darkMode: false,
followSystemTheme: true,
isCustomizeDarkModeTransition: false,
layout: {
minWidth: 900,
mode: 'vertical',
Expand Down
4 changes: 4 additions & 0 deletions src/store/modules/theme/index.ts
Expand Up @@ -43,6 +43,10 @@ export const useThemeStore = defineStore('theme-store', {
setFollowSystemTheme(visible: boolean) {
this.followSystemTheme = visible;
},
/** 设置自动跟随系统主题 */
setIsCustomizeDarkModeTransition(isCustomize: boolean) {
this.isCustomizeDarkModeTransition = isCustomize;
},
/** 自动跟随系统主题 */
setAutoFollowSystemMode(darkMode: boolean) {
if (this.followSystemTheme) {
Expand Down
2 changes: 2 additions & 0 deletions src/typings/system.d.ts
Expand Up @@ -90,6 +90,8 @@ declare namespace Theme {
darkMode: boolean;
/** 是否自动跟随系统主题 */
followSystemTheme: boolean;
/** 自定义暗黑动画过渡 */
isCustomizeDarkModeTransition: boolean;
/** 布局样式 */
layout: Layout;
/** 滚动模式 */
Expand Down

1 comment on commit 6e0cce4

@vercel
Copy link

@vercel vercel bot commented on 6e0cce4 Jun 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.