Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADDED] button to toggle dark mode #247

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions console/atest-ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@ import { DefaultResponseProcess } from './views/net'
import { useI18n } from 'vue-i18n'
import ClientMonitor from 'skywalking-client-js';
import setTheme from './theme'
const { t } = useI18n()
function switchAppMode()
{
setTheme(appMode.value)
}
interface Tree {
id: string
label: string
Expand Down Expand Up @@ -116,6 +124,7 @@ interface Store {
}
const stores = ref([] as Store[])
const appMode = ref(false)
function loadStores() {
const requestOptions = {
method: 'POST',
Expand Down Expand Up @@ -298,6 +307,10 @@ watch(viewName, (val) => {
<el-header style="height: 30px;justify-content: flex-end;">
<el-button type="primary" :icon="Edit" @click="viewName = 'secret'" data-intro="Manage the secrets."/>
<el-button type="primary" :icon="Share" @click="viewName = 'store'" data-intro="Manage the store backends." />
<el-form-item label="Dark Mode" style="margin-left:20px;">
<el-switch type="primary" data-intro="Switch light and dark modes" v-model="appMode" @click="switchAppMode"/>
</el-form-item>

</el-header>

<el-main>
Expand Down Expand Up @@ -460,6 +473,7 @@ nav {
margin-top: 2rem;
}
nav a.router-link-exact-active {
color: var(--color-text);
}
Expand Down
14 changes: 0 additions & 14 deletions console/atest-ui/src/assets/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,6 @@
--section-gap: 160px;
}

@media (prefers-color-scheme: dark) {
:root {
--color-background: var(--vt-c-black);
--color-background-soft: var(--vt-c-black-soft);
--color-background-mute: var(--vt-c-black-mute);

--color-border: var(--vt-c-divider-dark-2);
--color-border-hover: var(--vt-c-divider-dark-1);

--color-heading: var(--vt-c-text-dark-1);
--color-text: var(--vt-c-text-dark-2);
}
}

*,
*::before,
*::after {
Expand Down
27 changes: 27 additions & 0 deletions console/atest-ui/src/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const lightTheme: { [k: string]: string } = {
'--color-background': 'var(--vt-c-white)',
'--color-background-soft': 'var(--vt-c-white-soft)',
'--color-background-mute': 'var(--vt-c-white-mute)',
'--color-border': 'var(--vt-c-divider-light-2)',
'--color-border-hover': 'var(--vt-c-divider-light-1)',
'--color-heading': 'var(--vt-c-text-light-1)',
'--color-text': 'var(--vt-c-text-light-1)'
}

const darkTheme: { [k: string]: string } = {
'--color-background': 'var(--vt-c-black)',
'--color-background-soft': 'var(--vt-c-black-soft)',
'--color-background-mute': 'var(--vt-c-black-mute)',
'--color-border': 'var(--vt-c-divider-dark-2)',
'--color-border-hover': 'var(--vt-c-divider-dark-1)',
'--color-heading': 'var(--vt-c-text-dark-1)',
'--color-text': 'var(--vt-c-text-dark-2)'
}


export default function setTheme(darkMode: boolean) {
const theme = darkMode ? darkTheme : lightTheme
Object.keys(theme).forEach((key) => {
document.documentElement.style.setProperty(key, theme[key])
})
}
Loading