Skip to content

Commit d0254b7

Browse files
authored
feat(site): the official website adds the function of dynamically switching between light and dark themes (#2911)
1 parent 885c111 commit d0254b7

File tree

5 files changed

+12
-3
lines changed

5 files changed

+12
-3
lines changed

examples/sites/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"github-markdown-css": "~5.1.0",
5353
"highlight.js": "^11.5.1",
5454
"marked": "^4.3.0",
55+
"@vueuse/core": "^12.7.0",
5556
"prismjs": "^1.28.0",
5657
"sortablejs": "1.15.0",
5758
"tailwindcss": "^3.2.4",

examples/sites/src/views/components-doc/components/demo.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ onBeforeUnmount(() => {
355355
}
356356
}
357357
// 暗黑主题
358-
:global(html.dark-theme .pc-demo-container) {
358+
:global(html.dark .pc-demo-container) {
359359
background: #000;
360360
}
361361

examples/sites/src/views/layout/layout.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
<div class="main-layout ti-hp100 ti-f-c ti-f-box-stretch">
33
<div class="content-layout ti-fi-1" :has-sider="!isFrame">
44
<div id="layoutSider" class="layout-sider" :class="{ 'saas-border': templateModeState.isSaas }" v-if="!isFrame">
5+
<div style="padding: 10px 0; text-align: center">
6+
<tiny-button :reset-time="0" type="info" @click="toggleDark()">{{ isDark ? 'dark' : 'light' }}</tiny-button>
7+
</div>
58
<tiny-tree-menu
69
ref="treeMenuRef"
710
class="main-menu"
@@ -65,6 +68,7 @@ import { getWord, i18nByKey, appData, appFn, useApiMode, useTemplateMode } from
6568
import useTheme from '@/tools/useTheme'
6669
import FloatSettings from '@/views/components-doc/components/float-settings.vue'
6770
import VersionTip from '@/views/components-doc/components/version-tip.vue'
71+
import { useDark, useToggle } from '@vueuse/core'
6872
6973
export default defineComponent({
7074
name: 'LayoutVue',
@@ -103,6 +107,8 @@ export default defineComponent({
103107
const getTo = (route, key) => `${import.meta.env.VITE_CONTEXT}${allPath}${lang}/${theme}/${route}${key}`
104108
105109
const isThemeSaas = import.meta.env.VITE_TINY_THEME === 'saas'
110+
const isDark = useDark()
111+
const toggleDark = useToggle(isDark)
106112
107113
const changeLanguage = () => {
108114
appFn.toggleLang()
@@ -191,6 +197,8 @@ export default defineComponent({
191197
getWord,
192198
i18nByKey,
193199
isThemeSaas,
200+
isDark,
201+
toggleDark,
194202
isShowFilter
195203
}
196204
}

packages/theme/src/base/dark-theme.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* prettier-ignore */
2-
:root {
2+
:root.dark {
33
/* 1.1品牌色 */
44

55
/* 品牌主色 */

packages/theme/src/base/index.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
@import './vars.less';
1515
// @import './old-theme.less';
1616
// @import './aurora-theme.less';
17-
// @import './dark-theme.less';
17+
@import './dark-theme.less';
1818
@import './transition.less';

0 commit comments

Comments
 (0)