create-bar-project
Version:
This module helps create a base for web application projects.
53 lines (43 loc) • 1.06 kB
text/typescript
import { action, computed, IObservableArray, observable } from 'mobx';
interface ModalItem {
component?: any;
header?: string;
titleComponent?: any;
onCloseAction?: () => any;
}
export default class ModalStore {
private open = false;
private modalStack: IObservableArray<ModalItem> = observable([]);
public get isOpen(): boolean {
return this.open;
}
public get lastModalItem(): ModalItem {
return this.modalStack[this.modalStack.length - 1];
}
public get length(): number {
return this.modalStack.length;
}
public openModal(modalItem: ModalItem): void {
this.open = true;
this.modalStack.push(modalItem);
}
public closeModal = (): void => {
const onCloseAction = this.lastModalItem && this.lastModalItem.onCloseAction;
if (onCloseAction) {
onCloseAction();
}
this.open = false;
this.modalStack.clear();
};
public popModal = (): void => {
this.modalStack.pop();
};
}