@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.
57 lines (52 loc) • 2.4 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import * as React from "react";
import styled from "styled-components";
import defaultTheme from "../../defaultTheme";
import { SIZE_OPTIONS, baseURL } from "./consts";
import getSpacingToken from "../../common/getSpacingToken";
var getHeightToken = function getHeightToken(_ref) {
var _tokens;
var theme = _ref.theme,
size = _ref.size;
var tokens = (_tokens = {}, _defineProperty(_tokens, SIZE_OPTIONS.EXTRASMALL, theme.orbit.heightIllustrationSmall), _defineProperty(_tokens, SIZE_OPTIONS.SMALL, "120px"), _defineProperty(_tokens, SIZE_OPTIONS.MEDIUM, theme.orbit.heightIllustrationMedium), _defineProperty(_tokens, SIZE_OPTIONS.LARGE, "280px"), _defineProperty(_tokens, SIZE_OPTIONS.DISPLAY, "460px"), _tokens);
return tokens[size];
};
export var StyledImage = styled.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(baseURL, "/illustrations/0x").concat(height, "/").concat(illustrationPath),
srcSet: "".concat(baseURL, "/illustrations/0x").concat(height * 2, "/").concat(illustrationPath, " 2x, ").concat(baseURL, "/illustrations/0x").concat(height * 3, "/").concat(illustrationPath, " 3x")
};
}).withConfig({
displayName: "IllustrationPrimitive__StyledImage",
componentId: "itt1vn-0"
})(["display:inline-block;margin:auto 0;max-height:", ";max-width:100%;background-color:", ";margin-bottom:", ";flex-shrink:0;"], getHeightToken, function (_ref3) {
var theme = _ref3.theme;
return theme.orbit.backgroundIllustration;
}, getSpacingToken);
StyledImage.defaultProps = {
theme: defaultTheme
};
var IllustrationPrimitive = function IllustrationPrimitive(_ref4) {
var name = _ref4.name,
alt = _ref4.alt,
_ref4$size = _ref4.size,
size = _ref4$size === void 0 ? SIZE_OPTIONS.MEDIUM : _ref4$size,
dataTest = _ref4.dataTest,
spaceAfter = _ref4.spaceAfter;
return /*#__PURE__*/React.createElement(StyledImage, {
illustrationName: name,
alt: typeof alt === "string" ? alt : name,
size: size,
"data-test": dataTest,
spaceAfter: spaceAfter
});
};
export default IllustrationPrimitive;