antd-mobile
Version:
<img src="https://gw.alipayobjects.com/mdn/rms_ee68a8/afts/img/A*hjjDS5Yy-ooAAAAAAAAAAAAAARQnAQ" alt="logo" width="100%" />
41 lines (38 loc) • 1.17 kB
JavaScript
import { __awaiter } from "tslib";
import { show } from './show';
import { mergeProps } from '../../utils/with-default-props';
const defaultProps = {
confirmText: '确认',
cancelText: '取消'
};
export function confirm(p) {
const props = mergeProps(defaultProps, p);
return new Promise(resolve => {
show(Object.assign(Object.assign({}, props), {
closeOnAction: true,
onClose: () => {
var _a;
(_a = props.onClose) === null || _a === void 0 ? void 0 : _a.call(props);
resolve(false);
},
actions: [{
key: 'confirm',
text: props.confirmText,
primary: true,
onClick: () => __awaiter(this, void 0, void 0, function* () {
var _a;
yield (_a = props.onConfirm) === null || _a === void 0 ? void 0 : _a.call(props);
resolve(true);
})
}, {
key: 'cancel',
text: props.cancelText,
onClick: () => __awaiter(this, void 0, void 0, function* () {
var _b;
yield (_b = props.onCancel) === null || _b === void 0 ? void 0 : _b.call(props);
resolve(false);
})
}]
}));
});
}