UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

201 lines (168 loc) 5.71 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; 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) { function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } return function () { var Super = _getPrototypeOf(Derived), result; if (isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } import React, { Component } from 'react'; import Tooltip from '../tooltip'; import Icon from '../icon'; import Button from '../button'; import LocaleReceiver from '../locale-provider/LocaleReceiver'; import defaultLocale from '../locale-provider/default'; import { Size } from '../_util/enum'; import { getPrefixCls as _getPrefixCls } from '../configure'; var Popconfirm = /*#__PURE__*/ function (_Component) { _inherits(Popconfirm, _Component); var _super = _createSuper(Popconfirm); function Popconfirm(props) { var _this; _classCallCheck(this, Popconfirm); _this = _super.call(this, props); _this.onConfirm = function (e) { _this.setVisible(false); var onConfirm = _this.props.onConfirm; if (onConfirm) { onConfirm.call(_assertThisInitialized(_this), e); } }; _this.onCancel = function (e) { _this.setVisible(false); var onCancel = _this.props.onCancel; if (onCancel) { onCancel.call(_assertThisInitialized(_this), e); } }; _this.onVisibleChange = function (visible) { _this.setVisible(visible); }; _this.saveTooltip = function (node) { _this.tooltip = node; }; _this.renderOverlayWithLocale = function (popconfirmLocale) { var _this$props = _this.props, title = _this$props.title, cancelText = _this$props.cancelText, okText = _this$props.okText, okType = _this$props.okType; var prefixCls = _this.getPrefixCls(); return React.createElement("div", null, React.createElement("div", { className: "".concat(prefixCls, "-inner-content") }, React.createElement("div", { className: "".concat(prefixCls, "-message") }, React.createElement(Icon, { type: "warning" }), React.createElement("div", { className: "".concat(prefixCls, "-message-title") }, typeof title === 'function' ? title() : title)), React.createElement("div", { className: "".concat(prefixCls, "-buttons") }, React.createElement(Button, { onClick: _this.onCancel, size: Size.small }, cancelText || popconfirmLocale.cancelText), React.createElement(Button, { onClick: _this.onConfirm, type: okType, size: Size.small }, okText || popconfirmLocale.okText)))); }; _this.renderLocale = function () { return React.createElement(LocaleReceiver, { componentName: "Popconfirm", defaultLocale: defaultLocale.Popconfirm }, _this.renderOverlayWithLocale); }; _this.state = { visible: props.visible }; return _this; } _createClass(Popconfirm, [{ key: "componentWillReceiveProps", value: function componentWillReceiveProps(nextProps) { if ('visible' in nextProps) { this.setState({ visible: nextProps.visible }); } } }, { key: "getPopupDomNode", value: function getPopupDomNode() { return this.tooltip.getPopupDomNode(); } }, { key: "setVisible", value: function setVisible(visible) { var props = this.props; if (!('visible' in props)) { this.setState({ visible: visible }); } var onVisibleChange = props.onVisibleChange; if (onVisibleChange) { onVisibleChange(visible); } } }, { key: "getPrefixCls", value: function getPrefixCls() { var prefixCls = this.props.prefixCls; return _getPrefixCls('popover', prefixCls); } }, { key: "render", value: function render() { var _this$props2 = this.props, placement = _this$props2.placement, restProps = _objectWithoutProperties(_this$props2, ["placement"]); var visible = this.state.visible; return React.createElement(Tooltip, _extends({}, restProps, { prefixCls: this.getPrefixCls(), placement: placement, onVisibleChange: this.onVisibleChange, visible: visible, overlay: this.renderLocale, ref: this.saveTooltip })); } }]); return Popconfirm; }(Component); export { Popconfirm as default }; Popconfirm.displayName = 'Popconfirm'; Popconfirm.defaultProps = { transitionName: 'zoom-big', placement: 'top', trigger: 'click', okType: 'primary' }; //# sourceMappingURL=index.js.map