UNPKG

@kiwicom/orbit-components

Version:

<div align="center"> <a href="https://orbit.kiwi" target="_blank"> <img alt="orbit-components" src="https://orbit.kiwi/wp-content/uploads/2018/08/orbit-components.png" srcset="https://orbit.kiwi/wp-content/uploads/2018/08/orbit-components@2x.png 2x"

125 lines (102 loc) 5.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _react = require("react"); var React = _interopRequireWildcard(_react); var _styledComponents = require("styled-components"); var _styledComponents2 = _interopRequireDefault(_styledComponents); var _defaultTokens = require("../defaultTokens"); var _defaultTokens2 = _interopRequireDefault(_defaultTokens); var _consts = require("./consts"); 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)) 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.paletteWhite), _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.colorInkDark), _TOKENS$color)), _tokens); return tokens[name][type]; }; }; var StyledBadge = (0, _styledComponents2.default)(function (_ref2) { var className = _ref2.className, children = _ref2.children, dataTest = _ref2.dataTest; return React.createElement( "div", { className: className, "data-test": dataTest }, children ); }).withConfig({ displayName: "Badge__StyledBadge" })(["font-family:", ";display:inline-flex;box-sizing:border-box;justify-content:center;align-items:center;height:", ";line-height:", ";width:", ";font-size:", ";font-weight:", ";background-color:", ";color:", ";border-radius:", ";padding:0 8px;"], 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.heightBadge; }, function (_ref6) { var circled = _ref6.circled, theme = _ref6.theme; return circled && theme.orbit.widthBadgeCircled; }, function (_ref7) { var theme = _ref7.theme; return theme.orbit.fontSizeTextSmall; }, function (_ref8) { var theme = _ref8.theme; return theme.orbit.fontWeightMedium; }, getTypeToken(_consts.TOKENS.background), getTypeToken(_consts.TOKENS.color), function (_ref9) { var theme = _ref9.theme; return theme.orbit.borderRadiusBadge; }); StyledBadge.defaultProps = { theme: _defaultTokens2.default }; var IconContainer = (0, _styledComponents2.default)(function (_ref10) { var className = _ref10.className, children = _ref10.children; return React.createElement( "div", { className: className }, children ); }).withConfig({ displayName: "Badge__IconContainer" })(["display:flex;margin-right:", ";svg{height:", ";width:", ";color:", ";}"], function (_ref11) { var theme = _ref11.theme; return theme.orbit.marginRightBadgeIcon; }, function (_ref12) { var theme = _ref12.theme; return theme.orbit.widthIconSmall; }, function (_ref13) { var theme = _ref13.theme; return theme.orbit.heightIconSmall; }, getTypeToken(_consts.TOKENS.color)); IconContainer.defaultProps = { theme: _defaultTokens2.default }; var Badge = function Badge(props) { var _props$type = props.type, type = _props$type === undefined ? _consts.TYPE_OPTIONS.NEUTRAL : _props$type, icon = props.icon, children = props.children, circled = props.circled, dataTest = props.dataTest; return React.createElement( StyledBadge, { type: type, circled: circled, dataTest: dataTest }, icon && React.createElement( IconContainer, { type: type }, icon ), children ); }; exports.default = Badge;