@txdfe/at
Version:
一个设计体系组件库
225 lines • 10.5 kB
JavaScript
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
/* eslint-disable react/prop-types */
/* eslint-disable react/forbid-prop-types */
import React from 'react';
import PropTypes from 'prop-types';
import cls from 'classnames';
import ConfigProvider from '../config-provider';
import nextLocale from '../locale/zh-cn';
import Balloon from './balloon';
import Icon from '../icon';
import Button from '../button';
var iconMap = {
info: 'info-o-fill',
success: 'info-o-fill',
warning: 'warning-o-fill',
danger: 'remove-o-fill'
};
var noop = function noop() {};
var PopConfirm = /*#__PURE__*/function (_React$Component) {
function PopConfirm(props) {
var _this;
_classCallCheck(this, PopConfirm);
_this = _callSuper(this, PopConfirm, [props]);
_defineProperty(_this, "onVisibleChange", function (visible) {
if (!('visible' in _this.props)) {
_this.setState({
visible: visible
});
}
_this.props.onVisibleChange(visible);
});
_defineProperty(_this, "renderIcon", function () {
var _this$props = _this.props,
type = _this$props.type,
icon = _this$props.icon;
return /*#__PURE__*/React.createElement("div", {
className: cls(_defineProperty({
'pop-confirm-icon-area': true
}, "pop-confirm-icon-area-".concat(type), type))
}, icon || /*#__PURE__*/React.createElement(Icon, {
type: iconMap[type] || iconMap.info
}));
});
_defineProperty(_this, "renderTitleAndContent", function () {
var _this$props2 = _this.props,
title = _this$props2.title,
content = _this$props2.content,
footer = _this$props2.footer;
return /*#__PURE__*/React.createElement("div", {
className: cls({
'title-content-area': true,
'title-content-area-no-footer': !footer
})
}, title ? /*#__PURE__*/React.createElement("div", {
className: "title-area"
}, title) : null, /*#__PURE__*/React.createElement("div", {
className: cls({
'content-area': true,
'content-area-no-title': !title
})
}, content));
});
_defineProperty(_this, "renderFooter", function () {
var _this$props3 = _this.props,
type = _this$props3.type,
locale = _this$props3.locale,
footer = _this$props3.footer,
confirmProps = _this$props3.confirmProps,
cancelProps = _this$props3.cancelProps,
onConfirm = _this$props3.onConfirm,
onCancel = _this$props3.onCancel;
return footer ? /*#__PURE__*/React.createElement("div", {
className: "footer-area"
}, /*#__PURE__*/React.createElement(Button, _extends({}, cancelProps, {
onClick: onCancel,
type: "normal",
size: "small"
}), locale.cancel), /*#__PURE__*/React.createElement(Button, _extends({}, confirmProps, {
onClick: onConfirm,
type: "primary",
warning: type === 'danger',
size: "small"
}), locale.confirm)) : null;
});
_this.state = {
visible: props.visible || props.defaultVisible
};
return _this;
}
_inherits(PopConfirm, _React$Component);
return _createClass(PopConfirm, [{
key: "UNSAFE_componentWillReceiveProps",
value: function UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.visible !== this.props.visible) {
this.setState({
visible: nextProps.visible
});
}
}
}, {
key: "render",
value: function render() {
var _this$props4 = this.props,
prefix = _this$props4.prefix,
size = _this$props4.size,
trigger = _this$props4.trigger,
align = _this$props4.align,
alignEdge = _this$props4.alignEdge,
offset = _this$props4.offset,
triggerType = _this$props4.triggerType,
needAdjust = _this$props4.needAdjust,
shouldUpdatePosition = _this$props4.shouldUpdatePosition,
safeNode = _this$props4.safeNode,
safeId = _this$props4.safeId,
animation = _this$props4.animation,
cache = _this$props4.cache,
popupContainer = _this$props4.popupContainer,
popupStyle = _this$props4.popupStyle,
popupClassName = _this$props4.popupClassName,
popupProps = _this$props4.popupProps,
followTrigger = _this$props4.followTrigger,
id = _this$props4.id;
var visible = this.state.visible;
return /*#__PURE__*/React.createElement(Balloon, {
autoFocus: false,
closable: false,
popupClassName: cls(_defineProperty(_defineProperty({}, "".concat(prefix, "pop-confirm"), true), "".concat(prefix, "pop-confirm-").concat(size), true), popupClassName),
prefix: prefix,
visible: visible,
onVisibleChange: this.onVisibleChange,
align: align,
alignEdge: alignEdge,
offset: offset,
trigger: trigger,
triggerType: triggerType,
needAdjust: needAdjust,
shouldUpdatePosition: shouldUpdatePosition,
safeNode: safeNode,
safeId: safeId,
animation: animation,
cache: cache,
popupContainer: popupContainer,
popupStyle: popupStyle,
popupProps: popupProps,
followTrigger: followTrigger,
id: id
}, /*#__PURE__*/React.createElement("div", {
className: "".concat(prefix, "pop-confirm-container")
}, this.renderIcon(), this.renderTitleAndContent(), this.renderFooter()));
}
}]);
}(React.Component);
_defineProperty(PopConfirm, "displayName", 'PopConfirm');
_defineProperty(PopConfirm, "propTypes", {
prefix: PropTypes.string,
locale: PropTypes.object,
size: PropTypes.oneOf(['small', 'medium', 'large']),
type: PropTypes.oneOf(['info', 'warning', 'success', 'danger']),
align: Balloon.propTypes.align,
alignEdge: PropTypes.bool,
icon: PropTypes.node,
title: PropTypes.node,
content: PropTypes.node,
footer: PropTypes.bool,
confirmProps: PropTypes.object,
cancelProps: PropTypes.object,
onConfirm: PropTypes.func,
onCancel: PropTypes.func,
defaultVisible: PropTypes.bool,
visible: PropTypes.bool,
onVisibleChange: PropTypes.func,
offset: PropTypes.array,
trigger: PropTypes.node.isRequired,
triggerType: PropTypes.oneOf(['hover', 'click']),
needAdjust: PropTypes.bool,
shouldUpdatePosition: PropTypes.bool,
safeNode: PropTypes.string,
safeId: PropTypes.string,
animation: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]),
cache: PropTypes.bool,
popupContainer: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
popupStyle: PropTypes.object,
popupClassName: PropTypes.string,
popupProps: PropTypes.object,
followTrigger: PropTypes.bool,
id: PropTypes.string
});
_defineProperty(PopConfirm, "defaultProps", {
prefix: 'next-',
size: 'medium',
locale: nextLocale.Balloon,
type: 'info',
align: 'b',
alignEdge: true,
footer: true,
confirmProps: {},
cancelProps: {},
onConfirm: noop,
onCancel: noop,
defaultVisible: false,
onVisibleChange: noop,
offset: [0, 0],
triggerType: 'hover',
needAdjust: true,
animation: {
"in": 'zoomIn',
out: 'zoomOut'
},
cache: false
});
export default ConfigProvider.config(PopConfirm);