generated from usetrio/boilerplate-bikerent-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBikeImageSelector.component.tsx
55 lines (50 loc) · 1.44 KB
/
BikeImageSelector.component.tsx
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
import BikeImageList from 'components/BikeImageList'
import { BikeImage, Container } from './BikeImageSelector.styles'
import BikePlaceholder from 'assets/bike-placeholder.png'
interface BikeImageSelectorComponentProps {
selectedImageUrl: string
selectedImageIndex: number
imageUrls: string[]
isImageLoaded: boolean
handleSelectImage: (imageUrl: string, index: number) => void
handleIsImageLoaded: (newStatus: boolean) => void
}
const BikeImageSelector = ({
selectedImageUrl,
selectedImageIndex,
imageUrls,
isImageLoaded,
handleIsImageLoaded,
handleSelectImage,
}: BikeImageSelectorComponentProps) => {
return (
<Container data-testid='bike-image-selector'>
<BikeImageList
selectedImageUrl={selectedImageUrl}
selectedImageIndex={selectedImageIndex}
imageUrls={imageUrls}
handleSelectImage={handleSelectImage}
/>
{!isImageLoaded && (
<img
src={BikePlaceholder}
width='100%'
height='100%'
alt="Bigger bike's image Placeholder"
/>
)}
<BikeImage
isLoaded={isImageLoaded}
key={selectedImageUrl}
src={selectedImageUrl}
width='100%'
height='100%'
alt="Bigger bike's image"
data-testid='bike-selected-image'
onLoadStart={() => handleIsImageLoaded(false)}
onLoad={() => handleIsImageLoaded(true)}
/>
</Container>
)
}
export default BikeImageSelector