UNPKG

1.1 kBJavaScriptView Raw
1import React, { useEffect, useState } from 'react';
2import { renderToBody } from '../../utils/render-to-body';
3import { Cascader } from './cascader';
4export function prompt(props) {
5 return new Promise(resolve => {
6 const Wrapper = () => {
7 const [visible, setVisible] = useState(false);
8 useEffect(() => {
9 setVisible(true);
10 }, []);
11 return React.createElement(Cascader, Object.assign({}, props, {
12 visible: visible,
13 onConfirm: (val, extend) => {
14 var _a;
15 (_a = props.onConfirm) === null || _a === void 0 ? void 0 : _a.call(props, val, extend);
16 resolve(val);
17 },
18 onClose: () => {
19 var _a;
20 (_a = props.onClose) === null || _a === void 0 ? void 0 : _a.call(props);
21 setVisible(false);
22 resolve(null);
23 },
24 afterClose: () => {
25 var _a;
26 (_a = props.afterClose) === null || _a === void 0 ? void 0 : _a.call(props);
27 unmount();
28 }
29 }));
30 };
31 const unmount = renderToBody(React.createElement(Wrapper, null));
32 });
33}
\No newline at end of file