Files
pawol.nu/components/navigasyon.js
T

133 lines
3.2 KiB
JavaScript
Raw Normal View History

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} from 'next/router'
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
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 = [
'/',
2022-03-13 01:38:45 +04:00
'/paroles',
2021-09-29 18:59:31 +02:00
'/awtis?paj&paj=1',
2022-02-19 22:09:15 +04:00
'/soumet',
'/soutyen'
2020-12-11 01:36:54 +01:00
]
const tabRouteAs = [
'/',
2022-03-13 01:38:45 +04:00
'/paroles',
2021-09-29 18:59:31 +02:00
'/awtis/paj/1',
2022-02-19 22:09:15 +04:00
'/soumet',
'/soutyen'
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({selectedTab}) {
const router = useRouter()
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) {
2020-12-17 23:19:21 +01:00
router.push(tabRouteHref[newValue], tabRouteAs[newValue]).then(() => window.scrollTo(0, 0))
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}>
2022-10-26 22:06:10 +04:00
<AppBar style={{zIndex: 9999, boxShadow: 'none'}} position='fixed' color='default'>
2022-01-20 20:29:11 +04:00
<Tabs
2022-01-22 15:46:33 +04:00
allowScrollButtonsMobile
2022-02-19 22:09:15 +04:00
scrollButtons
2022-01-22 15:46:33 +04:00
centered={Boolean(!isMobile)}
2022-01-20 20:29:11 +04:00
value={selectedTab}
indicatorColor='primary'
textColor='primary'
aria-label='tabs menu'
2022-01-22 15:46:33 +04:00
variant={isMobile ? 'scrollable' : 'fullWidth'}
sx={{
[`& .${tabsClasses.scrollButtons}`]: {
'&.Mui-disabled': {opacity: 0.3},
},
}}
2022-01-20 20:29:11 +04:00
onChange={handleChange}
>
2022-01-22 13:41:29 +04:00
<Tab label='Accueil' {...a11yProps(0)} />
2022-03-13 01:38:45 +04:00
<Tab label='Paroles' {...a11yProps(1)} />
2022-01-22 13:41:29 +04:00
<Tab label='Artistes' {...a11yProps(2)} />
<Tab label='Soumettre' {...a11yProps(3)} />
2022-02-19 22:09:15 +04:00
<Tab label='Nous soutenir' {...a11yProps(4)} />
2022-01-20 20:29:11 +04:00
</Tabs>
</AppBar>
<TabPanel value={value} index={0} />
<TabPanel value={value} index={1} />
<TabPanel value={value} index={2} />
<TabPanel value={value} index={3} />
2022-02-19 22:09:15 +04:00
<TabPanel value={value} index={4} />
2022-01-20 20:29:11 +04:00
</div>
</Appdiv>
)
2020-12-11 01:36:54 +01:00
}
Navigasyon.propTypes = {
selectedTab: PropTypes.number.isRequired
}