2
2
import Box from '@mui/material/Box' ;
3
3
import Grid from '@mui/material/Grid' ;
4
4
import Stack from '@mui/material/Stack' ;
5
+ import { useMediaQuery } from '@mui/material' ;
6
+ import { useTheme } from '@emotion/react' ;
5
7
// Component Imports
6
8
import { imageList } from './imageList' ;
7
9
8
- const TopImages = ( ) => (
9
- < Grid
10
- container
11
- spacing = { 4 }
12
- sx = { { justifyContent : 'center' , alignItems : 'flex-end' , paddingBottom : '10px' } }
13
- >
14
- { imageList . slice ( 0 , 2 ) . map ( ( { image, alt } ) => (
15
- < Grid item key = { alt } >
16
- < Box
17
- component = "img"
18
- src = { image }
19
- alt = { alt }
20
- style = { { width : '200px' , height : 'auto' , borderRadius : '10px' } }
21
- />
22
- </ Grid >
23
- ) ) }
24
- </ Grid >
25
- ) ;
10
+ const TopImages = ( ) => {
11
+ const theme = useTheme ( ) ;
26
12
27
- const BottomImages = ( ) => {
28
- // Shuffle array
29
- const shuffled = imageList . slice ( 2 ) . sort ( ( ) => 0.5 - Math . random ( ) ) ;
13
+ const isMediumScreen = useMediaQuery ( theme . breakpoints . down ( 'md' ) ) ;
30
14
31
- // Get sub-array of first 3 elements after shuffled
32
- let selected = shuffled . slice ( 0 , 3 ) ;
15
+ return (
16
+ < Grid
17
+ container
18
+ spacing = { 4 }
19
+ sx = { {
20
+ justifyContent : 'center' ,
21
+ alignItems : 'flex-end' ,
22
+ paddingBottom : '10px'
23
+ } }
24
+ >
25
+ { imageList . slice ( 0 , 2 ) . map ( ( { image, alt } ) => (
26
+ < Grid item key = { alt } >
27
+ < Box
28
+ component = "img"
29
+ src = { image }
30
+ alt = { alt }
31
+ style = { {
32
+ width : isMediumScreen ? '125px' : '200px' ,
33
+ height : isMediumScreen ? '125px' : 'auto' ,
34
+ borderRadius : '10px'
35
+ } }
36
+ />
37
+ </ Grid >
38
+ ) ) }
39
+ </ Grid >
40
+ ) ;
41
+ } ;
42
+
43
+ const BottomImages = ( { shuffledImages } ) => {
44
+ const theme = useTheme ( ) ;
45
+
46
+ const isMediumScreen = useMediaQuery ( theme . breakpoints . down ( 'md' ) ) ;
33
47
34
48
const heights = [ '206px' , '274px' , '206px' ] ;
35
49
return (
36
- < Grid container spacing = { 4 } sx = { { justifyContent : 'center' , paddingTop : '20px' } } >
37
- { selected . map ( ( { image, alt } , index ) => (
50
+ < Grid
51
+ container
52
+ spacing = { 4 }
53
+ sx = { { justifyContent : 'center' , paddingTop : '20px' } }
54
+ >
55
+ { shuffledImages . slice ( 0 , 3 ) . map ( ( { image, alt } , index ) => (
38
56
< Grid item key = { alt } >
39
57
< Box
40
58
component = "img"
41
59
src = { image }
42
60
alt = { alt }
43
61
style = { {
44
- width : '200px' ,
45
- height : heights [ index ] ,
62
+ width : isMediumScreen ? '125px' : '200px' ,
63
+ height : isMediumScreen ? '125px' : heights [ index ] ,
46
64
borderRadius : '10px' ,
47
65
objectFit : 'cover' ,
48
66
objectPosition : 'top'
@@ -54,11 +72,15 @@ const BottomImages = () => {
54
72
) ;
55
73
} ;
56
74
57
- const ImageSection = ( ) => (
58
- < Stack >
59
- < TopImages />
60
- < BottomImages />
61
- </ Stack >
62
- ) ;
75
+ const ImageSection = ( ) => {
76
+ // Shuffle array, first two images will be shown in TopImages
77
+ const shuffledImages = imageList . slice ( 2 ) . sort ( ( ) => 0.5 - Math . random ( ) ) ;
78
+ return (
79
+ < Stack >
80
+ < TopImages />
81
+ < BottomImages shuffledImages = { shuffledImages } />
82
+ </ Stack >
83
+ )
84
+ } ;
63
85
64
86
export default ImageSection ;
0 commit comments