-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProductImages.js
53 lines (51 loc) · 1.14 KB
/
ProductImages.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
import styled from "styled-components";
import {useState} from "react";
const Image = styled.img`
max-width: 100%;
max-height: 100%;
`;
const BigImage = styled.img`
max-width: 100%;
max-height: 200px;
`;
const ImageButtons = styled.div`
display: flex;
gap: 10px;
flex-grow: 0;
margin-top: 10px;
`;
const ImageButton = styled.div`
border: 2px solid #ccc;
${props => props.active ? `
border-color: #ccc;
` : `
border-color: transparent;
`}
height: 40px;
padding: 2px;
cursor: pointer;
border-radius: 5px;
`;
const BigImageWrapper = styled.div`
text-align: center;
`;
export default function ProductImages({images}) {
const [activeImage,setActiveImage] = useState(images?.[0]);
return (
<>
<BigImageWrapper>
<BigImage src={activeImage} />
</BigImageWrapper>
<ImageButtons>
{images.map(image => (
<ImageButton
key={image}
active={image===activeImage}
onClick={() => setActiveImage(image)}>
<Image src={image} alt=""/>
</ImageButton>
))}
</ImageButtons>
</>
);
}