feat: re-work modal behaviour to be more natural

This commit is contained in:
Paul Makles
2022-06-18 11:22:37 +01:00
parent 63d5f6bb7d
commit 0ee7b73d61
11 changed files with 72 additions and 12 deletions

View File

@@ -31,8 +31,10 @@ class ModalController<T extends Modal> {
makeObservable(this, {
stack: observable,
push: action,
pop: action,
remove: action,
rendered: computed,
isVisible: computed,
});
}
@@ -50,6 +52,16 @@ class ModalController<T extends Modal> {
];
}
/**
* Remove the top modal from the screen
* @param signal What action to trigger
*/
pop(signal: "close" | "confirm" | "force") {
this.stack = this.stack.map((entry, index) =>
index === this.stack.length - 1 ? { ...entry, signal } : entry,
);
}
/**
* Remove the keyed modal from the stack
*/
@@ -66,6 +78,8 @@ class ModalController<T extends Modal> {
{this.stack.map((modal) => {
const Component = this.components[modal.type];
return (
// ESLint does not understand spread operator
// eslint-disable-next-line
<Component
{...modal}
onClose={() => this.remove(modal.key!)}
@@ -75,6 +89,10 @@ class ModalController<T extends Modal> {
</>
);
}
get isVisible() {
return this.stack.length > 0;
}
}
/**