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.

82 lines (68 loc) 2.45 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default; exports.__esModule = 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")); const getHeightToken = ({ theme, size }) => { const tokens = { [_consts.SIZE_OPTIONS.EXTRASMALL]: theme.orbit.heightIllustrationSmall, [_consts.SIZE_OPTIONS.SMALL]: "120px", // TODO: add token [_consts.SIZE_OPTIONS.MEDIUM]: theme.orbit.heightIllustrationMedium, [_consts.SIZE_OPTIONS.LARGE]: "280px", // TODO: create token heightIllustrationLarge [_consts.SIZE_OPTIONS.DISPLAY]: "460px" // TODO: create token heightIllustrationDisplay }; return tokens[size]; }; const StyledImage = _styledComponents.default.img.attrs(({ theme, size, illustrationName }) => { const height = parseInt(getHeightToken({ theme, size }), 10); const illustrationPath = `${illustrationName}-Q85.png`; return { src: `${_consts.baseURL}/illustrations/0x${height}/${illustrationPath}`, srcSet: `${_consts.baseURL}/illustrations/0x${height * 2}/${illustrationPath} 2x, ${_consts.baseURL}/illustrations/0x${height * 3}/${illustrationPath} 3x` }; }).withConfig({ displayName: "IllustrationPrimitive__StyledImage", componentId: "sc-2hh260-0" })(["display:inline-block;margin:auto 0;max-height:", ";max-width:100%;background-color:", ";margin-bottom:", ";flex-shrink:0;"], getHeightToken, ({ theme }) => theme.orbit.backgroundIllustration, _getSpacingToken.default); exports.StyledImage = StyledImage; StyledImage.defaultProps = { theme: _defaultTheme.default }; const IllustrationPrimitive = ({ name, alt, size = _consts.SIZE_OPTIONS.MEDIUM, dataTest, id, spaceAfter }) => { return /*#__PURE__*/React.createElement(StyledImage, { illustrationName: name, alt: typeof alt === "string" ? alt : name, size: size, id: id, "data-test": dataTest, spaceAfter: spaceAfter }); }; var _default = IllustrationPrimitive; exports.default = _default;