@aliretail/react-materials-components
Version:
76 lines (66 loc) • 2.15 kB
JavaScript
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _Tag from "@alifd/next/es/tag";
/* eslint no-shadow: "off" */
import * as React from 'react';
import * as PropTypes from 'prop-types';
var TagGroup = _Tag.Group;
var ETypeToColor;
(function (ETypeToColor) {
ETypeToColor["warning"] = "orange";
ETypeToColor["middle"] = "blue";
ETypeToColor["success"] = "green";
ETypeToColor["cancel"] = "gray";
ETypeToColor["error"] = "red";
})(ETypeToColor || (ETypeToColor = {}));
var StatusTag = /*#__PURE__*/function (_React$Component) {
_inheritsLoose(StatusTag, _React$Component);
function StatusTag() {
return _React$Component.apply(this, arguments) || this;
}
var _proto = StatusTag.prototype;
// 即便 ts 声明了 TStatusTagProps,这里还是要提供 propsTypes,用于 react 报错提示
_proto.render = function render() {
var _this$props = this.props,
type = _this$props.type,
text = _this$props.text,
color = _this$props.color,
size = _this$props.size,
list = _this$props.list;
if (list !== null && list !== void 0 && list.length) {
return /*#__PURE__*/React.createElement(TagGroup, {
className: "aliretail-tag-group"
}, list.map(function (t) {
return /*#__PURE__*/React.createElement(_Tag, {
type: "normal",
key: t.text || text,
className: ETypeToColor[t.type || type],
size: t.size || size,
color: t.color || color
}, t.text || text);
}));
}
return /*#__PURE__*/React.createElement(TagGroup, {
className: "aliretail-tag-group"
}, /*#__PURE__*/React.createElement(_Tag, {
type: "normal",
size: size,
className: ETypeToColor[type],
color: color
}, text));
};
return StatusTag;
}(React.Component);
StatusTag.propTypes = {
type: PropTypes.string,
text: PropTypes.string,
color: PropTypes.string,
size: PropTypes.string
};
StatusTag.defaultProps = {
type: '',
text: 'tag',
size: 'small'
};
StatusTag.TypeToColor = ETypeToColor;
export { StatusTag, ETypeToColor };
export default StatusTag;