migration: rework dark theme enabling

This commit is contained in:
axolotle 2024-03-14 16:52:28 +01:00
parent 4f047d92d3
commit 5892842cec
8 changed files with 27 additions and 21 deletions

View file

@ -8,7 +8,7 @@
:disabled="waiting"
exact-active-class="active"
>
<span v-if="theme">
<span v-if="dark">
<img alt="YunoHost logo" src="./assets/logo_light.png" width="40" />
</span>
<span v-else>
@ -116,7 +116,7 @@ export default {
'transitions',
'transitionName',
'waiting',
'theme',
'dark',
'ssoLink',
]),
},
@ -184,8 +184,11 @@ export default {
if (today.getDate() === 31 && today.getMonth() + 1 === 10) {
this.$store.commit('SET_SPINNER', 'spookycat')
}
document.documentElement.setAttribute('dark-theme', this.theme) // updates the data-theme attribute
// updates the data-bs-theme attribute
document.documentElement.setAttribute(
'data-bs-theme',
this.dark ? 'dark' : 'light',
)
},
}
</script>

View file

@ -63,7 +63,7 @@ export default {
&-#{$color} {
color: theme-color-level($color, 6);
[dark-theme='true'] & {
[data-bs-theme='light'] & {
color: theme-color-level($color, -6);
}

View file

@ -25,7 +25,7 @@ export default {
background-image: url('../../assets/spinners/pacman_dark.gif');
animation-name: back-and-forth-pacman;
[dark-theme='true'] & {
[data-bs-theme='dark'] & {
background-image: url('../../assets/spinners/pacman_light.gif');
}

View file

@ -40,7 +40,7 @@ app.config.globalProperties.$askConfirmation = function (message, props) {
bodyClass: [
'font-weight-bold',
'rounded-top',
store.state.theme ? 'text-white' : 'text-black',
store.state.dark ? 'text-white' : 'text-black',
],
...props,
})
@ -58,7 +58,7 @@ app.config.globalProperties.$askMdConfirmation = function (
okTitle: this.$t('yes'),
cancelTitle: this.$t('cancel'),
headerBgVariant: 'warning',
headerClass: store.state.theme ? 'text-white' : 'text-black',
headerClass: store.state.dark ? 'text-white' : 'text-black',
centered: true,
...props,
})

View file

@ -12,7 +12,7 @@ export default {
fallbackLocale: localStorage.getItem('fallbackLocale'),
cache: localStorage.getItem('cache') !== 'false',
transitions: localStorage.getItem('transitions') !== 'false',
theme: localStorage.getItem('theme') === 'true',
dark: localStorage.getItem('dark') === 'true',
experimental: localStorage.getItem('experimental') === 'true',
spinner: 'pacman',
supportedLocales,
@ -48,10 +48,13 @@ export default {
state.spinner = spinner
},
SET_THEME(state, boolean) {
localStorage.setItem('theme', boolean)
state.theme = boolean
document.documentElement.setAttribute('dark-theme', boolean)
SET_DARK(state, boolean) {
localStorage.setItem('dark', boolean)
state.dark = boolean
document.documentElement.setAttribute(
'data-bs-theme',
boolean ? 'dark' : 'light',
)
},
},
@ -68,8 +71,8 @@ export default {
})
},
UPDATE_THEME({ commit }, theme) {
commit('SET_THEME', theme)
UPDATE_DARK({ commit }, boolean) {
commit('SET_DARK', boolean)
},
},
@ -78,7 +81,7 @@ export default {
fallbackLocale: (state) => state.fallbackLocale,
cache: (state) => state.cache,
transitions: (state) => state.transitions,
theme: (state) => state.theme,
dark: (state) => state.dark,
experimental: (state) => state.experimental,
spinner: (state) => state.spinner,

View file

@ -166,7 +166,7 @@ export default {
},
computed: {
...mapGetters(['theme']),
...mapGetters(['dark']),
},
methods: {

View file

@ -63,7 +63,7 @@ export default {
props: { labels: { true: 'enabled', false: 'disabled' } },
},
theme: {
dark: {
id: 'theme',
label: this.$t('tools_webadmin.theme'),
component: 'CheckboxItem',
@ -77,7 +77,7 @@ export default {
computed: {
// Those are set/get computed properties
...mapStoreGetSet(['locale', 'fallbackLocale', 'theme'], 'dispatch'),
...mapStoreGetSet(['locale', 'fallbackLocale', 'dark'], 'dispatch'),
...mapStoreGetSet(['cache', 'transitions', 'experimental']),
},

View file

@ -91,7 +91,7 @@
id="apps-pre-upgrade"
:title="$t('app.upgrade.confirm.title')"
header-bg-variant="warning"
:header-class="theme ? 'text-white' : 'text-black'"
:header-class="dark ? 'text-white' : 'text-black'"
:ok-title="$t('system_upgrade_btn')"
ok-variant="success"
:cancel-title="$t('cancel')"
@ -166,7 +166,7 @@ export default {
},
computed: {
...mapGetters(['theme']),
...mapGetters(['dark']),
},
methods: {