Skip to content

Commit 3387a22

Browse files
authored
fix(site): refactor the implementation mode of switch dark theme (#2995)
* fix(site): remove switch theme button * fix(site): fix some wrong colors * fix(site): add { allowDarkTheme:true } to TDCommon * fix(site): add mock button for switch theme * fix(site): fix reviews
1 parent 1d42970 commit 3387a22

File tree

11 files changed

+45
-74
lines changed

11 files changed

+45
-74
lines changed

examples/sites/public/static/js/design-common.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const headerHtml = `
2727
<span class="header-detail-name">TinyVue</span>
2828
2929
<div class="nav-menus nav-menus-left"></div>
30+
<button id="switchTheme" style="margin-left:150px">切换主题</button>
3031
</div>
3132
</div>
3233
</div>`
@@ -147,6 +148,10 @@ class DesignCommon {
147148
link.href = '/static/css/design-common.css'
148149
link.rel = 'stylesheet'
149150
document.head.append(link)
151+
152+
document.getElementById('switchTheme').addEventListener('click', () => {
153+
document.querySelector('html').classList.toggle('dark')
154+
})
150155
}
151156
renderFooter() {
152157
document.getElementById('footer').innerHTML = footerHtml

examples/sites/src/App.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default defineComponent({
3131
onMounted(() => {
3232
// 加载header
3333
const common = new window.TDCommon(['#header'], {
34+
allowDarkTheme: true,
3435
searchConfig: {
3536
show: true
3637
},

examples/sites/src/assets/custom-markdown.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,26 @@ body .markdown-body {
9595
--color-attention-subtle: #fff8c5;
9696
--color-danger-fg: #cf222e;
9797
}
98+
.markdown-body code {
99+
text-shadow: none !important;
100+
}
101+
102+
.dark.dark .markdown-body {
103+
background-color: #000;
104+
}
105+
106+
.dark.dark .markdown-body pre {
107+
background-color: #1a1a1a;
108+
}
109+
110+
.dark.dark .markdown-body code {
111+
color: var(--tv-color-text);
112+
113+
.token.operator {
114+
background-color: transparent;
115+
}
116+
117+
.hljs-string {
118+
color: #6f42c1;
119+
}
120+
}
Lines changed: 2 additions & 14 deletions
Loading

examples/sites/src/assets/markdown.less

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

examples/sites/src/main.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import '@unocss/reset/eric-meyer.css'
66
import 'prismjs/themes/prism.css'
77
import 'uno.css'
88

9-
// highlight默认样式
10-
import 'highlight.js/styles/default.css'
11-
129
// 只使用markdown的亮色主题
1310
import 'github-markdown-css/github-markdown.css'
1411
import './assets/index.less'
@@ -17,7 +14,6 @@ import './style.css'
1714
// 覆盖默认的github markdown样式
1815
import './assets/custom-markdown.css'
1916
import './assets/custom-block.less'
20-
import './assets/markdown.less'
2117
import './assets/md-preview.less'
2218

2319
import { i18n } from './i18n/index'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ watch(
162162
onMounted(() => {
163163
loadPage()
164164
// 加载公共尾部
165-
const common = new window.TDCommon(['#footer'], {})
165+
const common = new window.TDCommon(['#footer'], { allowDarkTheme: true })
166166
common.renderFooter()
167167
setScrollListener()
168168
})

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,6 @@ onBeforeUnmount(() => {
335335
}
336336
}
337337
338-
:global(.dark .pc-demo-container.pc-demo-container) {
339-
background-color: #1a1a1a;
340-
border: none;
341-
}
342338
.pc-demo-container {
343339
display: flex;
344340
flex-direction: column;
@@ -400,3 +396,14 @@ onBeforeUnmount(() => {
400396
padding: 20px 5px;
401397
}
402398
</style>
399+
400+
<style lang="less">
401+
.dark .pc-demo-container.pc-demo-container {
402+
background-color: #1a1a1a;
403+
border: none;
404+
}
405+
406+
.dark .demo-content.demo-content .demo-desc {
407+
color: #b3b3b3;
408+
}
409+
</style>

examples/sites/src/views/docs/docs.vue

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ watch([() => router.currentRoute.value, () => router.currentRoute.value.params.d
4848
4949
onMounted(() => {
5050
loadPage()
51-
const common = new window.TDCommon(['#footer'], {})
51+
const common = new window.TDCommon(['#footer'], { allowDarkTheme: true })
5252
common.renderFooter()
5353
})
5454
</script>
@@ -67,23 +67,6 @@ onMounted(() => {
6767
}
6868
}
6969
70-
.dark .docs-container .markdown-body {
71-
background-color: #000;
72-
}
73-
74-
.dark .docs-container .markdown-body pre {
75-
background-color: #1a1a1a;
76-
}
77-
78-
.dark .docs-container .markdown-body code {
79-
text-shadow: none;
80-
color: var(--tv-color-text);
81-
82-
.token.operator {
83-
background-color: transparent;
84-
}
85-
}
86-
8770
.docs-page-anchor {
8871
.tiny-anchor__affix {
8972
overflow-y: auto;

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
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>
85
<tiny-tree-menu
96
ref="treeMenuRef"
107
class="main-menu"
@@ -68,7 +65,6 @@ import { getWord, i18nByKey, appData, appFn, useApiMode, useTemplateMode } from
6865
import useTheme from '@/tools/useTheme'
6966
import FloatSettings from '@/views/components-doc/components/float-settings.vue'
7067
import VersionTip from '@/views/components-doc/components/version-tip.vue'
71-
import { useDark, useToggle } from '@vueuse/core'
7268
7369
export default defineComponent({
7470
name: 'LayoutVue',
@@ -107,8 +103,6 @@ export default defineComponent({
107103
const getTo = (route, key) => `${import.meta.env.VITE_CONTEXT}${allPath}${lang}/${theme}/${route}${key}`
108104
109105
const isThemeSaas = import.meta.env.VITE_TINY_THEME === 'saas'
110-
const isDark = useDark()
111-
const toggleDark = useToggle(isDark)
112106
113107
const changeLanguage = () => {
114108
appFn.toggleLang()
@@ -197,8 +191,6 @@ export default defineComponent({
197191
getWord,
198192
i18nByKey,
199193
isThemeSaas,
200-
isDark,
201-
toggleDark,
202194
isShowFilter
203195
}
204196
}

0 commit comments

Comments
 (0)