Skip to content

Instantly share code, notes, and snippets.

@actuallyjamez
Created July 15, 2021 00:05
Show Gist options
  • Select an option

  • Save actuallyjamez/e23613a66deb9ab04a5ffe3e98db7df2 to your computer and use it in GitHub Desktop.

Select an option

Save actuallyjamez/e23613a66deb9ab04a5ffe3e98db7df2 to your computer and use it in GitHub Desktop.
Simple gatsby image component
import React, { ReactNode } from "react";
import { GatsbyImage } from "gatsby-plugin-image";
interface BackgroundImageProps extends React.HTMLAttributes<HTMLDivElement> {
image: any;
children: ReactNode;
}
const BackgroundImage = ({ image, children, ...div }: BackgroundImageProps) => {
return (
<div {...div}>
<div
style={{ position: "relative", display: "inline-block", width: "100%" }}
>
<GatsbyImage
image={image}
alt="Background Image"
style={{ position: "absolute", height: "100%", width: "100%" }}
/>
<div style={{ position: "relative", zIndex: 20 }}>{children}</div>
</div>
</div>
);
};
export default BackgroundImage;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment