Skip to content

Commit 8680f7d

Browse files
author
Hoang Nguyen
authored
UI: Dark mode toggle button on Management Server (#5052)
* add button toggle dark mode * switch components corresponding to dark mode * restructure the style dark mode file * fix collapse & login page * fix test failed * fix dark mode styles by refer antd pro * fix disabled colors of button, input,... & refactor file dark mode styles * add setting drawer and save it into local storage * add an alert for save the setting * add `cursor: pointer` * hide drawer when init * change id name of svg icon * fix after merged 4.15 * edit active color menu item * fix plaholder color, project chart color & reset setting * fix event change color picker & error input focus color * fix empty data color
1 parent fb0dedc commit 8680f7d

67 files changed

Lines changed: 2292 additions & 346 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ui/public/locales/en.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@
595595
"label.copy": "Copy",
596596
"label.copy.clipboard": "Copy to clipboard",
597597
"label.copy.text": "Copy Text",
598+
"label.copy.setting.success": "Copy success, Please replace theme setting in public/config.js",
598599
"label.copyid": "Copy ID",
599600
"label.copying.iso": "Copying ISO",
600601
"label.corrections.saved": "Corrections saved",
@@ -646,6 +647,7 @@
646647
"label.daily": "Daily",
647648
"label.dashboard": "Dashboard",
648649
"label.dashboard.endpoint": "Dashboard endpoint",
650+
"label.dark.mode": "Dark mode",
649651
"label.data.disk": "Data Disk",
650652
"label.data.disk.offering": "Data Disk Offering",
651653
"label.date": "Date",
@@ -1788,6 +1790,7 @@
17881790
"label.reservedsystemnetmask": "Reserved system netmask",
17891791
"label.reservedsystemstartip": "Start Reserved system IP",
17901792
"label.reset": "Reset",
1793+
"label.reset.to.default": "Reset to default",
17911794
"label.reset.ssh.key.pair": "Reset SSH Key Pair",
17921795
"label.reset.ssh.key.pair.on.vm": "Reset SSH Key Pair on VM",
17931796
"label.reset.vpn.connection": "Reset VPN connection",
@@ -1856,6 +1859,7 @@
18561859
"label.save.and.continue": "Save and continue",
18571860
"label.save.changes": "Save changes",
18581861
"label.save.new.rule": "Save new Rule",
1862+
"label.save.setting": "Save setting",
18591863
"label.saving.processing": "Saving....",
18601864
"label.scale.vm": "Scale VM",
18611865
"label.scale.up.policy": "SCALE UP POLICY",
@@ -2102,9 +2106,28 @@
21022106
"label.templatetype": "Template Type",
21032107
"label.tftp.dir": "TFTP Directory",
21042108
"label.tftpdir": "Tftp root directory",
2109+
"label.theme.alert": "The settings panel is only visible in the development environment, please save for the changes to take effect.",
2110+
"label.theme.color": "Theme Color",
2111+
"label.theme.cyan": "Cyan",
2112+
"label.theme.dark": "Dark Style",
2113+
"label.theme.daybreak.blue": "Daybreak Blue",
21052114
"label.theme.default": "Default Theme",
2115+
"label.theme.dust.red": "Dust Red",
2116+
"label.theme.geek.blue": "Geek Blue",
2117+
"label.theme.golden.purple": "Golden Purple",
21062118
"label.theme.grey": "Custom - Grey",
2119+
"label.theme.light": "Light Style",
21072120
"label.theme.lightblue": "Custom - Light Blue",
2121+
"label.theme.navigation.bgColor": "Background Color",
2122+
"label.theme.navigation.setting": "Navigation setting",
2123+
"label.theme.navigation.txtColor": "Text Color",
2124+
"label.theme.page.style.setting": "Page style setting",
2125+
"label.theme.polar.green": "Polar Green",
2126+
"label.theme.project": "Project Style",
2127+
"label.theme.project.navigation.setting": "Project Navigation setting",
2128+
"label.theme.sunset.orange": "Sunset Orange",
2129+
"label.theme.volcano": "Volcano",
2130+
"label.theme.white": "White",
21082131
"label.threshold": "Threshold",
21092132
"label.thursday": "Thursday",
21102133
"label.tier.details": "Tier details",

ui/src/App.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ export default {
3636
}
3737
},
3838
created () {
39-
window.less.modifyVars(this.$config.theme)
39+
const userThemeSetting = this.$store.getters.themeSetting || {}
40+
if (Object.keys(userThemeSetting).length === 0) {
41+
window.less.modifyVars(this.$config.theme)
42+
} else {
43+
window.less.modifyVars(userThemeSetting)
44+
}
4045
console.log('config and theme applied')
4146
}
4247
}

