var _excluded = ["children", "limit", "ellipsis"];

function _extends() { _extends = Object.assign || 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); }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

import React, { forwardRef } from 'react';
var Badge = forwardRef(function (_ref, ref) {
  var _ref$children = _ref.children,
      children = _ref$children === void 0 ? '0' : _ref$children,
      _ref$limit = _ref.limit,
      limit = _ref$limit === void 0 ? 2 : _ref$limit,
      _ref$ellipsis = _ref.ellipsis,
      ellipsis = _ref$ellipsis === void 0 ? '+' : _ref$ellipsis,
      others = _objectWithoutPropertiesLoose(_ref, _excluded);

  // 标题
  var caption = children;

  if (limit && children && (typeof children === 'string' || typeof children === 'number')) {
    // 数字大于99,则显示99+
    if (!isNaN(children)) {
      caption = children.length > limit ? '99999'.substring(0, limit) + ellipsis : children;
    } else {
      caption = children.length > limit ? children.substring(0, limit) + ellipsis : children;
    }
  }

  return /*#__PURE__*/React.createElement("span", _extends({
    ref: ref
  }, others, {
    className: "badge" + (others.className ? ' ' + others.className : '')
  }), caption);
});
export default Badge;