Skip to content

Commit d565439

Browse files
authored
[ADDED] button to toggle dark mode (#247)
* [ADDED] button to toggle styles * [REMOVED] media query from base.css
1 parent fac641f commit d565439

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

console/atest-ui/src/App.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,16 @@ import { DefaultResponseProcess } from './views/net'
1515
import { useI18n } from 'vue-i18n'
1616
import ClientMonitor from 'skywalking-client-js';
1717
18+
import setTheme from './theme'
19+
1820
const { t } = useI18n()
1921
22+
23+
function switchAppMode()
24+
{
25+
setTheme(appMode.value)
26+
}
27+
2028
interface Tree {
2129
id: string
2230
label: string
@@ -116,6 +124,7 @@ interface Store {
116124
}
117125
118126
const stores = ref([] as Store[])
127+
const appMode = ref(false)
119128
function loadStores() {
120129
const requestOptions = {
121130
method: 'POST',
@@ -298,6 +307,10 @@ watch(viewName, (val) => {
298307
<el-header style="height: 30px;justify-content: flex-end;">
299308
<el-button type="primary" :icon="Edit" @click="viewName = 'secret'" data-intro="Manage the secrets."/>
300309
<el-button type="primary" :icon="Share" @click="viewName = 'store'" data-intro="Manage the store backends." />
310+
<el-form-item label="Dark Mode" style="margin-left:20px;">
311+
<el-switch type="primary" data-intro="Switch light and dark modes" v-model="appMode" @click="switchAppMode"/>
312+
</el-form-item>
313+
301314
</el-header>
302315

303316
<el-main>
@@ -460,6 +473,7 @@ nav {
460473
margin-top: 2rem;
461474
}
462475
476+
463477
nav a.router-link-exact-active {
464478
color: var(--color-text);
465479
}

console/atest-ui/src/assets/base.css

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,6 @@
3636
--section-gap: 160px;
3737
}
3838

39-
@media (prefers-color-scheme: dark) {
40-
:root {
41-
--color-background: var(--vt-c-black);
42-
--color-background-soft: var(--vt-c-black-soft);
43-
--color-background-mute: var(--vt-c-black-mute);
44-
45-
--color-border: var(--vt-c-divider-dark-2);
46-
--color-border-hover: var(--vt-c-divider-dark-1);
47-
48-
--color-heading: var(--vt-c-text-dark-1);
49-
--color-text: var(--vt-c-text-dark-2);
50-
}
51-
}
52-
5339
*,
5440
*::before,
5541
*::after {

console/atest-ui/src/theme.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const lightTheme: { [k: string]: string } = {
2+
'--color-background': 'var(--vt-c-white)',
3+
'--color-background-soft': 'var(--vt-c-white-soft)',
4+
'--color-background-mute': 'var(--vt-c-white-mute)',
5+
'--color-border': 'var(--vt-c-divider-light-2)',
6+
'--color-border-hover': 'var(--vt-c-divider-light-1)',
7+
'--color-heading': 'var(--vt-c-text-light-1)',
8+
'--color-text': 'var(--vt-c-text-light-1)'
9+
}
10+
11+
const darkTheme: { [k: string]: string } = {
12+
'--color-background': 'var(--vt-c-black)',
13+
'--color-background-soft': 'var(--vt-c-black-soft)',
14+
'--color-background-mute': 'var(--vt-c-black-mute)',
15+
'--color-border': 'var(--vt-c-divider-dark-2)',
16+
'--color-border-hover': 'var(--vt-c-divider-dark-1)',
17+
'--color-heading': 'var(--vt-c-text-dark-1)',
18+
'--color-text': 'var(--vt-c-text-dark-2)'
19+
}
20+
21+
22+
export default function setTheme(darkMode: boolean) {
23+
const theme = darkMode ? darkTheme : lightTheme
24+
Object.keys(theme).forEach((key) => {
25+
document.documentElement.style.setProperty(key, theme[key])
26+
})
27+
}

0 commit comments

Comments
 (0)