Add popup model

This commit is contained in:
MrKBear 2022-03-21 17:33:10 +08:00
parent 41a2618b73
commit 7570e965cf

85
source/Context/Popups.ts Normal file
View File

@ -0,0 +1,85 @@
import { ReactNode } from "react";
/**
*
*/
class Popup {
/**
*
*/
public isClose: boolean = false;
/**
*
*/
public id: string;
/**
*
*/
public controller: PopupController;
/**
*
*/
public index: number = 0;
/**
* react
*/
public reactNode: ReactNode;
/**
*
*/
public rendererFunction: undefined | ((p: Popup) => ReactNode);
/**
*
*/
public render(): ReactNode {
if (this.rendererFunction) {
this.reactNode = this.rendererFunction(this);
}
return this.reactNode;
};
public constructor(controller: PopupController, id: string) {
this.controller = controller;
this.id = id;
}
}
/**
*
*/
class PopupController {
/**
* ID
*/
private idIndex = 0;
/**
*
*/
public popups: Popup[] = [];
public sortPopup() {
this.popups = this.popups.sort((a, b) => a.index - b.index);
}
public newPopup(): Popup {
let newPopup = new Popup(this, `P-${this.idIndex ++}`);
this.popups.push(newPopup);
return newPopup;
}
public closePopup(popup: Popup | string) {
}
}
export { Popup, PopupController }