-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGridImage.js
72 lines (65 loc) · 1.81 KB
/
GridImage.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import React from "react";
import PropTypes from "prop-types";
import styled from "styled-components";
/**
* A single image element in a masonry style image grid
*/
const GridImage = ({ key, index, left, top, photo, onClick }) => {
const { height, width, src, alt, caption } = photo;
return (
<ImageContainer
key={`${key}-${index}`}
index={index}
onClick={e => onClick(e, { index })}
style={{ left, top, height, width }}
>
<OverlayContainer className='MainGimg'>
<Image src={src} alt={alt} caption={caption} />
<Caption className='overlayCap'>
<span>{caption}</span>
</Caption>
</OverlayContainer>
</ImageContainer>
);
};
GridImage.propTypes = {
key: PropTypes.string.isRequired,
index: PropTypes.number.isRequired,
left: PropTypes.number.isRequired,
top: PropTypes.number.isRequired,
containerHeight: PropTypes.number.isRequired,
onClick: PropTypes.func.isRequired,
photo: PropTypes.shape({
alt: PropTypes.string.isRequired,
caption: PropTypes.string.isRequired,
height: PropTypes.number.isRequired,
width: PropTypes.number.isRequired,
src: PropTypes.string.isRequired
}).isRequired
};
export default GridImage;
const Caption = styled.div`
position: absolute;
`;
const OverlayContainer = styled.div`
position: relative;
height: 100%;
overflow: hidden;
`;
const ImageContainer = styled.div`
transition: border-color 0.2s linear;
display: block;
position: absolute;
cursor: pointer;
border-width: 0;
border-color: transparent;
border-style: solid;
:hover {
border-color: ${({ theme }) => theme.pageContentLinkHoverColor};
}
`;
const Image = styled.img`
width: inherit;
height: inherit;
position: absolute;
`;