-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCoverImage.js
More file actions
51 lines (46 loc) · 1.34 KB
/
CoverImage.js
File metadata and controls
51 lines (46 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* global window */
import React from 'react';
import styled from 'styled-components';
import Media from 'react-media';
import ProgressiveImage from 'react-progressive-bg-image';
import landscapeX60 from '../statics/images/landscapeX60.jpg';
import landscape from '../statics/images/landscape.jpg';
import portraitX60 from '../statics/images/portraitX60.jpg';
import portrait from '../statics/images/portrait.jpg';
/**
* matchMedia polyfill
* set default value to true
* ref: https://github.com/WickyNilliams/enquire.js/issues/82#issuecomment-26990494
* @author Michael Hsu
*/
window.matchMedia =
window.matchMedia ||
function matchMedia() {
return {
matches: true, // Desktop First
addListener: () => {},
removeListener: () => {},
};
};
const StyledProgressiveImage = styled(ProgressiveImage)`
height: calc(100vh - 120px);
width: auto;
background-color: aliceblue;
background-size: cover;
background-attachment: fixed;
background-position-y: 60%;
background-position-x: center;
overflow: hidden;
`;
const CoverImage = () => (
<Media query={{ minWidth: 1000 }}>
{matches => (
<StyledProgressiveImage
src={matches ? landscape : portrait}
placeholder={matches ? landscapeX60 : portraitX60}
/>
)}
</Media>
);
CoverImage.displayName = 'CoverImage';
export default CoverImage;