ui/src/assets/icons/dark.svg

Lines changed: 39 additions & 0 deletions
Loading

ui/src/assets/icons/light.svg

Lines changed: 40 additions & 0 deletions
Loading

ui/src/components/page/GlobalFooter.vue

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,8 @@ export default {
4949
5050
.line {
5151
margin-bottom: 8px;
52-
53-
a {
54-
color: rgba(0, 0, 0, .45);
55-
56-
&:hover {
57-
color: rgba(0, 0, 0, .65);
58-
}
59-
60-
}
6152
}
6253
.copyright {
63-
color: rgba(0, 0, 0, .45);
6454
font-size: 14px;
6555
}
6656
}

ui/src/components/page/GlobalLayout.vue

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@
6363
</a-drawer>
6464
</template>
6565

66+
<template>
67+
<drawer :visible="showSetting" placement="right">
68+
<div slot="handler">
69+
<a-button type="primary" size="large">
70+
<a-icon :type="showSetting ? 'close' : 'setting'"/>
71+
</a-button>
72+
</div>
73+
<setting slot="drawer" :visible="showSetting" />
74+
</drawer>
75+
</template>
76+
6677
<a-layout :class="[layoutMode, `content-width-${contentWidth}`]" :style="{ paddingLeft: contentPaddingLeft, minHeight: '100vh' }">
6778
<!-- layout header -->
6879
<global-header
@@ -94,19 +105,24 @@ import GlobalFooter from '@/components/page/GlobalFooter'
94105
import { triggerWindowResizeEvent } from '@/utils/util'
95106
import { mapState, mapActions } from 'vuex'
96107
import { mixin, mixinDevice } from '@/utils/mixin.js'
108+
import Drawer from '@/components/widgets/Drawer'
109+
import Setting from '@/components/view/Setting.vue'
97110
98111
export default {
99112
name: 'GlobalLayout',
100113
components: {
101114
SideMenu,
102115
GlobalHeader,
103-
GlobalFooter
116+
GlobalFooter,
117+
Drawer,
118+
Setting
104119
},
105120
mixins: [mixin, mixinDevice],
106121
data () {
107122
return {
108123
collapsed: false,
109-
menus: []
124+
menus: [],
125+
showSetting: false
110126
}
111127
},
112128
computed: {
@@ -129,13 +145,28 @@ export default {
129145
},
130146
mainMenu (newMenu) {
131147
this.menus = newMenu.find((item) => item.path === '/').children
148+
},
149+
'$store.getters.darkMode' (darkMode) {
150+
if (darkMode) {
151+
document.body.classList.add('dark-mode')
152+
} else {
153+
document.body.classList.remove('dark-mode')
154+
}
155+
}
156+
},
157+
provide: function () {
158+
return {
159+
parentToggleSetting: this.toggleSetting
132160
}
133161
},
134162
created () {
135163
this.menus = this.mainMenu.find((item) => item.path === '/').children
136164
this.collapsed = !this.sidebarOpened
137165
},
138166
mounted () {
167+
if (this.$store.getters.darkMode) {
168+
document.body.classList.add('dark-mode')
169+
}
139170
const userAgent = navigator.userAgent
140171
if (userAgent.indexOf('Edge') > -1) {
141172
this.$nextTick(() => {
@@ -146,6 +177,9 @@ export default {
146177
})
147178
}
148179
},
180+
beforeDestroy () {
181+
document.body.classList.remove('dark')
182+
},
149183
methods: {
150184
...mapActions(['setSidebar']),
151185
toggle () {
@@ -166,6 +200,9 @@ export default {
166200
if (!this.isDesktop()) {
167201
this.collapsed = false
168202
}
203+
},
204+
toggleSetting (showSetting) {
205+
this.showSetting = showSetting
169206
}
170207
}
171208
}

ui/src/components/view/DetailSettings.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@
4444
:dataSource="Object.keys(detailOptions)"
4545
:placeholder="$t('label.name')"
4646
@change="e => onAddInputChange(e, 'newKey')" />
47-
<a-input style=" width: 30px; border-left: 0; pointer-events: none; backgroundColor: #fff" placeholder="=" disabled />
47+
<a-input
48+
class="tag-disabled-input"
49+
style=" width: 30px; border-left: 0; pointer-events: none; text-align: center"
50+
placeholder="="
51+
disabled />
4852
<a-auto-complete
4953
class="detail-input"
5054
:filterOption="filterOption"

ui/src/components/view/InfoCard.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,13 +620,21 @@
620620
@keyup.enter="handleInputConfirm"
621621
compact>
622622
<a-input ref="input" :value="inputKey" @change="handleKeyChange" style="width: 30%; text-align: center" :placeholder="$t('label.key')" />
623-
<a-input style=" width: 30px; border-left: 0; pointer-events: none; backgroundColor: #fff" placeholder="=" disabled />
623+
<a-input
624+
class="tag-disabled-input"
625+
style="width: 30px; border-left: 0; pointer-events: none; text-align: center"
626+
placeholder="="
627+
disabled />
624628
<a-input :value="inputValue" @change="handleValueChange" style="width: 30%; text-align: center; border-left: 0" :placeholder="$t('label.value')" />
625629
<tooltip-button :tooltip="$t('label.ok')" icon="check" size="small" @click="handleInputConfirm" />
626630
<tooltip-button :tooltip="$t('label.cancel')" icon="close" size="small" @click="inputVisible=false" />
627631
</a-input-group>
628632
</div>
629-
<a-tag @click="showInput" style="background: #fff; borderStyle: dashed;" v-else-if="isAdminOrOwner() && 'createTags' in $store.getters.apis">
633+
<a-tag
634+
@click="showInput"
635+
class="btn-add-tag"
636+
style="borderStyle: dashed;"
637+
v-else-if="isAdminOrOwner() && 'createTags' in $store.getters.apis">
630638
<a-icon type="plus" /> {{ $t('label.new.tag') }}
631639
</a-tag>
632640
</div>

ui/src/components/view/ListView.vue

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -598,14 +598,6 @@ export default {
598598
/deep/ .ant-table-small > .ant-table-content > .ant-table-body {
599599
margin: 0;
600600
}
601-
602-
/deep/ .light-row {
603-
background-color: #fff;
604-
}
605-
606-
/deep/ .dark-row {
607-
background-color: #f9f9f9;
608-
}
609601
</style>
610602

611603
<style scoped lang="scss">

ui/src/components/view/SearchView.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@
7474
size="small"
7575
compact>
7676
<a-input ref="input" :value="inputKey" @change="e => inputKey = e.target.value" style="width: 50px; text-align: center" :placeholder="$t('label.key')" />
77-
<a-input style=" width: 20px; border-left: 0; pointer-events: none; backgroundColor: #fff" placeholder="=" disabled />
77+
<a-input
78+
class="tag-disabled-input"
79+
style=" width: 20px; border-left: 0; pointer-events: none; text-align: center"
80+
placeholder="="
81+
disabled />
7882
<a-input :value="inputValue" @change="handleValueChange" style="width: 50px; text-align: center; border-left: 0" :placeholder="$t('label.value')" />
7983
<tooltip-button :tooltip="$t('label.clear')" icon="close" size="small" @click="inputKey = inputValue = ''" />
8084
</a-input-group>

0 commit comments

Comments
 (0)