@alifd/meet-react
Version:
Fusion Mobile React UI System Component
70 lines (69 loc) • 4.01 kB
JavaScript
;
exports.__esModule = true;
exports.default = void 0;
var _babelRuntimeJsxStyleTransform = require("@alifd/babel-runtime-jsx-style-transform");
var _tslib = require("tslib");
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _view = _interopRequireDefault(require("../view"));
var _createChildren = _interopRequireDefault(require("./create-children"));
var _utils = require("../utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
var Tag = function (props, ref) {
var _classNames;
var _props$prefix = props.prefix,
prefix = _props$prefix === void 0 ? 'mt-' : _props$prefix,
_props$size = props.size,
size = _props$size === void 0 ? 'medium' : _props$size,
_props$type = props.type,
type = _props$type === void 0 ? 'normal' : _props$type,
_props$disabled = props.disabled,
disabled = _props$disabled === void 0 ? false : _props$disabled,
_props$onClick = props.onClick,
onClick = _props$onClick === void 0 ? function () {} : _props$onClick,
_props$style = props.style,
style = _props$style === void 0 ? {} : _props$style,
children = props.children,
color = props.color,
textColorProp = props.textColor,
className = props.className,
others = (0, _tslib.__rest)(props, ["prefix", "size", "type", "disabled", "onClick", "style", "children", "color", "textColor", "className"]);
var cssType = type === 'normal' ? 'outline' : 'solid';
var tagCls = (0, _classnames.default)(className, prefix + "tag", prefix + "tag--" + size, prefix + "tag--readonly-" + size, prefix + "tag--normal-" + cssType, (_classNames = {}, _classNames[prefix + "tag--normal-" + cssType + "-disabled"] = disabled, _classNames));
var textColor = textColorProp;
if ((0, _utils.isString)(color) && !textColor) {
if (type === 'primary') {
textColor = '#fff';
} else {
textColor = color;
}
}
var newStyle = Object.assign(Object.assign(Object.assign({}, (0, _utils.isString)(color) && type === 'primary' ? {
backgroundColor: color
} : {
borderColor: color
}), (0, _utils.isString)(textColor) ? {
color: textColor
} : null), style);
return /*#__PURE__*/(0, _react.createElement)(_view.default, _extends({}, others, {
ref: ref,
className: tagCls,
onClick: function handleClick(e) {
if (disabled) {
return;
}
if (onClick) {
onClick(e);
}
},
style: (0, _babelRuntimeJsxStyleTransform.rpx2vw4style)(newStyle)
}), (0, _createChildren.default)(children, {
textCls: prefix + "tag-font--" + size,
iconCls: prefix + "tag-font--" + size
}, prefix, size));
};
Tag.displayName = 'Tag';
var _default = exports.default = /*#__PURE__*/(0, _react.forwardRef)(Tag);