2020-05-22 21:02:17 +00:00
|
|
|
<template>
|
2023-06-01 04:23:28 +00:00
|
|
|
<b-link class="nav-link" @click="toggleNight">
|
2023-05-09 16:25:28 +00:00
|
|
|
<i-mdi-brightness-6 />
|
2023-03-23 18:28:13 +00:00
|
|
|
</b-link>
|
2020-05-22 21:02:17 +00:00
|
|
|
</template>
|
|
|
|
|
2023-03-23 17:23:14 +00:00
|
|
|
<script setup lang="ts">
|
2022-04-19 18:07:59 +00:00
|
|
|
import { useSettingsStore } from '@/stores/settings';
|
2023-06-02 15:05:10 +00:00
|
|
|
import { useColorMode } from 'bootstrap-vue-next';
|
2023-05-09 04:49:13 +00:00
|
|
|
import { onMounted, ref } from 'vue';
|
2020-05-22 21:02:17 +00:00
|
|
|
|
2023-06-02 15:05:10 +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
|
2023-06-02 15:05:10 +00:00
|
|
|
document.body.classList.add('ft-theme-transition');
|
2023-03-23 17:23:14 +00:00
|
|
|
window.setTimeout(() => {
|
2023-06-02 15:05:10 +00:00
|
|
|
document.body.classList.remove('ft-theme-transition');
|
2023-03-23 17:23:14 +00:00
|
|
|
}, 1000);
|
|
|
|
}
|
2023-06-02 15:05:10 +00:00
|
|
|
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);
|
2020-12-28 18:33:03 +00:00
|
|
|
});
|
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>
|
|
|
|
|
2020-07-26 08:48:07 +00:00
|
|
|
<style scoped></style>
|