-
Notifications
You must be signed in to change notification settings - Fork 310
/
SelectedImage.js
58 lines (51 loc) · 1.54 KB
/
SelectedImage.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
import React, { useState, useEffect } from 'react';
import Checkmark from './icons/checkmark';
const imgStyle = {
transition: 'transform .135s cubic-bezier(0.0,0.0,0.2,1),opacity linear .15s',
};
const selectedImgStyle = {
transform: 'translateZ(0px) scale3d(0.9, 0.9, 1)',
transition: 'transform .135s cubic-bezier(0.0,0.0,0.2,1),opacity linear .15s',
};
const cont = {
backgroundColor: '#eee',
cursor: 'pointer',
overflow: 'hidden',
position: 'relative',
};
const SelectedImage = ({ index, photo, margin, direction, top, left, selected }) => {
const [isSelected, setIsSelected] = useState(selected);
//calculate x,y scale
const sx = (100 - 30 / photo.width * 100) / 100;
const sy = (100 - 30 / photo.height * 100) / 100;
selectedImgStyle.transform = `translateZ(0px) scale3d(${sx}, ${sy}, 1)`;
if (direction === 'column') {
cont.position = 'absolute';
cont.left = left;
cont.top = top;
}
const handleOnClick = e => {
setIsSelected(!isSelected);
};
useEffect(
() => {
setIsSelected(selected);
},
[selected]
);
return (
<div
style={{ margin, height: photo.height, width: photo.width, ...cont }}
className={!isSelected ? 'not-selected' : ''}
>
<Checkmark selected={isSelected ? true : false} />
<img
style={isSelected ? { ...imgStyle, ...selectedImgStyle } : { ...imgStyle }}
{...photo}
onClick={handleOnClick}
/>
<style>{`.not-selected:hover{outline:2px solid #06befa}`}</style>
</div>
);
};
export default SelectedImage;