Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Suthesh/gatsby image nextgen #23

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"dependencies": {
"@artsy/fresnel": "^1.2.2",
"@svgr/webpack": "^5.4.0",
"@wardpeet/gatsby-image-nextgen": "0.0.2",
"babel-plugin-styled-components": "^1.11.1",
"commander": "^6.1.0",
"crc-32": "^1.2.0",
Expand Down
4 changes: 4 additions & 0 deletions src/components/elements/image/image-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ export const ImageWrapper = styled.div`
width: 100%;
height: 100%;
}
& .gatsby-image {
width: 100%;
height: 100%;
}
`
34 changes: 34 additions & 0 deletions src/components/elements/image/image.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React from 'react'
import Img from 'gatsby-image'
import { GatsbyImage } from '@wardpeet/gatsby-image-nextgen'
import { ImageWrapper } from './image-style'

export const Image = ({ data, alt, width, height, className }) => {
if (data) {
const data_fluid = data.childImageSharp.fluid
const data_fixed = data.childImageSharp.fixed

return (
<ImageWrapper className={className} width={width} height={height}>
<Img
Expand All @@ -19,3 +21,35 @@ export const Image = ({ data, alt, width, height, className }) => {

return null
}

export const NextGenImage = ({ data, alt, width, height, className }) => {
if (data) {
const data_fluid = data.childImageSharp.fluid
const data_fixed = data.childImageSharp.fixed

return (
<ImageWrapper className={className} width={width} height={height}>
<GatsbyImage
alt={alt}
images={{
fallback: {
src: data_fluid ? data_fluid.src : data_fixed.src,
srcSet: data_fluid ? data_fluid.srcSet : data_fixed.srcSet,
},
sources: [
{
src: data_fluid ? data_fluid.srcWebp : data_fixed.srcWebp,
srcSet: data_fluid ? data_fluid.srcSetWebp : data_fixed.srcSetWebp,
type: 'image/webp',
},
],
}}
height="100%"
layout={data_fluid ? 'fluid' : 'fixed'}
/>
</ImageWrapper>
)
}

return null
}
30 changes: 26 additions & 4 deletions src/pages/home/_hero.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useSnackbar } from 'react-simple-snackbar'
import { StyledInput, StyledText, LogoWrapper, StyledImage, HeroContainer } from './_home-style'
import { Media } from 'themes'
import Login from 'common/login'
import { WhiteText, Button, Flex, Image, Text, Background } from 'components/elements'
import { WhiteText, Button, Flex, NextGenImage, Text, Background } from 'components/elements'
import { localize, Localize } from 'components/localization'
import { BinarySocketBase } from 'websocket/socket_base'
import TrafficSource from 'common/traffic-source'
Expand All @@ -21,10 +21,32 @@ const query = graphql`
...fadeIn
}
hero_desktop: file(relativePath: { eq: "home/desktop/hero-image.png" }) {
...desktopFadeIn
childImageSharp {
# Specify the image processing specifications right in the query.
# Makes it trivial to update as your page's design changes.
fixed(width: 688, height: 382) {
fallback: base64
width
height
src
srcSet
srcWebp
srcSetWebp
}
}
}
hero_mobile: file(relativePath: { eq: "home/mobile/hero-image.png" }) {
...mobileFadeIn
childImageSharp {
# Specify the image processing specifications right in the query.
# Makes it trivial to update as your page's design changes.
fluid {
fallback: base64
src
srcSet
srcWebp
srcSetWebp
}
}
}
}
`
Expand Down Expand Up @@ -190,7 +212,7 @@ export const Hero = () => {
</Flex>
<div>
<Media greaterThanOrEqual="desktop">
<Image
<NextGenImage
data={data['hero_desktop']}
alt="platform devices desktop"
width="688px"
Expand Down
42 changes: 36 additions & 6 deletions src/pages/home/_highlights.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,43 @@ import { SectionContainer } from 'components/elements'
const query = graphql`
query {
anytime: file(relativePath: { eq: "home/anytime-anywhere.jpg" }) {
...fadeIn
childImageSharp {
# Specify the image processing specifications right in the query.
# Makes it trivial to update as your page's design changes.
fluid {
fallback: base64
src
srcSet
srcWebp
srcSetWebp
}
}
}
crypto: file(relativePath: { eq: "home/crypto-wallets.png" }) {
...fadeIn
childImageSharp {
# Specify the image processing specifications right in the query.
# Makes it trivial to update as your page's design changes.
fluid {
fallback: base64
src
srcSet
srcWebp
srcSetWebp
}
}
}
deposit: file(relativePath: { eq: "home/minimum-deposit.jpg" }) {
...fadeIn
childImageSharp {
# Specify the image processing specifications right in the query.
# Makes it trivial to update as your page's design changes.
fluid {
fallback: base64
src
srcSet
srcWebp
srcSetWebp
}
}
}
}
`
Expand All @@ -43,7 +73,7 @@ export const Highlights = () => {
data={data.anytime}
alt="highlights anytime"
width={{ _: '300px', xxl: '588px' }}
height={{ _: '100%', xxl: '100%' }}
height={{ _: '310px', xxl: '688px' }}
/>
</ContentWrapper>
</PartitionContainer>
Expand All @@ -64,7 +94,7 @@ export const Highlights = () => {
data={data.crypto}
alt="crypto wallet"
width={{ _: '292px', xxl: '528px' }}
height={{ _: '100%', xxl: '528px' }}
height={{ _: '292px', xxl: '528px' }}
/>
</ContentWrapper>
</PartitionContainer>
Expand All @@ -85,7 +115,7 @@ export const Highlights = () => {
data={data.deposit}
alt="deposit"
width={{ _: '276px', xxl: '510px' }}
height={{ _: '100%', xxl: '256px' }}
height={{ _: '138px', xxl: '256px' }}
/>
</ContentWrapper>
</PartitionContainer>
Expand Down
5 changes: 3 additions & 2 deletions src/pages/home/_home-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Image,
Text,
Background,
NextGenImage,
} from 'components/elements'
import { device } from 'themes/device'

Expand Down Expand Up @@ -46,7 +47,7 @@ export const LogoWrapper = styled(Flex)`
margin-left: 8px;
`

export const StyledImage = styled(Image)`
export const StyledImage = styled(NextGenImage)`
@media ${device.mobileS} {
width: 329px;
height: 181px;
Expand Down Expand Up @@ -83,7 +84,7 @@ export const ContentWrapper = styled(Container)`
}
`

export const HighLightsImage = styled(Image)`
export const HighLightsImage = styled(NextGenImage)`
margin: auto;
`

Expand Down
18 changes: 15 additions & 3 deletions src/pages/home/_reviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,26 @@ import {
Carousel,
SectionContainer,
Container,
Image,
NextGenImage,
} from 'components/elements'
import { Localize, localize } from 'components/localization'

const query = graphql`
query {
jose: file(relativePath: { eq: "home/reviews/jose.png" }) {
...fadeIn
childImageSharp {
# Specify the image processing specifications right in the query.
# Makes it trivial to update as your page's design changes.
fixed(width: 48, height: 48) {
fallback: base64
width
height
src
srcSet
srcWebp
srcSetWebp
}
}
}
}
`
Expand All @@ -27,7 +39,7 @@ const Card = ({ name, quote, location, image }) => {
{quote}
</CenterText>
<Flex m="auto">
<Image data={image} alt="jose" width="48px" height="48px" />
<NextGenImage data={image} alt="jose" width="48px" height="48px" />
<VFlex ml={'xs'}>
<Text fontSize={'s'} fontWeight="bold">
{name}
Expand Down