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.

59 lines (54 loc) 1.68 kB
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"; const getHeightToken = ({ theme, size }) => { const tokens = { [SIZE_OPTIONS.SMALL]: theme.orbit.heightIllustrationSmall, [SIZE_OPTIONS.MEDIUM]: theme.orbit.heightIllustrationMedium, [SIZE_OPTIONS.LARGE]: "280px", // TODO: create token heightIllustrationLarge [SIZE_OPTIONS.DISPLAY]: "460px" // TODO: create token heightIllustrationDisplay }; return tokens[size]; }; export const StyledImage = styled.img.attrs(({ theme, size, illustrationName }) => { const height = parseInt(getHeightToken({ theme, size }), 10); const illustrationPath = `${illustrationName}-Q85.png`; return { src: `${baseURL}/illustrations/0x${height}/${illustrationPath}`, srcSet: `${baseURL}/illustrations/0x${height * 2}/${illustrationPath} 2x, ${baseURL}/illustrations/0x${height * 3}/${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, ({ theme }) => theme.orbit.backgroundIllustration, getSpacingToken); StyledImage.defaultProps = { theme: defaultTheme }; const Illustration = ({ name, size = SIZE_OPTIONS.MEDIUM, dataTest, spaceAfter }) => React.createElement(StyledImage, { illustrationName: name, alt: name, size: size, "data-test": dataTest, spaceAfter: spaceAfter }); export default Illustration;