zarm
Version:
基于 React 的移动端UI库
35 lines (32 loc) • 1.36 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import { createBEM } from '@zarm-design/bem';
import * as React from 'react';
import { ConfigContext } from '../config-provider';
var Badge = /*#__PURE__*/React.forwardRef(function (props, ref) {
var _ref;
var className = props.className,
shape = props.shape,
bordered = props.bordered,
text = props.text,
children = props.children,
restProps = _objectWithoutProperties(props, ["className", "shape", "bordered", "text", "children"]);
var _React$useContext = React.useContext(ConfigContext),
prefixCls = _React$useContext.prefixCls;
var bem = createBEM('badge', {
prefixCls: prefixCls
});
var cls = bem([(_ref = {}, _defineProperty(_ref, "".concat(shape), !!shape), _defineProperty(_ref, "sup", !!children), _defineProperty(_ref, "bordered", bordered), _ref), className]);
return /*#__PURE__*/React.createElement("span", _extends({
ref: ref,
className: cls
}, restProps), children, /*#__PURE__*/React.createElement("sup", {
className: bem('content')
}, shape !== 'dot' && text));
});
Badge.displayName = 'Badge';
Badge.defaultProps = {
shape: 'dot'
};
export default Badge;