You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.5 KiB
49 lines
1.5 KiB
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
import * as React from 'react';
|
|
import usePatchElement from '../../_util/usePatchElement';
|
|
import HookModal from './HookModal';
|
|
import { withConfirm, withInfo, withSuccess, withError, withWarn } from '../confirm';
|
|
var uuid = 0;
|
|
export default function useModal() {
|
|
var _usePatchElement = usePatchElement(),
|
|
_usePatchElement2 = _slicedToArray(_usePatchElement, 2),
|
|
elements = _usePatchElement2[0],
|
|
patchElement = _usePatchElement2[1];
|
|
|
|
function getConfirmFunc(withFunc) {
|
|
return function hookConfirm(config) {
|
|
uuid += 1;
|
|
var modalRef = /*#__PURE__*/React.createRef();
|
|
var closeFunc;
|
|
var modal = /*#__PURE__*/React.createElement(HookModal, {
|
|
key: "modal-".concat(uuid),
|
|
config: withFunc(config),
|
|
ref: modalRef,
|
|
afterClose: function afterClose() {
|
|
closeFunc();
|
|
}
|
|
});
|
|
closeFunc = patchElement(modal);
|
|
return {
|
|
destroy: function destroy() {
|
|
if (modalRef.current) {
|
|
modalRef.current.destroy();
|
|
}
|
|
},
|
|
update: function update(newConfig) {
|
|
if (modalRef.current) {
|
|
modalRef.current.update(newConfig);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
}
|
|
|
|
return [{
|
|
info: getConfirmFunc(withInfo),
|
|
success: getConfirmFunc(withSuccess),
|
|
error: getConfirmFunc(withError),
|
|
warning: getConfirmFunc(withWarn),
|
|
confirm: getConfirmFunc(withConfirm)
|
|
}, /*#__PURE__*/React.createElement(React.Fragment, null, elements)];
|
|
} |