71 lines
2.1 KiB
JavaScript
71 lines
2.1 KiB
JavaScript
function data() {
|
|
function getThemeFromLocalStorage() {
|
|
// if user already changed the theme, use it
|
|
if (window.localStorage.getItem("dark")) {
|
|
return JSON.parse(window.localStorage.getItem("dark"));
|
|
}
|
|
|
|
// else return their preferences
|
|
return (
|
|
!!window.matchMedia &&
|
|
window.matchMedia("(prefers-color-scheme: dark)").matches
|
|
);
|
|
}
|
|
|
|
function setThemeToLocalStorage(value) {
|
|
window.localStorage.setItem("dark", value);
|
|
}
|
|
|
|
return {
|
|
dark: getThemeFromLocalStorage(),
|
|
toggleTheme() {
|
|
this.dark = !this.dark;
|
|
setThemeToLocalStorage(this.dark);
|
|
},
|
|
isSideMenuOpen: false,
|
|
toggleSideMenu() {
|
|
this.isSideMenuOpen = !this.isSideMenuOpen;
|
|
},
|
|
closeSideMenu() {
|
|
this.isSideMenuOpen = false;
|
|
},
|
|
isNotificationsMenuOpen: false,
|
|
toggleNotificationsMenu() {
|
|
this.isNotificationsMenuOpen = !this.isNotificationsMenuOpen;
|
|
},
|
|
closeNotificationsMenu() {
|
|
this.isNotificationsMenuOpen = false;
|
|
},
|
|
isProfileMenuOpen: false,
|
|
toggleProfileMenu() {
|
|
this.isProfileMenuOpen = !this.isProfileMenuOpen;
|
|
},
|
|
closeProfileMenu() {
|
|
this.isProfileMenuOpen = false;
|
|
},
|
|
isMasterMenuOpen: false,
|
|
toggleMasterMenu() {
|
|
this.isMasterMenuOpen = !this.isMasterMenuOpen;
|
|
},
|
|
isTransaksiMenuOpen: false,
|
|
toggleTransaksiMenu() {
|
|
this.isTransaksiMenuOpen = !this.isTransaksiMenuOpen;
|
|
},
|
|
isLaporanMenuOpen: false,
|
|
toggleLaporanMenu() {
|
|
this.isLaporanMenuOpen = !this.isLaporanMenuOpen;
|
|
},
|
|
// Modal
|
|
isModalOpen: false,
|
|
trapCleanup: null,
|
|
openModal() {
|
|
this.isModalOpen = true;
|
|
this.trapCleanup = focusTrap(document.querySelector("#modal"));
|
|
},
|
|
closeModal() {
|
|
this.isModalOpen = false;
|
|
this.trapCleanup();
|
|
},
|
|
};
|
|
}
|