UNPKG

@flatbiz/antd

Version:
74 lines (70 loc) 2.29 kB
/*! @flatjs/forge MIT @flatbiz/antd */ import { a as _slicedToArray, b as _objectSpread2 } from './_rollupPluginBabelHelpers-BspM60Sw.js'; import { useState, isValidElement, Fragment } from 'react'; import { jsxs, jsx } from 'react/jsx-runtime'; /** * 弹框 触发器 * ``` * <ModalAction action={<Button type="primary">打开</Button>}> * {({ onClose }) => ( * <Modal onOk={onClose}>xxx</Modal> * )} * </ModalAction> * ``` */ var ModalAction = function ModalAction(props) { var action = props.action, children = props.children; var _useState = useState(false), _useState2 = _slicedToArray(_useState, 2), open = _useState2[0], setOpen = _useState2[1]; var handleOnClick = function handleOnClick(e) { return new Promise(function ($return, $error) { var onClick; if (/*#__PURE__*/isValidElement(action)) { onClick = action.props.onClick; if (typeof onClick === 'function') { return Promise.resolve(onClick === null || onClick === void 0 ? void 0 : onClick(e)).then(function ($await_3) { try { return $If_2.call(this); } catch ($boundEx) { return $error($boundEx); } }.bind(this), $error); } function $If_2() { return $If_1.call(this); } return $If_2.call(this); } function $If_1() { setOpen(true); return $return(); } return $If_1.call(this); }); }; var onClose = function onClose() { setOpen(false); }; var childrenReactElement = /*#__PURE__*/isValidElement(children) ? children : children({ onClose: onClose, open: open }); return /*#__PURE__*/jsxs(Fragment, { children: [/*#__PURE__*/isValidElement(action) ? /*#__PURE__*/jsx(action.type, _objectSpread2(_objectSpread2({}, action.props), {}, { onClick: handleOnClick })) : action === null || action === void 0 ? void 0 : action({ onClick: handleOnClick, onClose: onClose, open: open }), /*#__PURE__*/jsx(childrenReactElement.type, _objectSpread2({ open: open, onClose: onClose, onCancel: onClose }, childrenReactElement.props))] }); }; export { ModalAction as M }; //# sourceMappingURL=modal-action-kQ60nGCG.js.map