Skip to content

Commit 257a561

Browse files
committed
refactor: remove z-index-values and use mui variables
1 parent 968f693 commit 257a561

File tree

9 files changed

+54
-76
lines changed

9 files changed

+54
-76
lines changed

src/app/[locale]/(main)/(container)/products/[...params]/components/BuyBox.tsx

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ const BuyBox: FC<BuyBoxProps> = ({ product }) => {
166166
color="primary"
167167
size="large"
168168
onClick={handleClickOnAdd}
169-
sx={{ minHeight: height }}
170169
>
171170
{t('buttons.addToCart')}
172171
</ButtonWithLoading>
@@ -220,36 +219,39 @@ const BuyBox: FC<BuyBoxProps> = ({ product }) => {
220219
flexDirection: 'column',
221220
}}
222221
>
223-
<List>
224-
{listItems.map((item) => {
225-
return (
226-
<>
227-
<ListItem
228-
disablePadding
229-
sx={{
230-
py: 1,
231-
}}
232-
>
233-
<ListItemIcon
222+
{!!listItems?.length && (
223+
<List>
224+
{listItems.map((item) => {
225+
return (
226+
<>
227+
<ListItem
228+
disablePadding
234229
sx={{
235-
minWidth: 0,
236-
mr: 1,
230+
py: 1,
237231
}}
238232
>
239-
{item.icon}
240-
</ListItemIcon>
241-
<ListItemText
242-
primary={item.text}
243-
primaryTypographyProps={{
244-
fontSize: (theme) => theme.typography.caption.fontSize,
245-
}}
246-
/>
247-
</ListItem>
248-
<Divider />
249-
</>
250-
);
251-
})}
252-
</List>
233+
<ListItemIcon
234+
sx={{
235+
minWidth: 0,
236+
mr: 1,
237+
}}
238+
>
239+
{item.icon}
240+
</ListItemIcon>
241+
<ListItemText
242+
primary={item.text}
243+
primaryTypographyProps={{
244+
fontSize: (theme) =>
245+
theme.typography.caption.fontSize,
246+
}}
247+
/>
248+
</ListItem>
249+
<Divider />
250+
</>
251+
);
252+
})}
253+
</List>
254+
)}
253255

