magicbean-saas-common
Version:
MagicBean SasS Common Components
76 lines (66 loc) • 1.86 kB
text/typescript
import { Module, VuexModule, Mutation, Action } from "vuex-module-decorators";
import { Actions, Mutations } from "@/store/enums/StoreEnums";
export interface StoreInfo {
classes: {
header?: Array<string>;
headerContainer?: Array<string>;
headerMobile?: Array<string>;
headerMenu?: Array<string>;
aside?: Array<string>;
asideMenu?: Array<string>;
asideToggle?: Array<string>;
toolbar?: Array<string>;
toolbarContainer?: Array<string>;
content?: Array<string>;
contentContainer?: Array<string>;
footerContainer?: Array<string>;
sidebar?: Array<string>;
pageTitle?: Array<string>;
};
}
export default class BodyModule extends VuexModule implements StoreInfo {
classes = {};
/**
* Get current page title
* @returns string
*/
get getClasses() {
return (position) => {
if (typeof position !== "undefined") {
return this.classes[position];
}
return this.classes;
};
}
[Mutations.SET_CLASSNAME_BY_POSITION](payload) {
const { position, className } = payload;
if (!this.classes[position]) {
this.classes[position] = [];
}
this.classes[position].push(className);
}
[Actions.ADD_BODY_CLASSNAME](className) {
document.body.classList.add(className);
}
[Actions.REMOVE_BODY_CLASSNAME](className) {
document.body.classList.remove(className);
}
[Actions.ADD_BODY_ATTRIBUTE](payload) {
const { qulifiedName, value } = payload;
document.body.setAttribute(qulifiedName, value);
}
[Actions.REMOVE_BODY_ATTRIBUTE](payload) {
const { qulifiedName } = payload;
document.body.removeAttribute(qulifiedName);
}
[Actions.ADD_CLASSNAME](payload) {
this.context.commit(Mutations.SET_CLASSNAME_BY_POSITION, payload);
}
}