choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
54 lines (45 loc) • 1.34 kB
JavaScript
import React, { useEffect } from 'react';
import { observer } from 'mobx-react-lite';
import isNil from 'lodash/isNil';
import noop from 'lodash/noop';
function getCount(count) {
if (typeof count === 'function') {
return count();
}
return count;
}
function defaultRenderer(props) {
var text = props.text;
if (text) {
return text;
}
}
var Count = function Count(props) {
var count = props.count,
overflowCount = props.overflowCount,
prefixCls = props.prefixCls,
_props$renderer = props.renderer,
renderer = _props$renderer === void 0 ? defaultRenderer : _props$renderer,
_props$asyncCount = props.asyncCount,
asyncCount = _props$asyncCount === void 0 ? noop : _props$asyncCount;
var number = getCount(count);
useEffect(function () {
if (count !== number) {
asyncCount();
}
}, [number]);
var renderedText = renderer({
text: overflowCount && number && number > overflowCount ? "".concat(overflowCount, "+") : number,
count: number,
overflowCount: overflowCount
});
if (!isNil(renderedText)) {
return /*#__PURE__*/React.createElement("span", {
className: "".concat(prefixCls, "-tab-count")
}, renderedText);
}
return null;
};
Count.displayName = 'Count';
export default observer(Count);
//# sourceMappingURL=Count.js.map