Skip to content

Commit 19ae5f7

Browse files
chore: code refactor
1 parent b782965 commit 19ae5f7

File tree

3 files changed

+112
-104
lines changed

3 files changed

+112
-104
lines changed

src/scenes/Dashboard/fragments/Banner.tsx

+3-49
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,11 @@ import React from 'react';
22
import { Box, Button, Typography, useTheme } from '@mui/material';
33

44
import '../dashboard.styles.css';
5+
import useStyles from '../useStyles';
56

67
const Banner = () => {
78
const theme = useTheme();
8-
const classes = {
9-
bannerContainer: {
10-
height: '1007.93px',
11-
background: "url('/assets/heroImage.png')",
12-
backgroundRepeat: 'no-repeat',
13-
backgroundSize: 'cover',
14-
backgroundPosition: 'center',
15-
opacity: '0.85',
16-
position: 'relative',
17-
zIndex: 1,
18-
},
19-
bannerAdv: {
20-
letterSpacing: '3px',
21-
fontWeight: '600',
22-
fontSize: '16px',
23-
'&.MuiTypography-subtitle1': {},
24-
},
25-
bannerTitle: {
26-
color: '#B88E2F',
27-
fontSize: '52px',
28-
fontStyle: 'normal',
29-
fontWeight: '700',
30-
lineHeight: '65px',
31-
'&.MuiTypography-h6': {},
32-
},
33-
bannerDesc: {
34-
width: '546px',
35-
fontSize: '18px',
36-
fontWeight: '500',
37-
lineHeight: '24px',
38-
letterSpacing: '1.2px',
39-
m: '1rem 0',
40-
'&.MuiTypography-body1': {},
41-
},
42-
button: {
43-
backgroundColor: theme.palette.secondary.main,
44-
color: theme.palette.primary.main,
45-
p: '1.7rem 4rem',
46-
width: '190px',
47-
height: '24px',
48-
textAlign: 'center',
49-
borderRadius: 'none',
50-
'&:hover': {
51-
backgroundColor: theme.palette.secondary[400],
52-
color: theme.palette.primary.main,
53-
},
54-
},
55-
};
9+
const classes = useStyles();
5610
return (
5711
<Box component='main' sx={classes.bannerContainer}>
5812
<Box
@@ -75,7 +29,7 @@ const Banner = () => {
7529
</Typography>
7630
</Box>
7731

78-
<Button variant='contained' size='small' sx={classes.button}>
32+
<Button variant='contained' size='small' sx={classes.bannerButton}>
7933
Buy Now
8034
</Button>
8135
</Box>

src/scenes/Dashboard/fragments/FeaturedProducts.tsx

+7-55
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,21 @@
1-
import {
2-
Box,
3-
Card,
4-
CardMedia,
5-
CardContent,
6-
Typography,
7-
CardActions,
8-
Button,
9-
Container,
10-
useTheme,
11-
Hidden,
12-
Fade,
13-
Backdrop,
14-
} from '@mui/material';
1+
import { Box, Card, CardMedia, CardContent, Typography, Button, Fade } from '@mui/material';
152
import { dataSource } from '../../../data';
163
import { useState } from 'react';
4+
import useStyles from '../useStyles';
175

186
const FeaturedProducts = () => {
19-
const theme = useTheme();
7+
const classes = useStyles();
208
const [hoveredCard, setHoveredCard] = useState<string | null>(null);
9+
const [isHovered, setIsHovered] = useState<boolean>(false);
2110

2211
const handleCardHover = (cardId: string) => {
2312
setHoveredCard(cardId);
13+
setIsHovered(true);
2414
};
2515

2616
const handleCardLeave = () => {
2717
setHoveredCard(null);
28-
};
29-
30-
const classes = {
31-
card: {
32-
maxWidth: '285px',
33-
maxHeight: '446px',
34-
gap: '1rem',
35-
m: '1rem 0.5rem',
36-
borderRadius: 'none',
37-
},
38-
cardMedia: {
39-
width: '285px',
40-
height: '301px',
41-
flexShrink: '0',
42-
},
43-
cardContent: {
44-
width: '285px',
45-
height: '145px',
46-
flexShrink: '0',
47-
backgroundColor: 'var(--color-light-bg, #F4F5F7)',
48-
},
49-
title: {
50-
fontSize: '40px',
51-
fontStyle: 'normal',
52-
fontWeight: '700',
53-
lineHeight: '120%',
54-
m: '1.5rem',
55-
},
56-
button: {
57-
backgroundColor: theme.palette.primary.main,
58-
color: theme.palette.secondary.main,
59-
width: '202px',
60-
height: '48px',
61-
textAlign: 'center',
62-
border: `1px solid ${theme.palette.secondary[200]}`,
63-
'&:hover': {
64-
backgroundColor: theme.palette.primary.main,
65-
color: theme.palette.secondary.main[600],
66-
},
67-
},
18+
setIsHovered(false);
6819
};
6920

7021
return (
@@ -96,6 +47,7 @@ const FeaturedProducts = () => {
9647
</Typography>
9748
</CardContent>
9849
</Card>
50+
9951
<Fade in={hoveredCard === item.id}>
10052
<Button
10153
variant='contained'

src/scenes/Dashboard/useStyles.ts

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import { useTheme } from '@mui/material';
2+
3+
const useStyles = () => {
4+
const theme = useTheme();
5+
6+
const bannerStyles = {
7+
bannerContainer: {
8+
height: '1007.93px',
9+
background: "url('/assets/heroImage.png')",
10+
backgroundRepeat: 'no-repeat',
11+
backgroundSize: 'cover',
12+
backgroundPosition: 'center',
13+
opacity: '0.85',
14+
position: 'relative',
15+
zIndex: 1,
16+
},
17+
bannerAdv: {
18+
letterSpacing: '3px',
19+
fontWeight: '600',
20+
fontSize: '16px',
21+
},
22+
bannerTitle: {
23+
color: '#B88E2F',
24+
fontSize: '52px',
25+
fontStyle: 'normal',
26+
fontWeight: '700',
27+
lineHeight: '65px',
28+
},
29+
bannerDesc: {
30+
width: '546px',
31+
fontSize: '18px',
32+
fontWeight: '500',
33+
lineHeight: '24px',
34+
letterSpacing: '1.2px',
35+
m: '1rem 0',
36+
},
37+
bannerButton: {
38+
backgroundColor: theme.palette.secondary.main,
39+
color: theme.palette.primary.main,
40+
p: '1.7rem 4rem',
41+
width: '190px',
42+
height: '24px',
43+
textAlign: 'center',
44+
borderRadius: 'none',
45+
'&:hover': {
46+
backgroundColor: theme.palette.secondary[400],
47+
color: theme.palette.primary.main,
48+
},
49+
},
50+
};
51+
52+
const featProductStyles = {
53+
card: {
54+
maxWidth: '285px',
55+
maxHeight: '446px',
56+
gap: '1rem',
57+
m: '1rem 0.5rem',
58+
borderRadius: 'none',
59+
},
60+
cardMedia: {
61+
width: '285px',
62+
height: '301px',
63+
flexShrink: '0',
64+
},
65+
cardContent: {
66+
width: '285px',
67+
height: '145px',
68+
flexShrink: '0',
69+
backgroundColor: 'var(--color-light-bg, #F4F5F7)',
70+
},
71+
title: {
72+
fontSize: '40px',
73+
fontStyle: 'normal',
74+
fontWeight: '700',
75+
lineHeight: '120%',
76+
m: '1.5rem',
77+
},
78+
button: {
79+
backgroundColor: theme.palette.primary.main,
80+
color: theme.palette.secondary.main,
81+
width: '202px',
82+
height: '48px',
83+
textAlign: 'center',
84+
border: `1px solid ${theme.palette.secondary[200]}`,
85+
'&:hover': {
86+
backgroundColor: theme.palette.primary.main,
87+
color: theme.palette.secondary.main[600],
88+
},
89+
},
90+
backdrop: {
91+
position: 'absolute',
92+
top: 0,
93+
left: 0,
94+
background: ' rgba(0, 0, 0, 0.5)',
95+
zIndex: 10,
96+
},
97+
};
98+
99+
return { ...bannerStyles, ...featProductStyles };
100+
};
101+
102+
export default useStyles;

0 commit comments

Comments
 (0)