var _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; };

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

import React, { forwardRef } from 'react';

var Badge = forwardRef(function (_ref, ref) {
  var _ref$children = _ref.children,
      children = _ref$children === undefined ? '0' : _ref$children,
      _ref$limit = _ref.limit,
      limit = _ref$limit === undefined ? 2 : _ref$limit,
      _ref$ellipsis = _ref.ellipsis,
      ellipsis = _ref$ellipsis === undefined ? '+' : _ref$ellipsis,
      others = _objectWithoutProperties(_ref, ['children', 'limit', 'ellipsis']);

  // 标题
  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 React.createElement(
    'span',
    _extends({ ref: ref }, others, { className: 'badge' + (others.className ? ' ' + others.className : '') }),
    caption
  );
});

export default Badge;