Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(images): implement ideal-image-loader
- Loading branch information
1 parent
b5655df
commit 3545b3a
Showing
24 changed files
with
932 additions
and
635 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import GatsbyImage from 'gatsby-image'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
const Image = ({ src, alt, height, width, className, fluid }) => { | ||
const x1 = src && src.x1 ? src.x1 : src; | ||
const x2 = src && src.x2 ? src.x2 : null; | ||
const x3 = src && src.x3 ? src.x3 : null; | ||
|
||
const base64 = x1 && x1.preSrc ? x1.preSrc : ''; | ||
|
||
const src1 = x1 && x1.src ? x1.src : x1; | ||
const src2 = x2 && x2.src ? x2.src : ''; | ||
const src3 = x3 && x3.src ? x3.src : ''; | ||
const webp1 = x1 && x1.webp ? x1.webp : ''; | ||
const webp2 = x2 && x2.webp ? x2.webp : ''; | ||
const webp3 = x3 && x3.webp ? x3.webp : ''; | ||
|
||
const src1FormattedFluid = src1 ? `${src1} ${width}w` : ''; | ||
const src2FormattedFluid = src2 ? `${src2} ${width * 2}w` : ''; | ||
const src3FormattedFluid = src3 ? `${src3} ${width * 3}w` : ''; | ||
const webp1FormattedFluid = webp1 ? `${webp1} ${width}w` : ''; | ||
const webp2FormattedFluid = webp2 ? `${webp2} ${width * 2}w` : ''; | ||
const webp3FormattedFluid = webp3 ? `${webp3} ${width * 3}w` : ''; | ||
|
||
const src1FormattedFixed = src1; | ||
const src2FormattedFixed = src2 ? `${src2} 2x` : ''; | ||
const src3FormattedFixed = src3 ? `${src3} 3x` : ''; | ||
const webp1FormattedFixed = webp1; | ||
const webp2FormattedFixed = webp2 ? `${webp2} 2x` : ''; | ||
const webp3FormattedFixed = webp3 ? `${webp3} 3x` : ''; | ||
|
||
const srcSet = (fluid | ||
? [src1FormattedFluid, src2FormattedFluid, src3FormattedFluid] | ||
: [src1FormattedFixed, src2FormattedFixed, src3FormattedFixed] | ||
) | ||
.filter(Boolean) | ||
.join(', '); | ||
const srcSetWebp = (fluid | ||
? [webp1FormattedFluid, webp2FormattedFluid, webp3FormattedFluid] | ||
: [webp1FormattedFixed, webp2FormattedFixed, webp3FormattedFixed] | ||
) | ||
.filter(Boolean) | ||
.join(', '); | ||
|
||
const imgObj = { | ||
...(fluid | ||
? { | ||
aspectRatio: width / height, | ||
sizes: `(max-width: ${width * 3}px) 100vw, ${width * 3}px`, | ||
} | ||
: { | ||
height, | ||
width, | ||
}), | ||
base64, | ||
src: src2 || src1, | ||
srcWebp: webp2 || webp1, | ||
srcSet, | ||
srcSetWebp, | ||
}; | ||
|
||
return ( | ||
<GatsbyImage | ||
fluid={fluid ? imgObj : null} | ||
fixed={!fluid ? imgObj : null} | ||
alt={alt} | ||
className={className} | ||
/> | ||
); | ||
}; | ||
|
||
Image.propTypes = { | ||
src: PropTypes.oneOfType([ | ||
PropTypes.shape({ | ||
x1: PropTypes.shape({ | ||
src: PropTypes.string.isRequired, | ||
preSrc: PropTypes.string, | ||
webp: PropTypes.string, | ||
}).isRequired, | ||
x2: PropTypes.shape({ | ||
src: PropTypes.string.isRequired, | ||
preSrc: PropTypes.string, | ||
webp: PropTypes.string, | ||
}).isRequired, | ||
x3: PropTypes.shape({ | ||
src: PropTypes.string.isRequired, | ||
preSrc: PropTypes.string, | ||
webp: PropTypes.string, | ||
}).isRequired, | ||
}), | ||
PropTypes.string, | ||
]).isRequired, | ||
alt: PropTypes.string.isRequired, | ||
height: PropTypes.number.isRequired, | ||
width: PropTypes.number.isRequired, | ||
className: PropTypes.string, | ||
fluid: PropTypes.bool, | ||
}; | ||
|
||
Image.defaultProps = { | ||
className: '', | ||
fluid: false, | ||
}; | ||
|
||
export default Image; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,32 @@ | ||
.cover { | ||
color: white; | ||
background: no-repeat center bottom; | ||
background-size: cover; | ||
background-image: url('../img/cover.jpg'); | ||
.container { | ||
position: relative; | ||
height: 100vh; | ||
text-align: center; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
|
||
> div { | ||
margin-bottom: 10px; | ||
.cover { | ||
top: 0; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
position: absolute !important; | ||
height: 100% !important; | ||
width: 100% !important; | ||
|
||
> img { | ||
height: 100% !important; | ||
object-fit: cover; | ||
} | ||
} | ||
|
||
.logo { | ||
height: 100px; | ||
.content { | ||
position: absolute; | ||
height: 100%; | ||
width: 100%; | ||
text-align: center; | ||
color: white; | ||
|
||
.title { | ||
margin: 20% 0 10px; | ||
text-shadow: 1px 0px 1px #CCCCCC, 0px 1px 1px #EEEEEE, 2px 1px 1px #CCCCCC, 1px 2px 1px #EEEEEE, 3px 2px 1px #CCCCCC, 2px 3px 1px #EEEEEE, 4px 3px 1px #CCCCCC, 3px 4px 1px #EEEEEE, 5px 4px 1px #CCCCCC, 4px 5px 1px #EEEEEE, 6px 5px 1px #CCCCCC, 5px 6px 1px #EEEEEE, 7px 6px 1px #CCCCCC; | ||
} | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,32 @@ | ||
.cover { | ||
color: white; | ||
background: no-repeat center bottom; | ||
background-size: cover; | ||
background-image: url('../img/cover.jpg'); | ||
.container { | ||
position: relative; | ||
height: 100vh; | ||
text-align: center; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
|
||
> div { | ||
margin-bottom: 10px; | ||
.cover { | ||
top: 0; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
position: absolute !important; | ||
height: 100% !important; | ||
width: 100% !important; | ||
|
||
> img { | ||
height: 100% !important; | ||
object-fit: cover; | ||
} | ||
} | ||
|
||
.content { | ||
position: absolute; | ||
height: 100%; | ||
width: 100%; | ||
text-align: center; | ||
color: white; | ||
|
||
.title { | ||
margin: 20% 0 10px; | ||
text-shadow: 0 -1px 4px #FFF, 0 -2px 10px #ff0, 0 -10px 20px #ff8000, 0 -18px 40px #F00; | ||
} | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.