import cx from "classnames"; import React from "react"; import breakpoints from "../../styles/export/breakpoint"; const overlayBreakpoints: { [key: string]: string } = { ...breakpoints, xxxl: "1920px", }; interface ImageSrcObject { default: string; xxxl?: string; xxl?: string; xl?: string; lg?: string; md?: string; sm?: string; xs?: string; [key: string]: string | undefined; } interface ImageProps { alt: string; src: string | ImageSrcObject; className?: string; [key: string]: any; } const CLASS_ROOT = "img"; const Image: React.FC = ({ className, src, alt, ...other }) => { const classes = cx(CLASS_ROOT, className); if (typeof src === "object") { // autocorrect to descending keys const descendingSrcKeys = Object.keys(src).sort( (a, b) => parseInt(overlayBreakpoints[b]) - parseInt(overlayBreakpoints[a]), ); // this could be done via conditional rendering, but that breaks ¯\_(ツ)_/¯ return ( {descendingSrcKeys.map( (breakpoint) => breakpoint !== "default" && ( ), )} {alt} ); } return {alt}; }; Image.displayName = "Image"; export { Image };