Created
July 15, 2021 00:05
-
-
Save actuallyjamez/e23613a66deb9ab04a5ffe3e98db7df2 to your computer and use it in GitHub Desktop.
Simple gatsby image component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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