Last active
July 19, 2020 20:58
-
-
Save 3200pro/9af6d603d828d88cc81b8616ee31f7a8 to your computer and use it in GitHub Desktop.
Gatsby +Sanity: Darkmode image that allow alternate image (Sanity Schema Code)
This file contains 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
/** @jsx jsx */ | |
import { jsx, useColorMode } from "theme-ui" | |
import { buildImageObj } from '../../lib/helpers' | |
import { imageUrlFor } from '../../lib/image-url' | |
function DarkModeImage (props) { | |
const [colorMode] = useColorMode() | |
const SanityImageToggle = (colorMode == 'light') ? props.primaryImage : props.darkmodeImage | |
return ( | |
<figure> | |
<img src={imageUrlFor(buildImageObj(SanityImageToggle)).url()} alt={props.alt}/> | |
</figure> | |
) | |
} | |
export default DarkModeImage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment