UNPKG

antd

Version:

An enterprise-class UI design language and React components implementation

49 lines (47 loc) 1.58 kB
import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; import * as React from 'react'; import usePatchElement from '../../_util/hooks/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)]; }