Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sidebar #29

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = {
'import/prefer-default-export': 'warn',
"import/prefer-default-export": "off",
"import/order": 'warn',
"import/extensions": 'warn'
"import/extensions": 'warn',
'@typescript-eslint/no-exp': 'off',
},
};
56 changes: 46 additions & 10 deletions src/components/layouts/SidebarApp.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import { Drawer, List, ListItem, ListItemText } from '@mui/material';
import { DRAWER_WIDTH } from '../../libs/constants';
import {
Drawer,
List,
ListItemButton,
ListItemIcon,
ListItemText,
Box,
Toolbar,
Divider,
Typography,
} from '@mui/material';
import { useLocation, useNavigate } from 'react-router-dom';
import { DRAWER_WIDTH, SIDEBAR_MENU } from '../../libs/constants';

function SidebarApp() {
const navigate = useNavigate();
const { pathname } = useLocation();

return (
<div>
<Box display="flex">
<Drawer
variant="permanent"
sx={{
Expand All @@ -15,16 +29,38 @@ function SidebarApp() {
},
}}
>
<Toolbar>
<Box
sx={{
width: '100%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
>
<Typography variant="h6" fontWeight="bold">
LOGO
</Typography>
</Box>
</Toolbar>
<Divider />
<List>
<ListItem button>
<ListItemText primary="Item 1" />
</ListItem>
<ListItem button>
<ListItemText primary="Item 2" />
</ListItem>
{SIDEBAR_MENU.map((item) => (
<ListItemButton
key={item.title}
sx={{ display: 'flex', justifyContent: 'center', gap: 1 }}
selected={item.path === pathname}
onClick={() => navigate(item.path)}
>
<ListItemIcon sx={{ minWidth: 'auto' }}>
<item.icon />
</ListItemIcon>
<ListItemText>{item.title}</ListItemText>
</ListItemButton>
))}
</List>
</Drawer>
</div>
</Box>
);
}

Expand Down
11 changes: 11 additions & 0 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { SvgIconTypeMap } from '@mui/material';
import { OverridableComponent } from '@mui/material/OverridableComponent';

export interface MenuItem {
title: string;
path: string;
icon: OverridableComponent<SvgIconTypeMap<NonNullable<unknown>, 'svg'>> & {
muiName: string;
};
children?: MenuItem[];
}
25 changes: 24 additions & 1 deletion src/libs/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
export const DRAWER_WIDTH = 280;
import SpaceDashboardIcon from '@mui/icons-material/SpaceDashboard';
import FingerprintIcon from '@mui/icons-material/Fingerprint';
import BlockIcon from '@mui/icons-material/Block';
import { MenuItem } from '../interfaces';

export const DRAWER_WIDTH = 240;

export const SIDEBAR_MENU: MenuItem[] = [
{
title: 'Dashboard',
path: '/',
icon: SpaceDashboardIcon,
},
{
title: 'Identifiers',
path: '/idenifiers',
icon: FingerprintIcon,
},
{
title: 'Permissions',
path: '/permissions',
icon: BlockIcon,
},
];
3 changes: 3 additions & 0 deletions src/pages/Identifiers/Identifiers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function Identifiers() {
return <div>Identifiers</div>;
}
3 changes: 3 additions & 0 deletions src/pages/Identifiers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Identifiers } from './Identifiers';

export default Identifiers;
3 changes: 3 additions & 0 deletions src/pages/Permissions/Permissions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function Permissions() {
return <div>Permissions</div>;
}
3 changes: 3 additions & 0 deletions src/pages/Permissions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Permissions } from './Permissions';

export default Permissions;
12 changes: 12 additions & 0 deletions src/router/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { createBrowserRouter } from 'react-router-dom';

import Dashboard from '../pages/Dashboard';
import Identifiers from '../pages/Identifiers';
import Permissions from '../pages/Permissions';

import DefaultLayout from '../layouts/DefaultLayout';

export const router = createBrowserRouter([
Expand All @@ -12,6 +16,14 @@ export const router = createBrowserRouter([
element: <Dashboard />,
index: true,
},
{
path: '/idenifiers',
element: <Identifiers />,
},
{
path: '/permissions',
element: <Permissions />,
mehdi-torabiv marked this conversation as resolved.
Show resolved Hide resolved
},
],
},
{
Expand Down
Loading