UNPKG

@jdcfe/yep-react

Version:

一套移动端的React组件库

52 lines (42 loc) 1.75 kB
import _extends from "@babel/runtime/helpers/extends"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; var __rest = this && this.__rest || function (s, e) { var t = {}; for (var p in s) { if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; } if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import * as React from 'react'; import classNames from 'classnames'; function Badge(props) { var _classNames; var className = props.className, prefixCls = props.prefixCls, children = props.children, text = props.text, max = props.max, dot = props.dot, restProps = __rest(props, ["className", "prefixCls", "children", "text", "max", "dot"]); text = typeof text === 'number' && text > max ? "".concat(max, "+") : text; // dot mode don't need text if (dot) { text = ''; } var scrollNumberCls = classNames((_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-dot"), dot), _defineProperty(_classNames, "".concat(prefixCls, "-text"), !dot), _classNames)); var badgeCls = classNames(prefixCls, className, _defineProperty({}, "".concat(prefixCls, "-not-a-wrapper"), !children)); return /*#__PURE__*/React.createElement("span", { className: badgeCls }, children, (text || dot) && /*#__PURE__*/React.createElement("sup", _extends({ className: scrollNumberCls }, restProps), text)); } Badge.defaultProps = { prefixCls: 'Yep-badge', style: {}, max: 99, dot: false }; export default Badge;