Skip to content

Commit c22750f

Browse files
committed
Make light as default theme
Fixes #111
1 parent 8722696 commit c22750f

File tree

7 files changed

+23
-13
lines changed

7 files changed

+23
-13
lines changed

src/App.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,18 @@ watch(() => layout.activeLanguage, () => {
3131
}, {
3232
immediate: true,
3333
})
34+
35+
watch(() => layout.isDark, (newValue) => {
36+
if (newValue)
37+
document.documentElement.classList.add('dark')
38+
else
39+
document.documentElement.classList.remove('dark')
40+
}, { immediate: true })
3441
</script>
3542

3643
<template>
3744
<n-config-provider
38-
:theme="isDark ? darkTheme : lightTheme" :theme-overrides="themeOverrides"
45+
:theme="layout.isDark ? darkTheme : lightTheme" :theme-overrides="themeOverrides"
3946
:rtl="layout.isRtl ? rtlStyles : []" :preflight-style-disabled="false"
4047
>
4148
<n-notification-provider placement="bottom-right">

src/auto-imports.d.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ declare global {
4747
const ignorableWatch: typeof import('@vueuse/core')['ignorableWatch']
4848
const inject: typeof import('vue')['inject']
4949
const injectLocal: typeof import('@vueuse/core')['injectLocal']
50-
const isDark: typeof import('./composables/dark')['isDark']
5150
const isDefined: typeof import('@vueuse/core')['isDefined']
5251
const isProxy: typeof import('vue')['isProxy']
5352
const isReactive: typeof import('vue')['isReactive']
@@ -372,7 +371,6 @@ declare module 'vue' {
372371
readonly ignorableWatch: UnwrapRef<typeof import('@vueuse/core')['ignorableWatch']>
373372
readonly inject: UnwrapRef<typeof import('vue')['inject']>
374373
readonly injectLocal: UnwrapRef<typeof import('@vueuse/core')['injectLocal']>
375-
readonly isDark: UnwrapRef<typeof import('./composables/dark')['isDark']>
376374
readonly isDefined: UnwrapRef<typeof import('@vueuse/core')['isDefined']>
377375
readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']>
378376
readonly isReactive: UnwrapRef<typeof import('vue')['isReactive']>
@@ -433,7 +431,6 @@ declare module 'vue' {
433431
readonly toRef: UnwrapRef<typeof import('vue')['toRef']>
434432
readonly toRefs: UnwrapRef<typeof import('vue')['toRefs']>
435433
readonly toValue: UnwrapRef<typeof import('vue')['toValue']>
436-
readonly toggleDark: UnwrapRef<typeof import('./composables/dark')['toggleDark']>
437434
readonly triggerRef: UnwrapRef<typeof import('vue')['triggerRef']>
438435
readonly tryOnBeforeMount: UnwrapRef<typeof import('@vueuse/core')['tryOnBeforeMount']>
439436
readonly tryOnBeforeUnmount: UnwrapRef<typeof import('@vueuse/core')['tryOnBeforeUnmount']>

src/components.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ declare module 'vue' {
3434
NBreadcrumb: typeof import('naive-ui')['NBreadcrumb']
3535
NBreadcrumbItem: typeof import('naive-ui')['NBreadcrumbItem']
3636
NButton: typeof import('naive-ui')['NButton']
37+
NCard: typeof import('naive-ui')['NCard']
3738
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
3839
NDataTable: typeof import('naive-ui')['NDataTable']
3940
NDialogProvider: typeof import('naive-ui')['NDialogProvider']
4041
NDrawer: typeof import('naive-ui')['NDrawer']
4142
NDrawerContent: typeof import('naive-ui')['NDrawerContent']
4243
NDropdown: typeof import('naive-ui')['NDropdown']
44+
NDynamicTags: typeof import('naive-ui')['NDynamicTags']
4345
NForm: typeof import('naive-ui')['NForm']
4446
NFormItem: typeof import('naive-ui')['NFormItem']
4547
NIcon: typeof import('naive-ui')['NIcon']
@@ -49,13 +51,17 @@ declare module 'vue' {
4951
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
5052
NMenu: typeof import('naive-ui')['NMenu']
5153
NMessageProvider: typeof import('naive-ui')['NMessageProvider']
54+
NModal: typeof import('naive-ui')['NModal']
5255
NNotificationProvider: typeof import('naive-ui')['NNotificationProvider']
5356
Notifications: typeof import('./components/Notifications.vue')['default']
5457
NPageHeader: typeof import('naive-ui')['NPageHeader']
5558
NPopselect: typeof import('naive-ui')['NPopselect']
59+
NSelect: typeof import('naive-ui')['NSelect']
5660
NSpace: typeof import('naive-ui')['NSpace']
61+
NSwitch: typeof import('naive-ui')['NSwitch']
5762
NTooltip: typeof import('naive-ui')['NTooltip']
5863
NTreeSelect: typeof import('naive-ui')['NTreeSelect']
64+
NUpload: typeof import('naive-ui')['NUpload']
5965
OrderManagement: typeof import('./components/Orders/OrderManagement.vue')['default']
6066
PersianIcon: typeof import('./components/CountryIcons/PersianIcon.vue')['default']
6167
ProductsManagement: typeof import('./components/Products/ProductsManagement.vue')['default']

src/components/ThemeSwitch.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import {
44
WeatherSunny48Regular as SunIcon,
55
} from '@vicons/fluent'
66
7-
const layoutStore = useLayoutStore()
7+
const layout = useLayoutStore()
88
</script>
99

1010
<template>
1111
<div v-bind="$attrs">
12-
<n-button quaternary circle @click="layoutStore.toggleTheme()">
12+
<n-button quaternary circle @click="layout.toggleTheme()">
1313
<template #icon>
1414
<NIcon size="1.4rem">
15-
<SunIcon v-if="isDark" />
15+
<SunIcon v-if="layout.isDark" />
1616
<MoonIcon v-else />
1717
</NIcon>
1818
</template>

src/composables/dark.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/store/layout.store.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ export const useLayoutStore = defineStore('layout', () => {
77
const isRtl = ref(false)
88
const { t, locale } = useI18n()
99

10+
const isDark = ref(false)
11+
1012
watch(() => useWindowSize().width.value, (newValue: number) => {
1113
forceCollapsed.value = newValue < 1000
1214
})
15+
1316
function toggleSidebar() {
1417
collapsed.value = !collapsed.value
1518
}
1619

1720
function toggleTheme() {
18-
toggleDark()
21+
isDark.value = !isDark.value
1922
}
2023

2124
function changeLanguage(lang: string) {
@@ -33,6 +36,7 @@ export const useLayoutStore = defineStore('layout', () => {
3336
activeLanguage,
3437
changeLanguage,
3538
forceCollapsed,
39+
isDark,
3640
}
3741
}, { persist: true })
3842

vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export default defineConfig({
142142
// }),
143143

144144
// https://github.com/webfansplz/vite-plugin-vue-devtools
145-
VueDevTools(),
145+
// VueDevTools(),
146146
],
147147

148148
// https://github.com/vitest-dev/vitest

0 commit comments

Comments
 (0)