2020-05-22 21:02:17 +00:00
|
|
|
<template>
|
2023-03-23 18:28:13 +00:00
|
|
|
<b-link variant="outline-primary" class="nav-link" @click="toggleNight">
|
|
|
|
<ThemeLightDark :size="16" />
|
|
|
|
</b-link>
|
2020-05-22 21:02:17 +00:00
|
|
|
</template>
|
|
|
|
|
2023-03-23 17:23:14 +00:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { ref, onMounted } from 'vue';
|
2020-12-28 18:33:03 +00:00
|
|
|
import ThemeLightDark from 'vue-material-design-icons/Brightness6.vue';
|
2022-04-19 18:07:59 +00:00
|
|
|
import { useSettingsStore } from '@/stores/settings';
|
2020-05-22 21:02:17 +00:00
|
|
|
|
2023-03-23 17:23:14 +00:00
|
|
|
const activeTheme = ref('');
|
|
|
|
const settingsStore = useSettingsStore();
|
2022-04-17 08:07:48 +00:00
|
|
|
|
2023-03-23 17:23:14 +00:00
|
|
|
const setTheme = (themeName) => {
|
|
|
|
// 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');
|
2023-03-23 17:23:14 +00:00
|
|
|
document.documentElement.setAttribute(
|
|
|
|
'data-theme',
|
|
|
|
themeName.toLowerCase() === 'bootstrap' ? 'light' : 'dark',
|
|
|
|
);
|
2023-03-23 18:28:13 +00:00
|
|
|
if (activeTheme.value) {
|
2023-03-23 17:23:14 +00:00
|
|
|
// Only transition if simple mode is active
|
|
|
|
document.documentElement.classList.add('ft-theme-transition');
|
|
|
|
window.setTimeout(() => {
|
|
|
|
document.documentElement.classList.remove('ft-theme-transition');
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 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>
|