Skip to content

Commit

Permalink
fix: navigation button spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
Tymek committed Aug 17, 2023
1 parent ac369d4 commit 8ec9080
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 37 deletions.
4 changes: 3 additions & 1 deletion frontend/src/component/admin/menu/AdminTabsMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useLocation } from 'react-router-dom';
import { useLocation, useNavigate } from 'react-router-dom';
import { Paper, styled, Tab, Tabs } from '@mui/material';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { CenteredNavLink } from './CenteredNavLink';
Expand All @@ -23,6 +23,7 @@ const StyledBadgeContainer = styled('div')(({ theme }) => ({
export const AdminTabsMenu: VFC = () => {
const { uiConfig, isPro, isOss } = useUiConfig();
const { pathname } = useLocation();
const navigate = useNavigate();

const activeTab = pathname.split('/')[2];

Expand Down Expand Up @@ -55,6 +56,7 @@ export const AdminTabsMenu: VFC = () => {
>
{tabs.map(tab => (
<Tab
sx={{ padding: 0 }}
key={tab.route}
value={tab.route?.split('/')?.[2]}
label={
Expand Down
50 changes: 15 additions & 35 deletions frontend/src/component/admin/menu/CenteredNavLink.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,21 @@
import { Theme } from '@mui/material';
import React, { FC } from 'react';
import { styled } from '@mui/material';
import { FC } from 'react';
import { NavLink } from 'react-router-dom';
import { useTheme } from '@mui/material/styles';

const createNavLinkStyle = (props: {
isActive: boolean;
theme: Theme;
}): React.CSSProperties => {
const navLinkStyle = {
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
width: '100%',
textDecoration: 'none',
color: 'inherit',
padding: props.theme.spacing(1.5, 3),
};

const activeNavLinkStyle: React.CSSProperties = {
const StyledNavLink = styled(NavLink)(({ theme }) => ({
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
width: '100%',
height: '100%',
textDecoration: 'none',
color: 'inherit',
padding: theme.spacing(0, 5),
'&.active': {
fontWeight: 'bold',
borderRadius: '3px',
padding: props.theme.spacing(1.5, 3),
};

return props.isActive
? { ...navLinkStyle, ...activeNavLinkStyle }
: navLinkStyle;
};
},
}));

export const CenteredNavLink: FC<{ to: string }> = ({ to, children }) => {
const theme = useTheme();
return (
<NavLink
to={to}
style={({ isActive }) => createNavLinkStyle({ isActive, theme })}
>
{children}
</NavLink>
);
return <StyledNavLink to={to}>{children}</StyledNavLink>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ export const NavigationMenu = ({
}
arrow
placement="left"
key={option.path}
>
<MenuItem
key={option.path}
component={StyledLink}
to={option.path}
onClick={handleClose}
Expand Down

0 comments on commit 8ec9080

Please sign in to comment.