UNPKG

@activecollab/components

Version:

ActiveCollab Components

71 lines (69 loc) 2.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Badge = void 0; var _react = _interopRequireDefault(require("react")); var _classnames = _interopRequireDefault(require("classnames")); var _Styles = require("./Styles"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } var getLabel = function getLabel(value, cap) { if (!value) { return null; } return cap && value > cap ? "".concat(cap, "+") : value; }; /** * @component Badge * @description * A small pill that sits on the corner of an avatar or an icon, or stands in a * row on its own. It shows a count, or nothing at all when it marks a state. * * @prop {position} - dictates the position of a badge. * @prop {dimension} - controls the height of a badge in pixels. The width grows with the content. * @prop {shape} - "pill" adds horizontal padding so the badge reads as long. * @prop {cap} - the highest number shown. Above it the badge renders `{cap}+`. * @prop {backgroundColor} - background-color of a badge. * @prop {textColor} - color of the number. * @prop {isStandalone} - takes the badge out of absolute positioning. * * @example * <IconButton variant="text gray" size="big"> * <BellOffIcon /> * <Badge position="top-right" backgroundColor="var(--red-alert)" dimension={16} value={7} cap={99} /> * </IconButton> * * @see * https://system.activecollab.com/?path=/story/components-indicators-badge--badge */ var Badge = exports.Badge = function Badge(_ref) { var _ref$dimension = _ref.dimension, dimension = _ref$dimension === void 0 ? 8 : _ref$dimension, className = _ref.className, _ref$position = _ref.position, position = _ref$position === void 0 ? "bottom-left" : _ref$position, backgroundColor = _ref.backgroundColor, textColor = _ref.textColor, value = _ref.value, cap = _ref.cap, _ref$shape = _ref.shape, shape = _ref$shape === void 0 ? "circle" : _ref$shape, _ref$shadows = _ref.shadows, shadows = _ref$shadows === void 0 ? false : _ref$shadows, _ref$isStandalone = _ref.isStandalone, isStandalone = _ref$isStandalone === void 0 ? false : _ref$isStandalone; var label = getLabel(value, cap); return /*#__PURE__*/_react.default.createElement(_Styles.StyledBadge, { className: (0, _classnames.default)("c-badge", className), dimension: dimension, position: position, shape: shape, shadows: shadows, hasLabel: label !== null, isStandalone: isStandalone, backgroundColor: backgroundColor, textColor: textColor, role: "status" }, label); }; //# sourceMappingURL=Badge.js.map