Files

137 lines
3.5 KiB
JavaScript
Raw Permalink Normal View History

'use client'
2021-09-21 21:28:04 +02:00
import {useState} from 'react'
2020-12-11 01:36:54 +01:00
import PropTypes from 'prop-types'
import {useRouter, usePathname} from 'next/navigation'
2020-12-11 01:36:54 +01:00
2022-01-19 07:06:26 +04:00
import {styled} from '@mui/material/styles'
import AppBar from '@mui/material/AppBar'
2022-01-22 15:46:33 +04:00
import Tabs, {tabsClasses} from '@mui/material/Tabs'
2022-01-19 07:06:26 +04:00
import Tab from '@mui/material/Tab'
import Typography from '@mui/material/Typography'
import Box from '@mui/material/Box'
2022-01-22 15:46:33 +04:00
import {useMediaQuery} from '@mui/material'
2020-12-11 01:36:54 +01:00
import MusicNoteIcon from '@mui/icons-material/MusicNote'
import RecordVoiceOverIcon from '@mui/icons-material/RecordVoiceOver'
import HomeIcon from '@mui/icons-material/Home'
import VolunteerActivismIcon from '@mui/icons-material/VolunteerActivism'
2022-01-19 06:35:04 +04:00
const PREFIX = 'navigasyon'
const classes = {
root: `${PREFIX}-root`
}
2022-01-20 20:29:11 +04:00
const Appdiv = styled('div')((
2022-01-19 06:35:04 +04:00
{
theme
}
) => ({
[`& .${classes.root}`]: {
flexGrow: 1,
width: '100%',
backgroundColor: theme.palette.background.paper
}
}))
2020-12-11 01:36:54 +01:00
const tabRouteHref = [
'/',
'/sipote',
2022-03-13 01:38:45 +04:00
'/paroles',
2026-04-28 12:34:20 +04:00
'/awtis'
2020-12-11 01:36:54 +01:00
]
const tabPath = {
akey: 0,
sipote: 1,
paroles: 2,
awtis: 3,
}
2020-12-11 01:36:54 +01:00
function TabPanel(props) {
const {children, value, index, ...other} = props
return (
2022-01-20 20:29:11 +04:00
<div
2020-12-11 01:36:54 +01:00
role='tabpanel'
hidden={value !== index}
id={`scrollable-force-tabpanel-${index}`}
aria-labelledby={`scrollable-force-tab-${index}`}
{...other}
>
{value === index && (
<Box p={3}>
<Typography component='div'>{children}</Typography>
</Box>
)}
2022-01-20 20:29:11 +04:00
</div>
2020-12-11 01:36:54 +01:00
)
}
TabPanel.propTypes = {
children: PropTypes.node,
index: PropTypes.any.isRequired,
value: PropTypes.any.isRequired
}
function a11yProps(index) {
return {
id: `scrollable-force-tab-${index}`,
'aria-controls': `scrollable-force-tabpanel-${index}`
}
}
export default function Navigasyon() {
2020-12-11 01:36:54 +01:00
const router = useRouter()
const pathname = usePathname()
const selectedPath = pathname === '/' ? 'akey' : pathname.split('/')[1]
const selectedTab = tabPath[selectedPath]
2022-01-22 15:46:33 +04:00
const isMobile = useMediaQuery('(max-width:422px)')
2021-09-21 21:28:04 +02:00
const [value, setValue] = useState(0)
2020-12-11 01:36:54 +01:00
const handleChange = (event, newValue) => {
setValue(newValue)
2020-12-16 00:14:43 +01:00
if (newValue !== selectedTab) {
router.push(tabRouteHref[newValue])
2020-12-16 00:14:43 +01:00
}
2020-12-11 01:36:54 +01:00
}
return (
2022-01-20 20:29:11 +04:00
<Appdiv>
<div className={classes.root}>
<AppBar style={{zIndex: 1, boxShadow: 'none'}} position='fixed' color='default'>
2026-04-21 19:32:58 +04:00
{selectedTab !== undefined && <Tabs
allowScrollButtonsMobile
scrollButtons
centered={Boolean(!isMobile)}
value={selectedTab}
indicatorColor='primary'
textColor='primary'
aria-label='tabs menu'
variant={isMobile ? 'scrollable' : 'fullWidth'}
sx={{
[`& .${tabsClasses.scrollButtons}`]: {
'&.Mui-disabled': {opacity: 0.3},
},
}}
onChange={handleChange}
>
<Tab icon={<HomeIcon />} aria-label='Accueil' {...a11yProps(0)} />
<Tab icon={<VolunteerActivismIcon />} aria-label='Nous soutenir' {...a11yProps(1)} />
<Tab icon={<MusicNoteIcon />} aria-label='Paroles' {...a11yProps(2)} />
<Tab icon={<RecordVoiceOverIcon />} aria-label='Artistes' {...a11yProps(3)} />
</Tabs>
}
2022-01-20 20:29:11 +04:00
</AppBar>
<TabPanel value={value} index={0} />
<TabPanel value={value} index={1} />
<TabPanel value={value} index={2} />
<TabPanel value={value} index={3} />
</div>
</Appdiv>
)
2020-12-11 01:36:54 +01:00
}