@txdfe/at
Version:
一个设计体系组件库
259 lines (226 loc) • 11.2 kB
JavaScript
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
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 _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
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; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/* 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) {
_inherits(PopConfirm, _React$Component);
var _super = _createSuper(PopConfirm);
function PopConfirm(props) {
var _this;
_classCallCheck(this, PopConfirm);
_this = _super.call(this, props);
_defineProperty(_assertThisInitialized(_this), "onVisibleChange", function (visible) {
if (!('visible' in _this.props)) {
_this.setState({
visible: visible
});
}
_this.props.onVisibleChange(visible);
});
_defineProperty(_assertThisInitialized(_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(_assertThisInitialized(_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(_assertThisInitialized(_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;
}
_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 _cls2;
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((_cls2 = {}, _defineProperty(_cls2, "".concat(prefix, "pop-confirm"), true), _defineProperty(_cls2, "".concat(prefix, "pop-confirm-").concat(size), true), _cls2), 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()));
}
}]);
return PopConfirm;
}(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);