sidebar
This commit is contained in:
1 parent
d1d96bd2ba
commit
1db5f4b70f
3 files changed
+24
-10
No files matched your search
@@ -1,8 +1,9 @@
|
|||||||
import { Sidebar } from "@/Components/v2/sidebar";
|
import { Sidebar } from "@/Components/v2/sidebar";
|
||||||
import { Outlet } from "react-router";
|
import { Outlet } from "react-router";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
|
import { useMediaQuery } from "@mui/material";
|
||||||
|
import { useSidebar } from "@/Hooks/useSidebar";
|
||||||
|
|
||||||
// TEMP
|
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import type { RootState } from "@/Types/state";
|
import type { RootState } from "@/Types/state";
|
||||||
import { lightTheme, darkTheme } from "@/Utils/Theme/v2Theme";
|
import { lightTheme, darkTheme } from "@/Utils/Theme/v2Theme";
|
||||||
@@ -12,6 +13,9 @@ const RootLayout = () => {
|
|||||||
const mode = useSelector((state: RootState) => state.ui.mode);
|
const mode = useSelector((state: RootState) => state.ui.mode);
|
||||||
const v2theme = mode === "dark" ? darkTheme : lightTheme;
|
const v2theme = mode === "dark" ? darkTheme : lightTheme;
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
||||||
|
const { collapsedWidth } = useSidebar();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack flexDirection="row">
|
<Stack flexDirection="row">
|
||||||
<ThemeProvider theme={v2theme}>
|
<ThemeProvider theme={v2theme}>
|
||||||
@@ -28,6 +32,7 @@ const RootLayout = () => {
|
|||||||
: "rgba(0, 0, 0, 0.01)",
|
: "rgba(0, 0, 0, 0.01)",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
|
paddingLeft: isSmall ? `${collapsedWidth + 12}px` : 12,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Stack
|
<Stack
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import Stack from "@mui/material/Stack";
|
import Stack, { type StackProps } from "@mui/material/Stack";
|
||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
@@ -7,14 +7,13 @@ import { useDispatch } from "react-redux";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import useSidebar from "@/Hooks/useSidebar";
|
import useSidebar from "@/Hooks/useSidebar";
|
||||||
|
|
||||||
export const Logo = () => {
|
export const Logo = (props: StackProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { collapsed } = useSidebar();
|
const { collapsed } = useSidebar();
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
pb={theme.spacing(6)}
|
|
||||||
direction="row"
|
direction="row"
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
gap={theme.spacing(4)}
|
gap={theme.spacing(4)}
|
||||||
@@ -22,9 +21,10 @@ export const Logo = () => {
|
|||||||
dispatch(toggleSidebar());
|
dispatch(toggleSidebar());
|
||||||
}}
|
}}
|
||||||
sx={{ cursor: "pointer" }}
|
sx={{ cursor: "pointer" }}
|
||||||
|
{...props}
|
||||||
>
|
>
|
||||||
<Typography
|
<Typography
|
||||||
minWidth={39}
|
minWidth={theme.spacing(16)}
|
||||||
minHeight={theme.spacing(16)}
|
minHeight={theme.spacing(16)}
|
||||||
display={"flex"}
|
display={"flex"}
|
||||||
justifyContent={"center"}
|
justifyContent={"center"}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { useEffect } from "react";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import List from "@mui/material/List";
|
import List from "@mui/material/List";
|
||||||
import { useSidebar } from "@/Hooks/useSidebar.js";
|
import { useSidebar } from "@/Hooks/useSidebar.js";
|
||||||
@@ -5,25 +6,30 @@ import { Logo } from "@/Components/v2/sidebar/Logo";
|
|||||||
import { getMenu } from "@/Components/v2/sidebar/Menu";
|
import { getMenu } from "@/Components/v2/sidebar/Menu";
|
||||||
import { NavItem } from "@/Components/v2/sidebar/NavItem";
|
import { NavItem } from "@/Components/v2/sidebar/NavItem";
|
||||||
|
|
||||||
import { useNavigate } from "react-router";
|
import { useNavigate, useLocation } from "react-router";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useTheme, useMediaQuery } from "@mui/material";
|
import { useTheme, useMediaQuery } from "@mui/material";
|
||||||
import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
import { toggleSidebar } from "@/Features/UI/uiSlice";
|
import { setCollapsed } from "@/Features/UI/uiSlice";
|
||||||
|
|
||||||
export const Sidebar = () => {
|
export const Sidebar = () => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const location = useLocation();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { width, transition } = useSidebar();
|
const { width, transition } = useSidebar();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
||||||
const menu = getMenu(t);
|
const menu = getMenu(t);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
dispatch(setCollapsed({ collapsed: isSmall }));
|
||||||
|
}, [isSmall, dispatch]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
component="aside"
|
component="aside"
|
||||||
position={{ xs: "fixed", md: "sticky" }}
|
position={isSmall ? "fixed" : "sticky"}
|
||||||
top={0}
|
top={0}
|
||||||
left={0}
|
left={0}
|
||||||
minHeight={"100vh"}
|
minHeight={"100vh"}
|
||||||
@@ -46,7 +52,10 @@ export const Sidebar = () => {
|
|||||||
height: "100%",
|
height: "100%",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Logo />
|
<Logo
|
||||||
|
pt={theme.spacing(8)}
|
||||||
|
pb={theme.spacing(10)}
|
||||||
|
/>
|
||||||
{menu.map((item) => {
|
{menu.map((item) => {
|
||||||
const selected = location.pathname.startsWith(`/${item.path}`);
|
const selected = location.pathname.startsWith(`/${item.path}`);
|
||||||
return (
|
return (
|
||||||
@@ -57,7 +66,7 @@ export const Sidebar = () => {
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
navigate(`/${item.path}`);
|
navigate(`/${item.path}`);
|
||||||
if (isSmall) {
|
if (isSmall) {
|
||||||
dispatch(toggleSidebar());
|
dispatch(setCollapsed({ collapsed: true }));
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in new issue
Block a user