import * as React from 'react'; import styled from 'styled-components'; import * as _ from 'styled-components/cssprop'; import { breakpointMedium } from '@tokens'; import { ImageProps } from './interface'; const StyledImg = styled.img` width: 100%; `; const Image: React.FC = ({ alt = '', aspect = '3:2', format = 'webp', src = '', width = 1500 }) => { // If on a small screen, request image at size of screen const baseWidth = window.innerWidth <= breakpointMedium ? window.innerWidth : width; const [a, b] = aspect.split(':').map(x => parseInt(x)); const aspectRatio = a / b; const height = Math.round(baseWidth / aspectRatio); // Setup Contentful image request // https://www.contentful.com/developers/docs/references/images-api/#/reference/resizing-&-cropping/specify-focus-area/retrieve-an-image/console src = src + `?fm=${format}&w=${baseWidth}&h=${height}&f=center&fit=thumb&`; return ; }; export default Image;