UNPKG

@alifd/meet-react

Version:

Fusion Mobile React UI System Component

45 lines 3.43 kB
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _extends() { _extends = Object.assign ? Object.assign.bind() : 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 _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } import { __rest } from "tslib"; import React, { createElement, forwardRef, Children } from "react"; import classNames from 'classnames'; import { Text } from "@alifd/meet-react-component-one"; import View from '../view'; var Badge = function Badge(props, ref) { var _props$overflowCount = props.overflowCount, overflowCount = _props$overflowCount === void 0 ? 99 : _props$overflowCount, className = props.className, _props$count = props.count, count = _props$count === void 0 ? 0 : _props$count, _props$dot = props.dot, dot = _props$dot === void 0 ? false : _props$dot, children = props.children, _props$content = props.content, content = _props$content === void 0 ? '' : _props$content, _props$prefix = props.prefix, prefix = _props$prefix === void 0 ? 'mt-' : _props$prefix, others = __rest(props, ["overflowCount", "className", "count", "dot", "children", "content", "prefix"]); var type = dot ? 'dot' : 'normal'; var auto = Children.count(children) > 0; var sup = count; sup = Number(count); if (!isNaN(sup) && sup !== 0) { sup = sup > overflowCount ? "".concat(overflowCount, "+") : sup; } else { sup = count; } var BadgeComponent = sup === 0 && type === 'normal' && !content ? null : /*#__PURE__*/React.createElement(View, { className: classNames(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "".concat(prefix, "badge--custom"), content), "".concat(prefix, "badge-content"), !content), "".concat(prefix, "badge-content--").concat(type), !content), "".concat(prefix, "badge-content--auto"), auto)) }, content ? content : dot ? null : /*#__PURE__*/React.createElement(Text, { className: "".concat(prefix, "badge-text") }, sup)); return /*#__PURE__*/React.createElement(View, _extends({}, others, { ref: ref, className: classNames(className, "".concat(prefix, "badge"), "".concat(prefix, "badge--").concat(type), _defineProperty({}, "".concat(prefix, "badge--auto"), auto)) }), children, BadgeComponent); }; Badge.displayName = 'Badge'; export default /*#__PURE__*/forwardRef(Badge);