Revenge/src/ui/alerts.ts

28 lines
1,011 B
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?: ConfirmationAlertOptions["content"];
body?: ConfirmationAlertOptions["content"];
};
export function showConfirmationAlert(options: ConfirmationAlertOptions) {
const internalOptions = options as InternalConfirmationAlertOptions;
internalOptions.body = options.content;
delete internalOptions.content;
internalOptions.isDismissable ??= true;
return Alerts.show(internalOptions);
};
2023-12-17 03:39:57 +00:00
export const showCustomAlert = (component: React.ComponentType<any>, props: any) => Alerts.openLazy({
2023-02-26 22:56:36 +00:00
importer: async () => () => React.createElement(component, props),
});
2023-12-17 03:39:57 +00:00
export const showInputAlert = (options: InputAlertProps) => showCustomAlert(InputAlert, options);