@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.
75 lines (60 loc) • 3.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.StyledImage = void 0;
var React = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
var _defaultTheme = _interopRequireDefault(require("../defaultTheme"));
var _consts = require("./consts");
var _getSpacingToken = _interopRequireDefault(require("../common/getSpacingToken"));
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 getHeightToken = function getHeightToken(_ref) {
var _tokens;
var theme = _ref.theme,
size = _ref.size;
var tokens = (_tokens = {}, _defineProperty(_tokens, _consts.SIZE_OPTIONS.SMALL, theme.orbit.heightIllustrationSmall), _defineProperty(_tokens, _consts.SIZE_OPTIONS.MEDIUM, theme.orbit.heightIllustrationMedium), _defineProperty(_tokens, _consts.SIZE_OPTIONS.LARGE, "280px"), _tokens);
return tokens[size];
};
var StyledImage = _styledComponents.default.img.attrs(function (_ref2) {
var theme = _ref2.theme,
size = _ref2.size,
illustrationName = _ref2.illustrationName;
var height = parseInt(getHeightToken({
theme: theme,
size: size
}), 10);
var illustrationPath = "".concat(illustrationName, "-Q85.png");
return {
src: "".concat(_consts.baseURL, "/illustrations/0x").concat(height, "/").concat(illustrationPath),
srcSet: "".concat(_consts.baseURL, "/illustrations/0x").concat(height * 2, "/").concat(illustrationPath, " 2x, ").concat(_consts.baseURL, "/illustrations/0x").concat(height * 3, "/").concat(illustrationPath, " 3x")
};
}).withConfig({
displayName: "Illustration__StyledImage",
componentId: "uskdow-0"
})(["display:inline-block;margin:auto 0;max-height:", ";max-width:100%;background-color:", ";margin-bottom:", ";"], getHeightToken, function (_ref3) {
var theme = _ref3.theme;
return theme.orbit.backgroundIllustration;
}, _getSpacingToken.default);
exports.StyledImage = StyledImage;
StyledImage.defaultProps = {
theme: _defaultTheme.default
};
var Illustration = function Illustration(_ref4) {
var name = _ref4.name,
_ref4$size = _ref4.size,
size = _ref4$size === void 0 ? _consts.SIZE_OPTIONS.MEDIUM : _ref4$size,
dataTest = _ref4.dataTest,
spaceAfter = _ref4.spaceAfter;
return React.createElement(StyledImage, {
illustrationName: name,
alt: name,
size: size,
"data-test": dataTest,
spaceAfter: spaceAfter
});
};
var _default = Illustration;
exports.default = _default;