Revenge/src/ui/alerts.ts

30 lines
1.1 KiB
TypeScript
Raw Normal View History

import { ConfirmationAlertOptions, InputAlertProps } from "@types";
import { findByProps } from "@metro/filters";
import InputAlert from "@ui/components/InputAlert";
const Alerts = findByProps("openLazy", "close");
2023-02-26 22:56:36 +00:00
interface InternalConfirmationAlertOptions extends Omit<ConfirmationAlertOptions, "content"> {
content: string | JSX.Element | JSX.Element[] | undefined;
body: string | undefined;
children: JSX.Element | JSX.Element[];
};
export function showConfirmationAlert(options: ConfirmationAlertOptions) {
const internalOptions = options as InternalConfirmationAlertOptions;
if (typeof options.content === "string") {
internalOptions.body = options.content;
} else {
internalOptions.children = options.content;
};
delete internalOptions.content;
return Alerts.show(internalOptions);
};
2023-02-26 22:56:36 +00:00
export const showCustomAlert = (component: React.ComponentType, props: any) => Alerts.openLazy({
importer: async () => () => React.createElement(component, props),
});
2023-02-26 22:56:36 +00:00
export const showInputAlert = (options: InputAlertProps) => showCustomAlert(InputAlert as React.ComponentType, options);