UNPKG

2.74 kBJavaScriptView Raw
1var _excluded = ["className", "cssModule", "color", "innerRef", "pill", "tag"];
2function _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); }
3function _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; }
4function _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; }
5import React from 'react';
6import PropTypes from 'prop-types';
7import classNames from 'classnames';
8import { mapToCssModules, tagPropType } from './utils';
9var propTypes = {
10 /** Pass children so this component can wrap the child elements */
11 children: PropTypes.node,
12 /** Add custom class */
13 className: PropTypes.string,
14 /** Change background color of Badge */
15 color: PropTypes.string,
16 /** Change existing className with a new className */
17 cssModule: PropTypes.object,
18 innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string]),
19 /** Add rounded corners to the Badge */
20 pill: PropTypes.bool,
21 /** Set a custom element for this component */
22 tag: tagPropType
23};
24function Badge(props) {
25 var className = props.className,
26 cssModule = props.cssModule,
27 _props$color = props.color,
28 color = _props$color === void 0 ? 'secondary' : _props$color,
29 innerRef = props.innerRef,
30 _props$pill = props.pill,
31 pill = _props$pill === void 0 ? false : _props$pill,
32 _props$tag = props.tag,
33 Tag = _props$tag === void 0 ? 'span' : _props$tag,
34 attributes = _objectWithoutProperties(props, _excluded);
35 var classes = mapToCssModules(classNames(className, 'badge', 'bg-' + color, pill ? 'rounded-pill' : false), cssModule);
36 if (attributes.href && Tag === 'span') {
37 Tag = 'a';
38 }
39 return /*#__PURE__*/React.createElement(Tag, _extends({}, attributes, {
40 className: classes,
41 ref: innerRef
42 }));
43}
44Badge.propTypes = propTypes;
45export default Badge;
\No newline at end of file