Files
pawol.nu/components/navigasyon.js
T

124 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 06:35:04 +04:00
import {styled} from '@material-ui/core/styles'
2020-12-11 01:36:54 +01:00
import AppBar from '@material-ui/core/AppBar'
import Tabs from '@material-ui/core/Tabs'
import Tab from '@material-ui/core/Tab'
import HomeIcon from '@material-ui/icons/Home'
import MenuBookIcon from '@material-ui/icons/MenuBook'
2021-05-22 23:43:21 +02:00
import RecordVoiceOverIcon from '@material-ui/icons/RecordVoiceOver'
import PlaylistAddIcon from '@material-ui/icons/PlaylistAdd'
2020-12-11 01:36:54 +01:00
import Typography from '@material-ui/core/Typography'
import Box from '@material-ui/core/Box'
2022-01-19 06:35:04 +04:00
const PREFIX = 'navigasyon'
const classes = {
root: `${PREFIX}-root`
}
const Root = styled('div')((
{
theme
}
) => ({
[`& .${classes.root}`]: {
marginBottom: 50,
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-19 06:35:04 +04:00
<Root
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-19 06:35:04 +04:00
</Root>
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 (
<div className={classes.root}>
2021-06-14 23:25:48 +02:00
<AppBar style={{zIndex: 1}} position='fixed' color='default'>
2020-12-11 01:36:54 +01:00
<Tabs
value={selectedTab}
variant='fullWidth'
scrollButtons='on'
2020-12-12 03:28:51 +01:00
indicatorColor='primary'
textColor='primary'
2020-12-11 01:36:54 +01:00
aria-label='scrollable force tabs example'
onChange={handleChange}
>
<Tab label='Kay-la' icon={<HomeIcon style={{fontSize: 30}} />} {...a11yProps(0)} />
2021-09-29 18:59:31 +02:00
<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)} />
2020-12-11 01:36:54 +01:00
</Tabs>
</AppBar>
<TabPanel value={value} index={0} />
<TabPanel value={value} index={1} />
<TabPanel value={value} index={2} />
2021-05-22 23:43:21 +02:00
<TabPanel value={value} index={3} />
2020-12-11 01:36:54 +01:00
</div>
)
}
Navigasyon.propTypes = {
selectedTab: PropTypes.number.isRequired
}