frequi_origin/src/components/ThemeSelect.vue

47 lines
1.3 KiB
Vue
Raw Normal View History

2020-05-22 21:02:17 +00:00
<template>
<b-nav-item @click="toggleNight">
2023-05-09 16:25:28 +00:00
<i-mdi-brightness-6 />
</b-nav-item>
2020-05-22 21:02:17 +00:00
</template>
2023-03-23 17:23:14 +00:00
<script setup lang="ts">
import { useSettingsStore } from '@/stores/settings';
import { useColorMode } from 'bootstrap-vue-next';
2020-05-22 21:02:17 +00:00
const mode = useColorMode();
2023-03-23 17:23:14 +00:00
const activeTheme = ref('');
const settingsStore = useSettingsStore();
2022-04-17 08:07:48 +00:00
2023-06-01 04:23:28 +00:00
const setTheme = (themeName: string) => {
2023-03-23 17:23:14 +00:00
// If theme is already active, do nothing.
if (activeTheme.value === themeName) {
return;
}
if (themeName.toLowerCase() === 'bootstrap' || themeName.toLowerCase() === 'bootstrap_dark') {
2023-03-23 18:28:13 +00:00
// const styles = document.getElementsByTagName('style');
if (activeTheme.value) {
2023-03-23 17:23:14 +00:00
// Only transition if simple mode is active
document.body.classList.add('ft-theme-transition');
2023-03-23 17:23:14 +00:00
window.setTimeout(() => {
document.body.classList.remove('ft-theme-transition');
2023-03-23 17:23:14 +00:00
}, 1000);
}
mode.value = themeName.toLowerCase() === 'bootstrap' ? 'light' : 'dark';
2023-03-23 17:23:14 +00:00
}
// Save the theme as localstorage
settingsStore.currentTheme = themeName;
activeTheme.value = themeName;
};
2022-04-17 08:07:48 +00:00
2023-03-23 17:23:14 +00:00
onMounted(() => {
if (settingsStore.currentTheme) setTheme(settingsStore.currentTheme);
});
2023-03-23 17:23:14 +00:00
const toggleNight = () => {
setTheme(activeTheme.value === 'bootstrap' ? 'bootstrap_dark' : 'bootstrap');
};
2020-05-22 21:02:17 +00:00
</script>
<style scoped></style>