zent
Version:
一套前端设计语言和基于React的实现
52 lines (51 loc) • 2.3 kB
JavaScript
import { __assign, __extends } from "tslib";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { PureComponent } from 'react';
import cx from 'classnames';
var NO_STYLE = {};
var Badge = (function (_super) {
__extends(Badge, _super);
function Badge() {
return _super !== null && _super.apply(this, arguments) || this;
}
Badge.prototype.renderCount = function () {
var _a = this.props, count = _a.count, maxCount = _a.maxCount, dot = _a.dot, showZero = _a.showZero, offset = _a.offset, style = _a.style;
var posStyle = Array.isArray(offset) && offset.length === 2
? {
right: offset[0],
top: offset[1],
}
: NO_STYLE;
var badgeStyle = style ? __assign(__assign({}, style), posStyle) : posStyle;
if (dot) {
return _jsx("span", { className: "zent-badge-dot", style: badgeStyle, "data-zv": '10.0.17' }, void 0);
}
else if (count > 0 || (count === 0 && showZero)) {
return (_jsx("span", __assign({ className: "zent-badge-count", style: badgeStyle, "data-zv": '10.0.17' }, { children: _jsx("span", __assign({ className: "zent-badge-count-num", "data-zv": '10.0.17' }, { children: count > maxCount ? maxCount + "+" : count }), void 0) }), void 0));
}
return null;
};
Badge.prototype.render = function () {
var _a;
var _b = this.props, className = _b.className, children = _b.children;
var containerCls = cx((_a = {
'zent-badge': true,
'zent-badge--has-content': children,
'zent-badge--no-content': !children
},
_a[className] = !!className,
_a['zent-badge-none-cont'] = !children,
_a));
return (_jsxs("div", __assign({ className: containerCls, "data-zv": '10.0.17' }, { children: [children ? _jsx("div", __assign({ className: "zent-badge-content", "data-zv": '10.0.17' }, { children: children }), void 0) : null, this.renderCount()] }), void 0));
};
Badge.defaultProps = {
count: 0,
maxCount: 99,
dot: false,
showZero: false,
className: '',
};
return Badge;
}(PureComponent));
export { Badge };
export default Badge;