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.

110 lines (97 loc) 5.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var React = _interopRequireWildcard(require("react")); var _styledComponents = _interopRequireDefault(require("styled-components")); var _defaultTokens = _interopRequireDefault(require("../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)) { 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), _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), _TOKENS$color)), _tokens); return tokens[name][type]; }; }; var StyledBadge = (0, _styledComponents.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", componentId: "sc-1y6i8f0-0" })(["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: _defaultTokens.default }; var IconContainer = (0, _styledComponents.default)(function (_ref10) { var className = _ref10.className, children = _ref10.children; return React.createElement("div", { className: className }, children); }).withConfig({ displayName: "Badge__IconContainer", componentId: "sc-1y6i8f0-1" })(["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: _defaultTokens.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, circled = props.circled, dataTest = props.dataTest; return React.createElement(StyledBadge, { type: type, circled: circled, dataTest: dataTest }, icon && React.createElement(IconContainer, { type: type }, icon), children); }; var _default = Badge; exports.default = _default;