254256
{isMobile && (
255257
<MobileBuyBox>

src/app/[locale]/(main)/(container)/products/[...params]/components/ProductTabs.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { Box, Tab, Tabs, Typography } from '@mui/material';
66
import { useTranslations } from 'next-intl';
77
import { FC, SyntheticEvent, useState } from 'react';
88
import { Product } from '../../types/common';
9-
import { Z_INDEX_VALUES } from '@/config/responsive';
109

1110
export interface ProductTabsProps {
1211
content?: string | null;
@@ -36,12 +35,9 @@ const ProductTabs: FC<ProductTabsProps> = ({ content, attributes }) => {
3635
<>
3736
<Box
3837
sx={{
39-
position: 'sticky',
40-
top: 118 + 60,
4138
borderBottom: 1,
4239
borderColor: 'divider',
4340
backgroundColor: (theme) => theme.palette.background.default,
44-
zIndex: Z_INDEX_VALUES.productTabs,
4541
}}
4642
>
4743
<Tabs

src/app/[locale]/(main)/(container)/products/[...params]/page.tsx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { FC } from 'react';
22

33
import Breadcrumbs from '@/components/Breadcrumbs/Breadcrumbs';
4-
import { MOBILE_BUY_BOX_HEIGHT } from '@/config/responsive';
54
import { getClient } from '@/graphql/clients/serverSideClient';
65
import { GET_SINGLE_VARIABLE_PRODUCT_QUERY } from '@/graphql/queries/products';
76
import { GetSingleProductQuery } from '@/graphql/types/graphql';
@@ -67,13 +66,7 @@ const Page: FC<PageProps> = async ({ params: { params } }) => {
6766
selectedVariantId: null,
6867
}}
6968
>
70-
<Grid
71-
container
72-
spacing={2}
73-
sx={{
74-
pb: { xs: `${MOBILE_BUY_BOX_HEIGHT}px` },
75-
}}
76-
>
69+
<Grid container spacing={2}>
7770
<Grid item md={5} xs={12}>
7871
<ProductGallery
7972
thumbnail={product.image}
@@ -115,13 +108,12 @@ const Page: FC<PageProps> = async ({ params: { params } }) => {
115108
</CardContent>
116109
</Card>
117110
</Grid>
118-
<Grid item xs={12}>
119-
<ProductTabs
120-
content={product.content}
121-
attributes={product.customAttributes?.nodes}
122-
/>
123-
</Grid>
124111
</Grid>
112+
113+
<ProductTabs
114+
content={product.content}
115+
attributes={product.customAttributes?.nodes}
116+
/>
125117
</ProductProvider>
126118
);
127119
};

src/app/[locale]/(main)/(container)/products/[...params]/providers/ProductProvider.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
'use client';
22

3-
import React, { FC, PropsWithChildren, useState } from 'react';
3+
import { MOBILE_BUY_BOX_HEIGHT } from '@/config/responsive';
4+
import { useAppContext } from '@/hooks/useAppContext';
5+
import { Box } from '@mui/material';
6+
import { FC, PropsWithChildren, useState } from 'react';
47
import {
58
IProductContext,
69
SelectedVariantId,
@@ -22,14 +25,22 @@ const ProductProvider: FC<PropsWithChildren<ProductProviderProps>> = ({
2225
setSelectedVariantId(+value);
2326
};
2427

28+
const { isMobile } = useAppContext();
29+
2530
return (
2631
<productContext.Provider
2732
value={{
2833
selectedVariantId,
2934
handleChangeSelectedVariantId,
3035
}}
3136
>
32-
{children}
37+
<Box
38+
sx={{
39+
paddingBottom: isMobile ? `${MOBILE_BUY_BOX_HEIGHT}px` : null,
40+
}}
41+
>
42+
{children}
43+
</Box>
3344
</productContext.Provider>
3445
);
3546
};

src/components/Dialog/Dialog.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useAppContext } from '@/hooks/useAppContext';
12
import { Close } from '@mui/icons-material';
23
import { Box, DialogActions, IconButton } from '@mui/material';
34
import MuiDialog, {
@@ -10,8 +11,6 @@ import ButtonWithLoading, {
1011
type ButtonWithLoadingProps,
1112
} from '../common/ButtonWithLoading';
1213
import DialogTransition from '../common/DialogTransition';
13-
import { useAppContext } from '@/hooks/useAppContext';
14-
import { Z_INDEX_VALUES } from '@/config/responsive';
1514

1615
export interface DialogProps extends MuiDialogProps {
1716
dialogContentProps?: DialogContentProps;
@@ -43,15 +42,6 @@ const Dialog: FC<DialogProps> = ({
4342
: {}),
4443
},
4544
}}
46-
slotProps={{
47-
root: isMobile
48-
? {
49-
style: {
50-
zIndex: Z_INDEX_VALUES.dialog,
51-
},
52-
}
53-
: {},
54-
}}
5545
sx={{
5646
...props.sx,
5747
...(isMobile

src/components/Footer/components/MobileFooter.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use client';
22

3-
import { Z_INDEX_VALUES } from '@/config/responsive';
43
import { cartAtom } from '@/store/atoms';
54
import {
65
AccountCircleOutlined,
@@ -73,7 +72,7 @@ const MobileFooter = () => {
7372
position: 'fixed',
7473
bottom: 0,
7574
boxShadow: (theme) => theme.shadows[3],
76-
zIndex: Z_INDEX_VALUES.mobileFooter,
75+
zIndex: (theme) => theme.zIndex.appBar,
7776
}}
7877
>
7978
<MuiBottomNavigation

src/components/Header/Header.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use client';
22

3-
import { Z_INDEX_VALUES } from '@/config/responsive';
43
import { AppBar } from '@mui/material';
54
import { FC, ReactNode } from 'react';
65

@@ -18,7 +17,7 @@ const Header: FC<HeaderProps> = ({ children }) => {
1817
borderColor: (theme) => theme.palette.divider,
1918
position: 'sticky',
2019
top: 0,
21-
zIndex: Z_INDEX_VALUES.siteHeader,
20+
zIndex: (theme) => theme.zIndex.appBar,
2221
}}
2322
>
2423
{children}

src/components/common/ProgressBar.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use client';
22

3-
import { Z_INDEX_VALUES } from '@/config/responsive';
43
import Box from '@mui/material/Box';
54
import LinearProgress from '@mui/material/LinearProgress';
65
import { useEffect, useState } from 'react';
@@ -32,7 +31,7 @@ const ProgressBar = () => {
3231
top: 0,
3332
left: 0,
3433
right: 0,
35-
zIndex: Z_INDEX_VALUES.progressBar,
34+
zIndex: (theme) => theme.zIndex.appBar + 1,
3635
}}
3736
>
3837
<LinearProgress variant="determinate" value={progress} />

src/config/responsive.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,2 @@
11
export const MOBILE_FOOTER_HEIGHT = 56;
2-
export const MOBILE_BUY_BOX_HEIGHT = MOBILE_FOOTER_HEIGHT * 1.8;
3-
4-
export const Z_INDEX_VALUES = {
5-
dialog: 2000,
6-
progressBar: 1300,
7-
siteHeader: 1299,
8-
mobileFooter: 1290,
9-
mobileBuyBox: 1289,
10-
variantSelectorMenu: 10,
11-
productTabs: 9,
12-
};
2+
export const MOBILE_BUY_BOX_HEIGHT = MOBILE_FOOTER_HEIGHT * 1.3;

0 commit comments

Comments
 (0)