UNPKG

@carrot-farm/mongsil-ui

Version:
27 lines (26 loc) 1.21 kB
import * as React from 'react'; import Input from '../../Input'; import Dialog from '../Dialog'; function Prompt(_a) { var title = _a.title, body = _a.body, visible = _a.visible, onOk = _a.onOk, _b = _a.onClose, onClose = _b === void 0 ? function () { } : _b; var ref = React.useRef(null); var _c = React.useState(''), value = _c[0], setValue = _c[1]; var handleOk = function () { if (typeof onOk === 'function') { onOk(value); } }; var handleInputChange = function (value) { setValue(value); }; React.useEffect(function () { var _a; if (visible === true && ref.current) { (_a = ref.current.querySelector('input')) === null || _a === void 0 ? void 0 : _a.focus(); } }, [visible]); return (React.createElement(Dialog, { title: title, body: React.createElement("div", null, React.createElement("p", null, body), React.createElement(Input, { ref: ref, onChange: function (v) { return handleInputChange(v !== null && v !== void 0 ? v : ''); } })), visible: visible, onOk: handleOk, onCancel: onClose, onClose: onClose, onBackdropClick: onClose })); } export default Prompt;