@fruits-chain/react-native-xiaoshu
Version:
🌈 React Native UI library
51 lines (43 loc) • 1.64 kB
JavaScript
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import React, { memo } from 'react';
import Portal from '../portal';
import DialogView from './dialog';
import DialogInputView from './dialog-input';
import DialogMethodView from './dialog-method';
/**
* 对话框
*/
const Dialog = opts => {
return new Promise(resolve => {
const key = Portal.add( /*#__PURE__*/React.createElement(DialogMethodView, _extends({}, opts, {
onClosed: () => {
var _opts$onClosed;
Portal.remove(key);
(_opts$onClosed = opts.onClosed) === null || _opts$onClosed === void 0 ? void 0 : _opts$onClosed.call(opts);
},
callback: action => {
resolve(action);
}
})));
});
};
Dialog.Component = /*#__PURE__*/memo(props => {
return /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement(DialogView, props));
});
Dialog.confirm = options => {
return Dialog({
showCancelButton: true,
...options
});
};
Dialog.input = opts => {
const key = Portal.add( /*#__PURE__*/React.createElement(DialogInputView, _extends({}, opts, {
onClosed: () => {
var _opts$onClosed2;
Portal.remove(key);
(_opts$onClosed2 = opts.onClosed) === null || _opts$onClosed2 === void 0 ? void 0 : _opts$onClosed2.call(opts);
}
})));
};
export default Dialog;
//# sourceMappingURL=index.js.map