UNPKG

2.94 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7var _react = _interopRequireDefault(require("react"));
8var _propTypes = _interopRequireDefault(require("prop-types"));
9var _classnames = _interopRequireDefault(require("classnames"));
10var _utils = require("./utils");
11const _excluded = ["className", "cssModule", "color", "innerRef", "pill", "tag"];
12function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13function _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); }
14function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
15function _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; }
16const propTypes = {
17 /** Pass children so this component can wrap the child elements */
18 children: _propTypes.default.node,
19 /** Add custom class */
20 className: _propTypes.default.string,
21 /** Change background color of Badge */
22 color: _propTypes.default.string,
23 /** Change existing className with a new className */
24 cssModule: _propTypes.default.object,
25 innerRef: _propTypes.default.oneOfType([_propTypes.default.object, _propTypes.default.func, _propTypes.default.string]),
26 /** Add rounded corners to the Badge */
27 pill: _propTypes.default.bool,
28 /** Set a custom element for this component */
29 tag: _utils.tagPropType
30};
31function Badge(props) {
32 let {
33 className,
34 cssModule,
35 color = 'secondary',
36 innerRef,
37 pill = false,
38 tag: Tag = 'span'
39 } = props,
40 attributes = _objectWithoutProperties(props, _excluded);
41 const classes = (0, _utils.mapToCssModules)((0, _classnames.default)(className, 'badge', 'bg-' + color, pill ? 'rounded-pill' : false), cssModule);
42 if (attributes.href && Tag === 'span') {
43 Tag = 'a';
44 }
45 return /*#__PURE__*/_react.default.createElement(Tag, _extends({}, attributes, {
46 className: classes,
47 ref: innerRef
48 }));
49}
50Badge.propTypes = propTypes;
51var _default = Badge;
52exports.default = _default;
\No newline at end of file