@@ -2,7 +2,7 @@ import { useEffect } from 'react';
22import { Outlet , useLocation , useNavigate } from 'react-router-dom' ;
33
44// material-ui
5- import { useTheme } from '@mui/material/styles' ;
5+ import { styled , useTheme } from '@mui/material/styles' ;
66import useMediaQuery from '@mui/material/useMediaQuery' ;
77import AppBar from '@mui/material/AppBar' ;
88import Container from '@mui/material/Container' ;
@@ -16,15 +16,64 @@ import MainContentStyled from './MainContentStyled';
1616import Loader from 'ui-component/Loader' ;
1717import Breadcrumbs from 'ui-component/extended/Breadcrumbs' ;
1818
19- import { MenuOrientation } from 'config' ;
19+ import { MenuOrientation , ThemeMode } from 'config' ;
2020import useConfig from 'hooks/useConfig' ;
2121import { handlerDrawerOpen , useGetMenuMaster } from 'api/menu' ;
2222import Tabs from '@mui/material/Tabs' ;
23- import Tab from '@mui/material/Tab' ;
23+ import Tab , { TabProps } from '@mui/material/Tab' ;
2424import MainCard from '../../ui-component/cards/MainCard' ;
2525
2626// ==============================|| MAIN LAYOUT ||============================== //
2727
28+ // icon tab style
29+ const AntTabs = styled ( Tabs ) ( ( { theme } ) => ( {
30+ background : theme . palette . mode === ThemeMode . DARK ? theme . palette . dark [ 800 ] : theme . palette . primary . light ,
31+ width : 'fit-content' ,
32+ borderBottom : 'none' , // убираем бордер
33+ '& .MuiTabs-flexContainer' : {
34+ border : '1px solid' ,
35+ borderRadius : '12px' ,
36+ borderColor : '#3F3F3F' ,
37+ height : '61px'
38+ } ,
39+ '& .MuiTabs-scroller' : {
40+ borderBottom : 'none'
41+ } ,
42+ borderRadius : '12px' ,
43+ boxShadow : 'none' ,
44+ '& .MuiTabs-indicator' : {
45+ backgroundColor : theme . palette . secondary . main ,
46+ height : 0 // скрываем индикатор активного таба
47+ }
48+ } ) ) ;
49+
50+ // style constant
51+ const AntTab = styled ( ( props : TabProps ) => < Tab disableRipple { ...props } /> ) ( ( { theme } ) => ( {
52+ textTransform : 'none' ,
53+ minWidth : 0 ,
54+ fontWeight : theme . typography . fontWeightRegular ,
55+ fontFamily : 'Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif' ,
56+ // fontWeight: 500, // Medium
57+ fontSize : '16px' ,
58+ color : theme . palette . grey [ 100 ] ,
59+ '&.MuiTab-root' : {
60+ borderRight : '1px solid #3F3F3F' ,
61+ borderColor : '#3F3F3F' ,
62+ minWidth : '125px'
63+ } ,
64+ '&:hover' : {
65+ color : theme . palette . grey [ 500 ] ,
66+ opacity : 1
67+ } ,
68+ '&.Mui-selected' : {
69+ color : theme . palette . background . default ,
70+ backgroundColor : theme . palette . secondary . main ,
71+ fontWeight : theme . typography . fontWeightMedium
72+ } ,
73+ '&.Mui-focusVisible' : {
74+ backgroundColor : theme . palette . secondary . main
75+ }
76+ } ) ) ;
2877export default function MainLayout ( ) {
2978 const theme = useTheme ( ) ;
3079 const downMD = useMediaQuery ( theme . breakpoints . down ( 'md' ) ) ;
@@ -72,24 +121,42 @@ export default function MainLayout() {
72121 < MainContentStyled { ...{ borderRadius, menuOrientation, open : drawerOpen , marginTop : 80 } } >
73122 < Container
74123 maxWidth = { 'lg' }
75- sx = { { ...( ! container && { px : { xs : 0 } } ) , minHeight : 'calc(100vh - 228px)' , display : 'flex' , flexDirection : 'column' } }
124+ sx = { {
125+ ...( ! container && { px : { xs : 0 } } ) ,
126+ minHeight : 'calc(100vh - 228px)' ,
127+ display : 'flex' ,
128+ flexDirection : 'column'
129+ } }
76130 >
77131 { /* breadcrumb */ }
78132 < Breadcrumbs />
79133 { /*<Outlet />*/ }
80134
135+ { /*<MainCard>*/ }
81136 < MainCard >
82- < Box sx = { { width : '100%' } } >
83- < Tabs value = { currentTabIndex } onChange = { handleChange } centered >
84- { tabs . map ( ( tab ) => (
85- < Tab key = { tab . path } label = { tab . label } />
86- ) ) }
87- </ Tabs >
88- < Box sx = { { p : 3 } } >
89- < Outlet />
90- </ Box >
137+ < AntTabs value = { currentTabIndex } onChange = { handleChange } centered >
138+ { tabs . map ( ( tab , index ) => (
139+ < AntTab
140+ wrapped = { true }
141+ key = { tab . path }
142+ label = { tab . label }
143+ onClick = { ( ) => {
144+ const tabPath = `/${ tab . path } ` ;
145+ // клик на активный таб
146+ if ( currentTabIndex === index ) {
147+ navigate ( tabPath , { replace : true , state : { refresh : Date . now ( ) } } ) ;
148+ } else {
149+ navigate ( tabPath ) ;
150+ }
151+ } }
152+ />
153+ ) ) }
154+ </ AntTabs >
155+ < Box sx = { { pt : 3 } } >
156+ < Outlet />
91157 </ Box >
92158 </ MainCard >
159+ { /*</MainCard>*/ }
93160 </ Container >
94161 { /* footer */ }
95162 < Footer />
0 commit comments