|
| 1 | +import React from 'react' |
| 2 | +import PropTypes from 'prop-types' |
| 3 | + |
| 4 | +import Image from 'gatsby-image' |
| 5 | + |
| 6 | +// Styling based on https://codepen.io/havardob/pen/ZOOmMe |
| 7 | + |
| 8 | +const data = { |
| 9 | + 'alisa-anton-166247-unsplash-2000px': { |
| 10 | + style: { left: `6vw`, bottom: `6vw` }, |
| 11 | + author: `Alisa Anton`, |
| 12 | + url: `https://unsplash.com/photos/ukxAK0c2FqM`, |
| 13 | + }, |
| 14 | + 'anthony-esau-173126-unsplash-2000px': { |
| 15 | + style: { left: `30vw`, bottom: `12vw` }, |
| 16 | + author: `Anthony Esau`, |
| 17 | + url: `https://unsplash.com/photos/N2zk9yXjmLA`, |
| 18 | + }, |
| 19 | + 'beth-solano-313648-unsplash-2000px': { |
| 20 | + style: { left: `39vw`, top: `3vw` }, |
| 21 | + author: `Beth Solando`, |
| 22 | + url: `https://unsplash.com/photos/VGkn9ENxLXM`, |
| 23 | + }, |
| 24 | + 'desmond-simon-412494-unsplash-2000px': { |
| 25 | + style: { right: `5vw`, bottom: `5vw` }, |
| 26 | + author: `Desmond Simon`, |
| 27 | + url: `https://unsplash.com/photos/HhOo98Iygps`, |
| 28 | + }, |
| 29 | + 'igor-ovsyannykov-307432-unsplash-2000px': { |
| 30 | + style: { right: `27vw`, bottom: `3vw` }, |
| 31 | + author: `Igor Ovsyannykov`, |
| 32 | + url: `https://unsplash.com/photos/uzd2UEDdQJ8`, |
| 33 | + }, |
| 34 | + 'quino-al-101314-unsplash-2000px': { |
| 35 | + style: { right: `28vw`, bottom: `27vw` }, |
| 36 | + author: `Quino Al`, |
| 37 | + url: `https://unsplash.com/photos/vBxlL1xpSdc`, |
| 38 | + }, |
| 39 | + 'samuel-zeller-16570-unsplash-2000px': { |
| 40 | + style: { right: `16vw`, top: `2vw` }, |
| 41 | + author: `Samuel Zeller`, |
| 42 | + url: `https://unsplash.com/photos/CwkiN6_qpDI`, |
| 43 | + }, |
| 44 | + 'tyler-lastovich-205631-unsplash-2000px': { |
| 45 | + style: { right: `3vw`, top: `14vw` }, |
| 46 | + author: `Tyler Lastovich`, |
| 47 | + url: `https://unsplash.com/photos/DMJUIGRO_1M`, |
| 48 | + }, |
| 49 | +} |
| 50 | + |
| 51 | +function generateStyle(imageData) { |
| 52 | + const rotation = Math.floor(Math.random() * 26) - 13 |
| 53 | + return { |
| 54 | + boxSizing: `content-box`, |
| 55 | + |
| 56 | + display: `block`, |
| 57 | + position: `absolute`, |
| 58 | + |
| 59 | + width: `18vw`, |
| 60 | + |
| 61 | + padding: `0.8vw 0.4vw 0`, |
| 62 | + background: `linear-gradient(120deg, #fff, #eee 60%)`, |
| 63 | + |
| 64 | + color: `inherit`, |
| 65 | + |
| 66 | + boxShadow: `2px 2px 7px 0px rgba(0,0,0,0.4), rgba(0, 0, 0, 0.1) 1px 1px 3px 0px inset`, |
| 67 | + transform: `rotate(${rotation}deg)`, |
| 68 | + |
| 69 | + ...imageData.style, |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +const Polaroid = ({ image }) => { |
| 74 | + const imageData = data[image.name] |
| 75 | + |
| 76 | + return ( |
| 77 | + <a |
| 78 | + href={imageData.url} |
| 79 | + title={`by ${imageData.author}`} |
| 80 | + style={generateStyle(imageData)} |
| 81 | + > |
| 82 | + <div style={{ position: `relative` }}> |
| 83 | + <Image |
| 84 | + sizes={{ |
| 85 | + ...image.childImageSharp.sizes, |
| 86 | + base64: image.childImageSharp.sqip.dataURI, |
| 87 | + }} |
| 88 | + /> |
| 89 | + <div |
| 90 | + style={{ |
| 91 | + position: `absolute`, |
| 92 | + top: 0, |
| 93 | + left: 0, |
| 94 | + background: `linear-gradient(120deg, rgba(255, 255, 255, 0.5), transparent 60%, rgba(0, 0, 0, 0.4) 99%)`, |
| 95 | + boxShadow: `inset 4px 5px 10px 0 rgba(0,0,0,0.05)`, |
| 96 | + width: `100%`, |
| 97 | + height: `100%` |
| 98 | + }} |
| 99 | + /> |
| 100 | + </div> |
| 101 | + <div |
| 102 | + style={{ |
| 103 | + lineHeight: `4vw`, |
| 104 | + textAlign: `center`, |
| 105 | + fontSize: `1.6vw`, |
| 106 | + }} |
| 107 | + >{`📷 ${imageData.author}`}</div> |
| 108 | + </a> |
| 109 | + ) |
| 110 | +} |
| 111 | + |
| 112 | +Polaroid.propTypes = { |
| 113 | + image: PropTypes.object, |
| 114 | +} |
| 115 | + |
| 116 | +export default Polaroid |
0 commit comments