Code:
<script>
import { BaseSwitch } from "src/components";
export default {
name: "sidebar-share",
components: {
BaseSwitch
},
props: {
backgroundColor: String
},
data() {
return {
sidebarMini: true,
darkMode: true,
isOpen: false,
sidebarColors: [
{ color: "primary", active: false, value: "primary" },
{ color: "vue", active: true, value: "vue" },
{ color: "info", active: false, value: "blue" },
{ color: "success", active: false, value: "green" },
{ color: "warning", active: false, value: "orange" },
{ color: "danger", active: false, value: "red" }
]
};
},
methods: {
toggleDropDown() {
this.isOpen = !this.isOpen;
},
closeDropDown() {
this.isOpen = false;
},
toggleList(list, itemToActivate) {
list.forEach(listItem => {
listItem.active = false;
});
itemToActivate.active = true;
},
changeSidebarBackground(item) {
this.$emit("update:backgroundColor", item.value);
this.toggleList(this.sidebarColors, item);
localStorage.setItem("sidebarbg", item.value);
},
toggleMode(type) {
let docClasses = document.body.classList;
if (type) {
docClasses.remove("white-content");
localStorage.setItem("mode", "dark-content");
} else {
docClasses.add("white-content");
localStorage.setItem("mode", "white-content");
}
},
minimizeSidebar() {
this.$sidebar.toggleMinimize();
}
},
mounted() {
let modeSwitch = document.getElementById("dark-mode");
if (localStorage.getItem("mode")) {
if (localStorage.getItem("mode") == "white-content") {
document.body.classList.add("white-content");
modeSwitch.classList.add("bootstrap-switch-off");
} else if (localStorage.getItem("mode") == "dark-content") {
document.body.classList.remove("white-content");
modeSwitch.classList.add("bootstrap-switch-on");
}
}
let sidebarBg = document.getElementById("sidebar-bg");
if (localStorage.getItem("sidebarbg")) {
this.$emit("update:backgroundColor", localStorage.getItem("sidebarbg"));
}
}
};
</script>