optimizely-oui
Version:
Optimizely's Component Library.
62 lines (50 loc) • 3.27 kB
JavaScript
function _extends() { _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; }; return _extends.apply(this, arguments); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _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; }
function _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; }
import React from "react";
import PropTypes from "prop-types";
import classNames from "classnames";
import { FILL_COLOR_MAP } from "../../utils/accessibility";
/**
* Tiny inline component used to draw attention to an item's state or status.
* @param {Object} props - Properties passed to component
* @returns {ReactElement}
*/
var Badge = function Badge(_ref) {
var backgroundColor = _ref.backgroundColor,
children = _ref.children,
className = _ref.className,
color = _ref.color,
testSection = _ref.testSection,
props = _objectWithoutProperties(_ref, ["backgroundColor", "children", "className", "color", "testSection"]);
var classes = classNames(_defineProperty({
"oui-badge": true
}, "oui-badge--".concat(color), color), className); // ensure valid backgroundColor name
// (in the case that propType errors are ignored)
var badgeFillColor = backgroundColor && color === "default" && (Object.keys(FILL_COLOR_MAP).includes(backgroundColor) ? FILL_COLOR_MAP[backgroundColor] : null);
return React.createElement("span", _extends({
"data-oui-component": true,
className: classes,
style: {
backgroundColor: badgeFillColor
},
"data-test-section": testSection
}, props), children);
};
Badge.propTypes = {
/** @deprecated Color to use for the background of the token */
backgroundColor: PropTypes.oneOf(["yellow", "default", "green", "orange", "pink", "magenta", "grey", "purple", "black"]),
/** Text that appears within the component */
children: PropTypes.node.isRequired,
/* CSS class names. */
className: PropTypes.string,
/** Various color schemes. Purple has been deprecated 2021-06-08. */
color: PropTypes.oneOf(["default", "draft", "live", "primary", "plain", "purple", "bad-news"]),
/** Hook for automated JavaScript tests */
testSection: PropTypes.string
};
Badge.defaultProps = {
color: "default"
};
export default Badge;