Files
pawol.nu/components/navigasyon.js
T
2022-01-22 13:41:29 +04:00

121 lines
2.7 KiB
JavaScript

import {useState} from 'react'
import PropTypes from 'prop-types'
import {useRouter} from 'next/router'
import {styled} from '@mui/material/styles'
import AppBar from '@mui/material/AppBar'
import Tabs from '@mui/material/Tabs'
import Tab from '@mui/material/Tab'
import Typography from '@mui/material/Typography'
import Box from '@mui/material/Box'
const PREFIX = 'navigasyon'
const classes = {
root: `${PREFIX}-root`
}
const Appdiv = styled('div')((
{
theme
}
) => ({
[`& .${classes.root}`]: {
flexGrow: 1,
width: '100%',
backgroundColor: theme.palette.background.paper
}
}))
const tabRouteHref = [
'/',
'/teks',
'/awtis?paj&paj=1',
'/soumet'
]
const tabRouteAs = [
'/',
'/teks',
'/awtis/paj/1',
'/soumet'
]
function TabPanel(props) {
const {children, value, index, ...other} = props
return (
<div
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>
)}
</div>
)
}
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()
const [value, setValue] = useState(0)
const handleChange = (event, newValue) => {
setValue(newValue)
if (newValue !== selectedTab) {
router.push(tabRouteHref[newValue], tabRouteAs[newValue]).then(() => window.scrollTo(0, 0))
}
}
return (
<Appdiv>
<div className={classes.root}>
<AppBar style={{zIndex: 1}} position='fixed' color='default'>
<Tabs
centered
value={selectedTab}
variant='fullWidth'
indicatorColor='primary'
textColor='primary'
aria-label='tabs menu'
onChange={handleChange}
>
<Tab label='Accueil' {...a11yProps(0)} />
<Tab label='Textes' {...a11yProps(1)} />
<Tab label='Artistes' {...a11yProps(2)} />
<Tab label='Soumettre' {...a11yProps(3)} />
</Tabs>
</AppBar>
<TabPanel value={value} index={0} />
<TabPanel value={value} index={1} />
<TabPanel value={value} index={2} />
<TabPanel value={value} index={3} />
</div>
</Appdiv>
)
}
Navigasyon.propTypes = {
selectedTab: PropTypes.number.isRequired
}