Skip to content

Instantly share code, notes, and snippets.

@captain-woof
Created August 31, 2021 18:03
Show Gist options
  • Select an option

  • Save captain-woof/6ba72aea6029c8d693784e64c3accddf to your computer and use it in GitHub Desktop.

Select an option

Save captain-woof/6ba72aea6029c8d693784e64c3accddf to your computer and use it in GitHub Desktop.
React Waterfall Grid example
import styled from 'styled-components'
import {WaterfallGrid} from 'react-waterfall-grid'
import { useMediaQuery } from 'react-responsive'
// You are free to add as many grid contents as you want. Here, you see only 4 pictures.
import Image1 from './static/images/1.jpg'
import Image2 from './static/images/2.jpg'
import Image3 from './static/images/3.jpg'
import Image4 from './static/images/4.jpg'
const ParentContainer = styled.div`
width: 100%;
background-color: #121212;
`
const Image = styled.img`
object-fit: cover;
`
export default function App() {
// Boolean - True if phone
const isPhone = useMediaQuery({ query: 'max-width: 480px' })
// List of images <img>
const imagesList = [Image1, Image2, Image3, Image4].map((imagePath) => (
<Image key={imagePath} style={{ width: (isPhone ? "200px" : "300px") }} src={imagePath} alt={imagePath}
variants={imageVariants} whileHover={{ scale: 1.05, transition: { ease: ease, duration: 0.8 } }} />
))
return (
<ParentContainer id="parent-container">
<WaterfallGrid childItems={imagesList} childWidth={isPhone ? 200 : 300}
styleGridContainer={{ width: "100%", position: "relative", justifyContent: "center", zIndex: 1 }}/>
</ParentContainer>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment