2023-03-03 15:54:28 +00:00
|
|
|
import { defineStore } from 'pinia';
|
2024-04-23 17:36:45 +00:00
|
|
|
import styles from '@/styles';
|
2023-03-03 15:54:28 +00:00
|
|
|
import { darkModeKey, styleKey } from '@/config';
|
|
|
|
|
2024-04-23 17:36:45 +00:00
|
|
|
|
|
|
|
interface StyleState {
|
|
|
|
[key: string]: string | boolean;
|
|
|
|
asideStyle: string;
|
|
|
|
asideScrollbarsStyle: string;
|
|
|
|
asideBrandStyle: string;
|
|
|
|
asideMenuItemStyle: string;
|
|
|
|
asideMenuItemActiveStyle: string;
|
|
|
|
asideMenuDropdownStyle: string;
|
|
|
|
navBarItemLabelStyle: string;
|
|
|
|
navBarItemLabelHoverStyle: string;
|
|
|
|
navBarItemLabelActiveColorStyle: string;
|
|
|
|
overlayStyle: string;
|
|
|
|
darkMode: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Define StyleService store
|
2023-03-03 15:54:28 +00:00
|
|
|
export const StyleService = defineStore('style', {
|
2024-04-23 17:36:45 +00:00
|
|
|
state: (): StyleState => ({
|
|
|
|
// Styles
|
2023-06-27 16:23:18 +00:00
|
|
|
asideStyle: '',
|
|
|
|
asideScrollbarsStyle: '',
|
|
|
|
asideBrandStyle: '',
|
|
|
|
asideMenuItemStyle: '',
|
|
|
|
asideMenuItemActiveStyle: '',
|
|
|
|
asideMenuDropdownStyle: '',
|
|
|
|
navBarItemLabelStyle: '',
|
|
|
|
navBarItemLabelHoverStyle: '',
|
|
|
|
navBarItemLabelActiveColorStyle: '',
|
|
|
|
overlayStyle: '',
|
2024-04-23 17:36:45 +00:00
|
|
|
// Dark mode default false
|
2023-06-27 16:23:18 +00:00
|
|
|
darkMode: false,
|
|
|
|
}),
|
|
|
|
actions: {
|
2024-04-23 17:36:45 +00:00
|
|
|
// Set style based on payload value ('basic' or 'white')
|
|
|
|
setStyle(payload: 'basic' | 'white') {
|
2023-06-27 16:23:18 +00:00
|
|
|
if (!styles[payload]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (typeof localStorage !== 'undefined') {
|
|
|
|
localStorage.setItem(styleKey, payload);
|
|
|
|
}
|
2024-04-23 17:36:45 +00:00
|
|
|
const style = styles[payload] as Record<string, string>;
|
2023-06-27 16:23:18 +00:00
|
|
|
for (const key in style) {
|
2024-04-23 17:36:45 +00:00
|
|
|
// let keyStyle: string = `${key}Style`;//key as keyof typeof style;
|
|
|
|
this[`${key}Style` as keyof StyleState] = style[key];
|
2023-06-27 16:23:18 +00:00
|
|
|
}
|
|
|
|
},
|
2024-04-23 17:36:45 +00:00
|
|
|
// Toggle dark mode
|
|
|
|
setDarkMode(payload?: boolean) {
|
|
|
|
this.darkMode = payload !== undefined ? payload : !this.darkMode;
|
2023-06-27 16:23:18 +00:00
|
|
|
if (typeof localStorage !== 'undefined') {
|
|
|
|
localStorage.setItem(darkModeKey, this.darkMode ? '1' : '0');
|
|
|
|
}
|
|
|
|
if (typeof document !== 'undefined') {
|
|
|
|
document.body.classList[this.darkMode ? 'add' : 'remove']('dark-scrollbars');
|
|
|
|
document.documentElement.classList[this.darkMode ? 'add' : 'remove']('dark-scrollbars-compat');
|
|
|
|
}
|
|
|
|
},
|
2024-09-16 15:59:46 +00:00
|
|
|
|
|
|
|
// Toggle dark mode
|
|
|
|
setLocale(payload?: boolean) {
|
|
|
|
this.darkMode = payload !== undefined ? payload : !this.darkMode;
|
|
|
|
if (typeof localStorage !== 'undefined') {
|
|
|
|
localStorage.setItem(darkModeKey, this.darkMode ? '1' : '0');
|
|
|
|
}
|
|
|
|
if (typeof document !== 'undefined') {
|
|
|
|
document.body.classList[this.darkMode ? 'add' : 'remove']('dark-scrollbars');
|
|
|
|
document.documentElement.classList[this.darkMode ? 'add' : 'remove']('dark-scrollbars-compat');
|
|
|
|
}
|
|
|
|
},
|
2023-06-27 16:23:18 +00:00
|
|
|
},
|
2024-04-23 17:36:45 +00:00
|
|
|
});
|