mirror of
https://github.com/Yidadaa/ChatGPT-Next-Web.git
synced 2025-08-09 02:35:41 +08:00
feat: replace window.confirm with showConfirm
This commit is contained in:
@@ -4,6 +4,7 @@ import CloseIcon from "../icons/close.svg";
|
||||
import EyeIcon from "../icons/eye.svg";
|
||||
import EyeOffIcon from "../icons/eye-off.svg";
|
||||
import DownIcon from "../icons/down.svg";
|
||||
import Locale from "../locales";
|
||||
|
||||
import { createRoot } from "react-dom/client";
|
||||
import React, { HTMLProps, useEffect, useState } from "react";
|
||||
@@ -87,7 +88,7 @@ export function Loading() {
|
||||
|
||||
interface ModalProps {
|
||||
title: string;
|
||||
children?: JSX.Element | JSX.Element[];
|
||||
children?: any;
|
||||
actions?: JSX.Element[];
|
||||
onClose?: () => void;
|
||||
}
|
||||
@@ -262,3 +263,45 @@ export function Select(
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function showConfirm(content: any) {
|
||||
const div = document.createElement("div");
|
||||
div.className = "modal-mask";
|
||||
document.body.appendChild(div);
|
||||
|
||||
const root = createRoot(div);
|
||||
const closeModal = () => {
|
||||
root.unmount();
|
||||
div.remove();
|
||||
};
|
||||
|
||||
return new Promise<boolean>((resolve) => {
|
||||
root.render(
|
||||
<Modal
|
||||
title={Locale.UI.Confirm}
|
||||
actions={[
|
||||
<IconButton
|
||||
key="cancel"
|
||||
text={Locale.UI.Cancel}
|
||||
onClick={() => {
|
||||
resolve(false);
|
||||
closeModal();
|
||||
}}
|
||||
></IconButton>,
|
||||
<IconButton
|
||||
key="confirm"
|
||||
text={Locale.UI.Confirm}
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
resolve(true);
|
||||
closeModal();
|
||||
}}
|
||||
></IconButton>,
|
||||
]}
|
||||
onClose={closeModal}
|
||||
>
|
||||
{content}
|
||||
</Modal>,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user