UNPKG

@jdcfe/yep-react

Version:

一套移动端的React组件库

153 lines (140 loc) 5.5 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } import * as React from 'react'; import classNames from 'classnames'; import noop from '../_utils/noop'; import confirm from './confirm'; import Popup from '../popup'; var Dialog = /*#__PURE__*/function (_React$PureComponent) { _inherits(Dialog, _React$PureComponent); var _super = _createSuper(Dialog); function Dialog(props) { var _this; _classCallCheck(this, Dialog); _this = _super.call(this, props); _this.renderHeader = _this.renderHeader.bind(_assertThisInitialized(_this)); _this.renderBody = _this.renderBody.bind(_assertThisInitialized(_this)); _this.renderFooter = _this.renderFooter.bind(_assertThisInitialized(_this)); _this.close = _this.close.bind(_assertThisInitialized(_this)); _this.onMaskClick = _this.onMaskClick.bind(_assertThisInitialized(_this)); _this.state = { show: false }; return _this; } _createClass(Dialog, [{ key: "componentDidMount", value: function componentDidMount() { this.setState({ show: this.props.show }); } }, { key: "componentWillReceiveProps", value: function componentWillReceiveProps(nextProps) { this.setState({ show: nextProps.show }); } }, { key: "close", value: function close(e) { var onClose = this.props.onClose; if (onClose) { onClose(e); } } }, { key: "onMaskClick", value: function onMaskClick(e) { var maskCloseable = this.props.maskCloseable; if (e.target === e.currentTarget && maskCloseable) { this.close(e); } } }, { key: "renderHeader", value: function renderHeader() { var _this$props = this.props, prefixCls = _this$props.prefixCls, title = _this$props.title; return /*#__PURE__*/React.createElement("div", { className: "".concat(prefixCls, "-header") }, /*#__PURE__*/React.createElement("div", { className: "".concat(prefixCls, "-title") }, title)); } }, { key: "renderBody", value: function renderBody() { var _this$props2 = this.props, prefixCls = _this$props2.prefixCls, bodyStyle = _this$props2.bodyStyle, children = _this$props2.children; return /*#__PURE__*/React.createElement("div", { className: "".concat(prefixCls, "-body"), style: bodyStyle }, children); } }, { key: "renderFooter", value: function renderFooter() { var _this$props3 = this.props, prefixCls = _this$props3.prefixCls, footer = _this$props3.footer; return /*#__PURE__*/React.createElement("div", { className: "".concat(prefixCls, "-footer") }, footer); } }, { key: "render", value: function render() { var _this$props4 = this.props, prefixCls = _this$props4.prefixCls, className = _this$props4.className, style = _this$props4.style, title = _this$props4.title, maskTransition = _this$props4.maskTransition, dialogTransition = _this$props4.dialogTransition, footer = _this$props4.footer, usePortal = _this$props4.usePortal, maskCloseable = _this$props4.maskCloseable; var cls = classNames(prefixCls, className, "".concat(prefixCls, "-transparent")); return /*#__PURE__*/React.createElement(Popup, { show: this.state.show, maskTransition: maskTransition, popupTransition: dialogTransition, maskCloseable: maskCloseable, usePortal: usePortal }, /*#__PURE__*/React.createElement("div", { className: "".concat(prefixCls, "-wrap"), onClick: this.onMaskClick }, /*#__PURE__*/React.createElement("div", { className: cls, style: style }, /*#__PURE__*/React.createElement("div", { className: "".concat(prefixCls, "-content") }, title && this.renderHeader(), this.renderBody(), footer && this.renderFooter())))); } }]); return Dialog; }(React.PureComponent); export { Dialog as default }; Dialog.confirm = confirm; Dialog.defaultProps = { prefixCls: 'Yep-dialog', style: {}, bodyStyle: {}, show: false, maskCloseable: false, maskTransition: 'fade', dialogTransition: 'zoom', onClose: noop, usePortal: true };