2023-07-15 12:57:03 +08:00
|
|
|
'use client';
|
|
|
|
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { ModalStaticFunctions } from './confirm';
|
2020-02-03 13:00:35 +08:00
|
|
|
import confirm, {
|
2022-06-11 21:39:58 +08:00
|
|
|
modalGlobalConfig,
|
|
|
|
withConfirm,
|
|
|
|
withError,
|
2020-02-03 13:00:35 +08:00
|
|
|
withInfo,
|
|
|
|
withSuccess,
|
2022-06-11 21:39:58 +08:00
|
|
|
withWarn,
|
2020-02-03 13:00:35 +08:00
|
|
|
} from './confirm';
|
2021-08-17 16:22:42 +08:00
|
|
|
import destroyFns from './destroyFns';
|
2023-06-05 09:57:26 +08:00
|
|
|
import type { ModalFuncProps } from './interface';
|
2022-06-11 21:39:58 +08:00
|
|
|
import OriginModal from './Modal';
|
|
|
|
import PurePanel from './PurePanel';
|
|
|
|
import useModal from './useModal';
|
2016-08-15 12:00:05 +08:00
|
|
|
|
2023-06-05 09:57:26 +08:00
|
|
|
export type { ModalFuncProps, ModalLocale, ModalProps } from './interface';
|
2017-03-03 11:40:54 +08:00
|
|
|
|
2019-08-05 18:38:10 +08:00
|
|
|
function modalWarn(props: ModalFuncProps) {
|
2020-02-03 13:00:35 +08:00
|
|
|
return confirm(withWarn(props));
|
2019-08-05 18:38:10 +08:00
|
|
|
}
|
|
|
|
|
2020-09-16 11:43:55 +08:00
|
|
|
type ModalType = typeof OriginModal &
|
2021-08-17 16:22:42 +08:00
|
|
|
ModalStaticFunctions & {
|
|
|
|
useModal: typeof useModal;
|
|
|
|
destroyAll: () => void;
|
|
|
|
config: typeof modalGlobalConfig;
|
2022-06-11 21:39:58 +08:00
|
|
|
/** @private Internal Component. Do not use in your production. */
|
2022-06-13 17:55:00 +08:00
|
|
|
_InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel;
|
2021-08-17 16:22:42 +08:00
|
|
|
};
|
2020-09-16 11:43:55 +08:00
|
|
|
|
|
|
|
const Modal = OriginModal as ModalType;
|
2020-02-03 13:00:35 +08:00
|
|
|
|
2021-08-17 16:22:42 +08:00
|
|
|
Modal.useModal = useModal;
|
|
|
|
|
2019-08-11 19:38:08 +08:00
|
|
|
Modal.info = function infoFn(props: ModalFuncProps) {
|
2020-02-03 13:00:35 +08:00
|
|
|
return confirm(withInfo(props));
|
2015-09-07 11:48:57 +08:00
|
|
|
};
|
|
|
|
|
2019-08-11 19:38:08 +08:00
|
|
|
Modal.success = function successFn(props: ModalFuncProps) {
|
2020-02-03 13:00:35 +08:00
|
|
|
return confirm(withSuccess(props));
|
2015-09-07 11:48:57 +08:00
|
|
|
};
|
|
|
|
|
2019-08-11 19:38:08 +08:00
|
|
|
Modal.error = function errorFn(props: ModalFuncProps) {
|
2020-02-03 13:00:35 +08:00
|
|
|
return confirm(withError(props));
|
2015-09-07 11:48:57 +08:00
|
|
|
};
|
|
|
|
|
2019-08-05 18:38:10 +08:00
|
|
|
Modal.warning = modalWarn;
|
|
|
|
|
|
|
|
Modal.warn = modalWarn;
|
2016-04-11 14:59:37 +08:00
|
|
|
|
2019-08-11 19:38:08 +08:00
|
|
|
Modal.confirm = function confirmFn(props: ModalFuncProps) {
|
2020-02-03 13:00:35 +08:00
|
|
|
return confirm(withConfirm(props));
|
2015-09-07 11:48:57 +08:00
|
|
|
};
|
|
|
|
|
2019-08-11 19:38:08 +08:00
|
|
|
Modal.destroyAll = function destroyAllFn() {
|
2018-12-03 17:08:48 +08:00
|
|
|
while (destroyFns.length) {
|
|
|
|
const close = destroyFns.pop();
|
|
|
|
if (close) {
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-02-09 21:49:15 +08:00
|
|
|
Modal.config = modalGlobalConfig;
|
2020-07-14 11:14:46 +08:00
|
|
|
|
2022-06-13 17:55:00 +08:00
|
|
|
Modal._InternalPanelDoNotUseOrYouWillBeFired = PurePanel;
|
2022-06-11 21:39:58 +08:00
|
|
|
|
2023-01-08 21:30:41 +08:00
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
Modal.displayName = 'Modal';
|
|
|
|
}
|
|
|
|
|
2016-03-21 21:16:38 +08:00
|
|
|
export default Modal;
|