|
@@ -9,7 +9,8 @@ import {
|
9
|
9
|
} from "@mui/material";
|
10
|
10
|
import Grid from '@mui/material/Grid2';
|
11
|
11
|
import CloseIcon from "@mui/icons-material/Close";
|
12
|
|
-import defaultImage from "../../assets/images/default.png"
|
|
12
|
+import defaultImage from "../../assets/images/default.png";
|
|
13
|
+import { Carousel } from 'react-responsive-carousel';
|
13
|
14
|
|
14
|
15
|
// Utility function to check if an object is empty
|
15
|
16
|
const isEmptyObject = (obj) => Object.keys(obj).length === 0 && obj.constructor === Object;
|
|
@@ -20,6 +21,7 @@ const ImageView = () => {
|
20
|
21
|
|
21
|
22
|
const [previewImage, setPreviewImage] = useState("");
|
22
|
23
|
const [isZoomed, setIsZoomed] = useState(false);
|
|
24
|
+ const [currentIndex, setCurrentIndex] = useState(0);
|
23
|
25
|
|
24
|
26
|
useEffect(() => {
|
25
|
27
|
|
|
@@ -37,6 +39,10 @@ const ImageView = () => {
|
37
|
39
|
setIsZoomed(!isZoomed);
|
38
|
40
|
};
|
39
|
41
|
|
|
42
|
+ const handleSlideChange = (index) => {
|
|
43
|
+ setPreviewImage(product?.images[index]?.url)
|
|
44
|
+ };
|
|
45
|
+
|
40
|
46
|
return (
|
41
|
47
|
<Box sx={{ flexGrow: 1 }}>
|
42
|
48
|
<Grid container spacing={2}>
|
|
@@ -46,24 +52,32 @@ const ImageView = () => {
|
46
|
52
|
sx={{
|
47
|
53
|
overflow: "hidden",
|
48
|
54
|
cursor: "pointer",
|
|
55
|
+ px: {
|
|
56
|
+ xs: 0,
|
|
57
|
+ sm: 0,
|
|
58
|
+ md: 15
|
|
59
|
+ }
|
49
|
60
|
}}
|
50
|
|
- onClick={handleZoomToggle}
|
51
|
61
|
>
|
52
|
|
- <Box
|
53
|
|
- src={previewImage || defaultImage}
|
54
|
|
- component="img"
|
55
|
|
- alt="Preview"
|
56
|
|
- sx={{
|
57
|
|
- width: {
|
58
|
|
- xs: "100%",
|
59
|
|
- sm: "100%",
|
60
|
|
- md: "70%"
|
61
|
|
- },
|
62
|
|
- height: "auto",
|
63
|
|
- display: "block",
|
64
|
|
- margin: "auto auto"
|
65
|
|
- }}
|
66
|
|
- />
|
|
62
|
+
|
|
63
|
+ <Carousel showStatus={false} showIndicators={false} onClickItem={() => { handleZoomToggle() }} onChange={(index) => handleSlideChange(index)} selectedItem={currentIndex}>
|
|
64
|
+ {product?.images?.map(({ src, url }, index) => (
|
|
65
|
+ <Box
|
|
66
|
+ key={index}
|
|
67
|
+ component="img"
|
|
68
|
+ src={url}
|
|
69
|
+ alt={`img_${index + 1}`}
|
|
70
|
+ sx={{
|
|
71
|
+ width: "100%",
|
|
72
|
+ zIndex: 0,
|
|
73
|
+ position: "relative",
|
|
74
|
+ top: "50%",
|
|
75
|
+ transform: "translateY(-50%)"
|
|
76
|
+ }}
|
|
77
|
+ />
|
|
78
|
+ ))}
|
|
79
|
+ </Carousel>
|
|
80
|
+
|
67
|
81
|
</Box>
|
68
|
82
|
</Grid>
|
69
|
83
|
|
|
@@ -87,10 +101,14 @@ const ImageView = () => {
|
87
|
101
|
{product?.images?.map(({ src, url }, index) => (
|
88
|
102
|
<IconButton
|
89
|
103
|
key={index}
|
90
|
|
- onClick={() => handleThumbnailClick(url)}
|
|
104
|
+ onClick={() => {
|
|
105
|
+ handleThumbnailClick(url)
|
|
106
|
+ setCurrentIndex(index)
|
|
107
|
+ }}
|
91
|
108
|
sx={{
|
92
|
|
- borderRadius: 2,
|
93
|
|
- overflow: "hidden",
|
|
109
|
+ p:0.4,
|
|
110
|
+ borderRadius: 1,
|
|
111
|
+ backgroundColor: (previewImage == url) ? "#95AAC5" : "none"
|
94
|
112
|
}}
|
95
|
113
|
>
|
96
|
114
|
<img
|
|
@@ -111,16 +129,24 @@ const ImageView = () => {
|
111
|
129
|
|
112
|
130
|
{/* Zoom Dialog */}
|
113
|
131
|
<Dialog open={isZoomed} onClose={handleZoomToggle} maxWidth="lg">
|
114
|
|
- <DialogContent sx={{ position: "relative" }}>
|
115
|
|
- <img
|
116
|
|
- src={previewImage || defaultImage}
|
117
|
|
- alt="Zoomed Preview"
|
118
|
|
- style={{
|
119
|
|
- width: "100%",
|
120
|
|
- height: "auto",
|
|
132
|
+ <DialogContent
|
|
133
|
+ sx={{
|
|
134
|
+ position: "relative",
|
|
135
|
+ overflow: "hidden", // Prevent scrolling on DialogContent
|
|
136
|
+ height: "90vh", // Adjust height as needed
|
|
137
|
+ }}
|
|
138
|
+ >
|
|
139
|
+ {/* Fixed position close button */}
|
|
140
|
+ <Box
|
|
141
|
+ sx={{
|
|
142
|
+ width: 50,
|
|
143
|
+ height: 50,
|
|
144
|
+ position: "absolute",
|
|
145
|
+ top: 10,
|
|
146
|
+ right: 1.5,
|
|
147
|
+ zIndex: 2, // Ensure it stays above other content
|
121
|
148
|
}}
|
122
|
|
- />
|
123
|
|
- <Box sx={{ width: 50, height: 50, position: "absolute", top: 10, right: 10 }}>
|
|
149
|
+ >
|
124
|
150
|
<IconButton
|
125
|
151
|
onClick={handleZoomToggle}
|
126
|
152
|
sx={{
|
|
@@ -134,8 +160,26 @@ const ImageView = () => {
|
134
|
160
|
<CloseIcon />
|
135
|
161
|
</IconButton>
|
136
|
162
|
</Box>
|
|
163
|
+
|
|
164
|
+ {/* Scrollable content */}
|
|
165
|
+ <Box
|
|
166
|
+ sx={{
|
|
167
|
+ overflow: "auto", // Allow scrolling within this Box
|
|
168
|
+ height: "100%", // Fill available height of DialogContent
|
|
169
|
+ }}
|
|
170
|
+ >
|
|
171
|
+ <img
|
|
172
|
+ src={previewImage || defaultImage}
|
|
173
|
+ alt="Zoomed Preview"
|
|
174
|
+ style={{
|
|
175
|
+ width: "100%",
|
|
176
|
+ height: "auto",
|
|
177
|
+ }}
|
|
178
|
+ />
|
|
179
|
+ </Box>
|
137
|
180
|
</DialogContent>
|
138
|
181
|
</Dialog>
|
|
182
|
+
|
139
|
183
|
</Box>
|
140
|
184
|
);
|
141
|
185
|
};
|