fancy icon based on if path selected
This commit is contained in:
@@ -14,10 +14,15 @@ import IconButton from '@mui/material/IconButton';
|
|||||||
import { useMediaQuery } from '@mui/material';
|
import { useMediaQuery } from '@mui/material';
|
||||||
import { useTheme } from '@mui/material/styles';
|
import { useTheme } from '@mui/material/styles';
|
||||||
import CollectionsBookmarkIcon from '@mui/icons-material/CollectionsBookmark';
|
import CollectionsBookmarkIcon from '@mui/icons-material/CollectionsBookmark';
|
||||||
|
import CollectionsOutlinedBookmarkIcon from '@mui/icons-material/CollectionsBookmarkOutlined';
|
||||||
import NewReleasesIcon from '@mui/icons-material/NewReleases';
|
import NewReleasesIcon from '@mui/icons-material/NewReleases';
|
||||||
|
import NewReleasesOutlinedIcon from '@mui/icons-material/NewReleasesOutlined';
|
||||||
import ExploreIcon from '@mui/icons-material/Explore';
|
import ExploreIcon from '@mui/icons-material/Explore';
|
||||||
|
import ExploreOutlinedIcon from '@mui/icons-material/ExploreOutlined';
|
||||||
import ExtensionIcon from '@mui/icons-material/Extension';
|
import ExtensionIcon from '@mui/icons-material/Extension';
|
||||||
|
import ExtensionOutlinedIcon from '@mui/icons-material/ExtensionOutlined';
|
||||||
import GetAppIcon from '@mui/icons-material/GetApp';
|
import GetAppIcon from '@mui/icons-material/GetApp';
|
||||||
|
import GetAppOutlinedIcon from '@mui/icons-material/GetAppOutlined';
|
||||||
import SettingsIcon from '@mui/icons-material/Settings';
|
import SettingsIcon from '@mui/icons-material/Settings';
|
||||||
import ArrowBack from '@mui/icons-material/ArrowBack';
|
import ArrowBack from '@mui/icons-material/ArrowBack';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
@@ -42,36 +47,43 @@ const navbarItems: Array<NavbarItem> = [
|
|||||||
{
|
{
|
||||||
path: '/library',
|
path: '/library',
|
||||||
title: 'Library',
|
title: 'Library',
|
||||||
IconComponent: CollectionsBookmarkIcon,
|
SelectedIconComponent: CollectionsBookmarkIcon,
|
||||||
|
IconComponent: CollectionsOutlinedBookmarkIcon,
|
||||||
show: 'both',
|
show: 'both',
|
||||||
}, {
|
}, {
|
||||||
path: '/updates',
|
path: '/updates',
|
||||||
title: 'Updates',
|
title: 'Updates',
|
||||||
IconComponent: NewReleasesIcon,
|
SelectedIconComponent: NewReleasesIcon,
|
||||||
|
IconComponent: NewReleasesOutlinedIcon,
|
||||||
show: 'both',
|
show: 'both',
|
||||||
}, {
|
}, {
|
||||||
path: '/sources',
|
path: '/sources',
|
||||||
title: 'Sources',
|
title: 'Sources',
|
||||||
IconComponent: ExploreIcon,
|
SelectedIconComponent: ExploreIcon,
|
||||||
|
IconComponent: ExploreOutlinedIcon,
|
||||||
show: 'desktop',
|
show: 'desktop',
|
||||||
}, {
|
}, {
|
||||||
path: '/extensions',
|
path: '/extensions',
|
||||||
title: 'Extensions',
|
title: 'Extensions',
|
||||||
IconComponent: ExtensionIcon,
|
SelectedIconComponent: ExtensionIcon,
|
||||||
|
IconComponent: ExtensionOutlinedIcon,
|
||||||
show: 'desktop',
|
show: 'desktop',
|
||||||
}, {
|
}, {
|
||||||
path: '/browse',
|
path: '/browse',
|
||||||
title: 'Browse',
|
title: 'Browse',
|
||||||
IconComponent: ExploreIcon,
|
SelectedIconComponent: ExploreIcon,
|
||||||
|
IconComponent: ExploreOutlinedIcon,
|
||||||
show: 'mobile',
|
show: 'mobile',
|
||||||
}, {
|
}, {
|
||||||
path: '/downloads',
|
path: '/downloads',
|
||||||
title: 'Downloads',
|
title: 'Downloads',
|
||||||
IconComponent: GetAppIcon,
|
SelectedIconComponent: GetAppIcon,
|
||||||
|
IconComponent: GetAppOutlinedIcon,
|
||||||
show: 'both',
|
show: 'both',
|
||||||
}, {
|
}, {
|
||||||
path: '/settings',
|
path: '/settings',
|
||||||
title: 'Settings',
|
title: 'Settings',
|
||||||
|
SelectedIconComponent: SettingsIcon,
|
||||||
IconComponent: SettingsIcon,
|
IconComponent: SettingsIcon,
|
||||||
show: 'both',
|
show: 'both',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -28,19 +28,25 @@ interface IProps {
|
|||||||
|
|
||||||
export default function DesktopSideBar({ navBarItems }: IProps) {
|
export default function DesktopSideBar({ navBarItems }: IProps) {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
|
const iconFor = (path: string, IconComponent: any, SelectedIconComponent: any) => {
|
||||||
|
if (location.pathname === path) return <SelectedIconComponent sx={{ color: 'primary.main' }} fontSize="large" />;
|
||||||
|
return <IconComponent sx={{ color: 'grey.A400' }} fontSize="large" />;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SideNavBarContainer>
|
<SideNavBarContainer>
|
||||||
{
|
{
|
||||||
// eslint-disable-next-line react/destructuring-assignment
|
// eslint-disable-next-line react/destructuring-assignment
|
||||||
navBarItems.map(({ path, title, IconComponent }: NavbarItem) => (
|
navBarItems.map(({
|
||||||
|
path, title, IconComponent, SelectedIconComponent,
|
||||||
|
}: NavbarItem) => (
|
||||||
<Link to={path} style={{ color: 'inherit', textDecoration: 'none' }} key={path}>
|
<Link to={path} style={{ color: 'inherit', textDecoration: 'none' }} key={path}>
|
||||||
<ListItem disableRipple button key={title}>
|
<ListItem disableRipple button key={title}>
|
||||||
<ListItemIcon style={{ minWidth: '0' }}>
|
<ListItemIcon style={{ minWidth: '0' }}>
|
||||||
|
|
||||||
<Tooltip placement="right" title={title}>
|
<Tooltip placement="right" title={title}>
|
||||||
<IconComponent sx={{ color: location.pathname === path ? 'primary.main' : 'grey.A400' }} fontSize="large" />
|
{iconFor(path, IconComponent, SelectedIconComponent)}
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|
||||||
</ListItemIcon>
|
</ListItemIcon>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@@ -39,10 +39,20 @@ interface IProps {
|
|||||||
|
|
||||||
export default function MobileBottomBar({ navBarItems }: IProps) {
|
export default function MobileBottomBar({ navBarItems }: IProps) {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
|
const iconFor = (path: string, IconComponent: any, SelectedIconComponent: any) => {
|
||||||
|
if (location.pathname === path) return <SelectedIconComponent sx={{ color: 'primary.main' }} fontSize="medium" />;
|
||||||
|
return <IconComponent sx={{ color: 'grey.A400' }} fontSize="medium" />;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BottomNavContainer>
|
<BottomNavContainer>
|
||||||
{
|
{
|
||||||
navBarItems.map(({ path, title, IconComponent }: NavbarItem) => (
|
navBarItems.map((
|
||||||
|
{
|
||||||
|
path, title, IconComponent, SelectedIconComponent,
|
||||||
|
}: NavbarItem,
|
||||||
|
) => (
|
||||||
<Link to={path} key={path}>
|
<Link to={path} key={path}>
|
||||||
<ListItem disableRipple button sx={{ justifyContent: 'center', padding: '8px' }} key={title}>
|
<ListItem disableRipple button sx={{ justifyContent: 'center', padding: '8px' }} key={title}>
|
||||||
<Box sx={{
|
<Box sx={{
|
||||||
@@ -55,7 +65,7 @@ export default function MobileBottomBar({ navBarItems }: IProps) {
|
|||||||
: 'grey.A400',
|
: 'grey.A400',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<IconComponent fontSize="medium" />
|
{iconFor(path, IconComponent, SelectedIconComponent)}
|
||||||
<div style={{ fontSize: '0.65rem' }}>{title}</div>
|
<div style={{ fontSize: '0.65rem' }}>{title}</div>
|
||||||
</Box>
|
</Box>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
|
|||||||
3
src/typings.d.ts
vendored
3
src/typings.d.ts
vendored
@@ -193,9 +193,10 @@ interface SourcePreferences {
|
|||||||
props: any
|
props: any
|
||||||
}
|
}
|
||||||
|
|
||||||
interface NavbarItem{
|
interface NavbarItem {
|
||||||
path: string,
|
path: string,
|
||||||
title:string,
|
title:string,
|
||||||
|
SelectedIconComponent: OverridableComponent<SvgIconTypeMap<{}, 'svg'>>,
|
||||||
IconComponent: OverridableComponent<SvgIconTypeMap<{}, 'svg'>>,
|
IconComponent: OverridableComponent<SvgIconTypeMap<{}, 'svg'>>,
|
||||||
show: 'mobile' | 'desktop' | 'both'
|
show: 'mobile' | 'desktop' | 'both'
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user