Files
pawol.nu/components/navigasyon.js
T

125 lines
3.1 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'
import Tabs from '@mui/material/Tabs'
import Tab from '@mui/material/Tab'
import HomeIcon from '@mui/icons-material/Home'
import MenuBookIcon from '@mui/icons-material/MenuBook'
import RecordVoiceOverIcon from '@mui/icons-material/RecordVoiceOver'
import PlaylistAddIcon from '@mui/icons-material/PlaylistAdd'
import Typography from '@mui/material/Typography'
import Box from '@mui/material/Box'
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 = [
'/',
2021-05-22 23:43:21 +02:00
'/teks',
2021-09-29 18:59:31 +02:00
'/awtis?paj&paj=1',
'/soumet'
2020-12-11 01:36:54 +01:00
]
const tabRouteAs = [
'/',
2021-05-22 23:43:21 +02:00
'/teks',
2021-09-29 18:59:31 +02:00
'/awtis/paj/1',
'/soumet'
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-19 06:35:04 +04:00
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}>
<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='Kay-la' icon={<HomeIcon style={{fontSize: 30}} />} {...a11yProps(0)} />
<Tab label='Tèks' icon={<MenuBookIcon style={{fontSize: 30}} />} {...a11yProps(1)} />
<Tab label='Awtis' icon={<RecordVoiceOverIcon style={{fontSize: 30}} />} {...a11yProps(2)} />
<Tab label='Soumèt' icon={<PlaylistAddIcon style={{fontSize: 30}} />} {...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>
)
2020-12-11 01:36:54 +01:00
}
Navigasyon.propTypes = {
selectedTab: PropTypes.number.isRequired
}