2021-10-29 17:51:43 +05:30
|
|
|
/*
|
|
|
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
|
|
import React from 'react';
|
2021-11-08 04:30:31 +05:30
|
|
|
import { ListItem } from '@mui/material';
|
|
|
|
|
import { styled, Box } from '@mui/system';
|
2021-10-30 16:56:33 +03:30
|
|
|
import { Link as RRDLink, useLocation } from 'react-router-dom';
|
2021-11-08 04:30:31 +05:30
|
|
|
import { useTheme } from '@mui/material/styles';
|
2021-10-29 17:51:43 +05:30
|
|
|
|
|
|
|
|
const BottomNavContainer = styled('div')(({ theme }) => ({
|
|
|
|
|
bottom: 0,
|
|
|
|
|
left: 0,
|
|
|
|
|
height: theme.spacing(7),
|
|
|
|
|
width: '100vw',
|
2022-11-26 13:51:56 +01:00
|
|
|
backgroundColor: theme.palette.custom.light,
|
2021-10-29 17:51:43 +05:30
|
|
|
position: 'fixed',
|
|
|
|
|
display: 'flex',
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'space-evenly',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
// For Some reason the theme is throwing and error when accessing the Zindex object,
|
|
|
|
|
// This is the zIndex of the appBar in the default theme
|
|
|
|
|
zIndex: 1100,
|
|
|
|
|
}));
|
|
|
|
|
|
2021-10-30 16:56:33 +03:30
|
|
|
const Link = styled(RRDLink)({
|
|
|
|
|
textDecoration: 'none',
|
|
|
|
|
flex: 1,
|
|
|
|
|
});
|
|
|
|
|
|
2021-10-29 17:51:43 +05:30
|
|
|
interface IProps {
|
|
|
|
|
navBarItems: Array<NavbarItem>
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-30 16:10:34 +03:30
|
|
|
export default function MobileBottomBar({ navBarItems }: IProps) {
|
2021-10-29 17:51:43 +05:30
|
|
|
const location = useLocation();
|
2021-11-08 04:30:31 +05:30
|
|
|
const theme = useTheme();
|
2021-10-30 17:29:27 +03:30
|
|
|
|
|
|
|
|
const iconFor = (path: string, IconComponent: any, SelectedIconComponent: any) => {
|
|
|
|
|
if (location.pathname === path) return <SelectedIconComponent sx={{ color: 'primary.main' }} fontSize="medium" />;
|
2021-11-08 04:30:31 +05:30
|
|
|
return <IconComponent sx={{ color: (theme.palette.mode === 'dark') ? 'grey.A400' : 'grey.600' }} fontSize="medium" />;
|
2021-10-30 17:29:27 +03:30
|
|
|
};
|
|
|
|
|
|
2021-10-29 17:51:43 +05:30
|
|
|
return (
|
|
|
|
|
<BottomNavContainer>
|
|
|
|
|
{
|
2021-10-30 17:29:27 +03:30
|
|
|
navBarItems.map((
|
|
|
|
|
{
|
|
|
|
|
path, title, IconComponent, SelectedIconComponent,
|
|
|
|
|
}: NavbarItem,
|
|
|
|
|
) => (
|
2021-10-30 16:56:33 +03:30
|
|
|
<Link to={path} key={path}>
|
|
|
|
|
<ListItem disableRipple button sx={{ justifyContent: 'center', padding: '8px' }} key={title}>
|
2021-11-08 04:30:31 +05:30
|
|
|
<Box
|
|
|
|
|
display="flex"
|
|
|
|
|
flexDirection="column"
|
|
|
|
|
alignItems="center"
|
2021-10-29 17:51:43 +05:30
|
|
|
>
|
2021-10-30 17:29:27 +03:30
|
|
|
{iconFor(path, IconComponent, SelectedIconComponent)}
|
2021-11-08 04:30:31 +05:30
|
|
|
<Box sx={{
|
|
|
|
|
fontSize: '0.65rem',
|
|
|
|
|
// eslint-disable-next-line no-nested-ternary
|
|
|
|
|
color: location.pathname === path
|
|
|
|
|
? 'primary.main'
|
|
|
|
|
: ((theme.palette.mode === 'dark')
|
|
|
|
|
? 'grey.A400'
|
|
|
|
|
: 'grey.600'),
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{title}
|
|
|
|
|
</Box>
|
2021-10-29 17:51:43 +05:30
|
|
|
</Box>
|
|
|
|
|
</ListItem>
|
|
|
|
|
</Link>
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
</BottomNavContainer>
|
|
|
|
|
);
|
|
|
|
|
}
|