UNPKG

@kiwicom/orbit-components

Version:

Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com’s products.

122 lines (106 loc) 6.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.StyledBadge = void 0; var React = _interopRequireWildcard(require("react")); var _styledComponents = _interopRequireDefault(require("styled-components")); var _defaultTheme = _interopRequireDefault(require("../defaultTheme")); var _consts = require("./consts"); var _rtl = require("../utils/rtl"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } 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; } var getTypeToken = function getTypeToken(name) { return function (_ref) { var _TOKENS$background, _TOKENS$color, _tokens; var theme = _ref.theme, type = _ref.type; var tokens = (_tokens = {}, _defineProperty(_tokens, _consts.TOKENS.background, (_TOKENS$background = {}, _defineProperty(_TOKENS$background, _consts.TYPE_OPTIONS.NEUTRAL, theme.orbit.backgroundBadgeNeutral), _defineProperty(_TOKENS$background, _consts.TYPE_OPTIONS.INFO, theme.orbit.backgroundBadgeInfo), _defineProperty(_TOKENS$background, _consts.TYPE_OPTIONS.SUCCESS, theme.orbit.backgroundBadgeSuccess), _defineProperty(_TOKENS$background, _consts.TYPE_OPTIONS.WARNING, theme.orbit.backgroundBadgeWarning), _defineProperty(_TOKENS$background, _consts.TYPE_OPTIONS.CRITICAL, theme.orbit.backgroundBadgeCritical), _defineProperty(_TOKENS$background, _consts.TYPE_OPTIONS.DARK, theme.orbit.backgroundBadgeDark), _defineProperty(_TOKENS$background, _consts.TYPE_OPTIONS.WHITE, theme.orbit.backgroundBadgeWhite), _defineProperty(_TOKENS$background, _consts.TYPE_OPTIONS.INFO_INVERTED, theme.orbit.paletteBlueNormal), _defineProperty(_TOKENS$background, _consts.TYPE_OPTIONS.CRITICAL_INVERTED, theme.orbit.paletteRedNormal), _defineProperty(_TOKENS$background, _consts.TYPE_OPTIONS.SUCCESS_INVERTED, theme.orbit.paletteGreenNormal), _defineProperty(_TOKENS$background, _consts.TYPE_OPTIONS.WARNING_INVERTED, theme.orbit.paletteOrangeNormal), _TOKENS$background)), _defineProperty(_tokens, _consts.TOKENS.color, (_TOKENS$color = {}, _defineProperty(_TOKENS$color, _consts.TYPE_OPTIONS.NEUTRAL, theme.orbit.colorTextBadgeNeutral), _defineProperty(_TOKENS$color, _consts.TYPE_OPTIONS.INFO, theme.orbit.colorTextBadgeInfo), _defineProperty(_TOKENS$color, _consts.TYPE_OPTIONS.SUCCESS, theme.orbit.colorTextBadgeSuccess), _defineProperty(_TOKENS$color, _consts.TYPE_OPTIONS.WARNING, theme.orbit.colorTextBadgeWarning), _defineProperty(_TOKENS$color, _consts.TYPE_OPTIONS.CRITICAL, theme.orbit.colorTextBadgeCritical), _defineProperty(_TOKENS$color, _consts.TYPE_OPTIONS.DARK, theme.orbit.colorTextBadgeDark), _defineProperty(_TOKENS$color, _consts.TYPE_OPTIONS.WHITE, theme.orbit.colorTextBadgeWhite), _defineProperty(_TOKENS$color, _consts.TYPE_OPTIONS.INFO_INVERTED, theme.orbit.paletteWhite), _defineProperty(_TOKENS$color, _consts.TYPE_OPTIONS.CRITICAL_INVERTED, theme.orbit.paletteWhite), _defineProperty(_TOKENS$color, _consts.TYPE_OPTIONS.SUCCESS_INVERTED, theme.orbit.paletteWhite), _defineProperty(_TOKENS$color, _consts.TYPE_OPTIONS.WARNING_INVERTED, theme.orbit.paletteWhite), _TOKENS$color)), _tokens); return tokens[name][type]; }; }; var StyledBadge = (0, _styledComponents.default)(function (_ref2) { var className = _ref2.className, children = _ref2.children, dataTest = _ref2.dataTest, ariaLabel = _ref2.ariaLabel; return React.createElement("div", { className: className, "data-test": dataTest, "aria-label": ariaLabel }, children); }).withConfig({ displayName: "Badge__StyledBadge", componentId: "sc-1y6i8f0-0" })(["font-family:", ";display:inline-flex;flex:0 0 auto;box-sizing:border-box;justify-content:center;align-items:center;min-height:", ";line-height:14px;font-size:", ";font-weight:", ";background-color:", ";color:", ";border-radius:", ";padding:", ";"], function (_ref3) { var theme = _ref3.theme; return theme.orbit.fontFamily; }, function (_ref4) { var theme = _ref4.theme; return theme.orbit.heightBadge; }, function (_ref5) { var theme = _ref5.theme; return theme.orbit.fontSizeTextSmall; }, function (_ref6) { var theme = _ref6.theme; return theme.orbit.fontWeightMedium; }, getTypeToken(_consts.TOKENS.background), getTypeToken(_consts.TOKENS.color), function (_ref7) { var theme = _ref7.theme; return theme.orbit.borderRadiusBadge; }, function (_ref8) { var theme = _ref8.theme; return theme.orbit.paddingBadge; }); exports.StyledBadge = StyledBadge; StyledBadge.defaultProps = { theme: _defaultTheme.default }; var IconContainer = (0, _styledComponents.default)(function (_ref9) { var className = _ref9.className, children = _ref9.children; return React.createElement("div", { className: className }, children); }).withConfig({ displayName: "Badge__IconContainer", componentId: "sc-1y6i8f0-1" })(["display:flex;flex-shrink:0;margin:", ";svg{height:", ";width:", ";}"], function (_ref10) { var theme = _ref10.theme, hasContent = _ref10.hasContent; return hasContent && (0, _rtl.rtlSpacing)(theme.orbit.marginBadgeIcon); }, function (_ref11) { var theme = _ref11.theme; return theme.orbit.widthIconSmall; }, function (_ref12) { var theme = _ref12.theme; return theme.orbit.heightIconSmall; }); IconContainer.defaultProps = { theme: _defaultTheme.default }; var StyledBadgeContent = _styledComponents.default.div.withConfig({ displayName: "Badge__StyledBadgeContent", componentId: "sc-1y6i8f0-2" })(["padding:5px 0;line-height:1;"]); StyledBadgeContent.defaultProps = { theme: _defaultTheme.default }; var Badge = function Badge(props) { var _props$type = props.type, type = _props$type === void 0 ? _consts.TYPE_OPTIONS.NEUTRAL : _props$type, icon = props.icon, children = props.children, ariaLabel = props.ariaLabel, dataTest = props.dataTest; return React.createElement(StyledBadge, { type: type, dataTest: dataTest, ariaLabel: ariaLabel }, icon && React.createElement(IconContainer, { type: type, hasContent: !!children }, icon), React.createElement(StyledBadgeContent, null, children)); }; var _default = Badge; exports.default = _default;