Browse Source

new form test 2

amenpunk 2 years ago
parent
commit
b93579540a
2 changed files with 68 additions and 110 deletions
  1. 20 110
      src/Components/Dashboard.js
  2. 48 0
      src/Components/Navigation/AppBar.js

+ 20 - 110
src/Components/Dashboard.js

@@ -1,13 +1,11 @@
1
-import React, { useEffect, useState, useRef } from 'react';
2
-import { styled, createTheme, ThemeProvider } from '@mui/material/styles';
1
+import React from 'react';
2
+import {createTheme, ThemeProvider } from '@mui/material/styles';
3 3
 
4 4
 import { MainListItems, secondaryListItems } from './listItems';
5 5
 import { 
6 6
     Menu,MenuItem,Container,Avatar, Badge,IconButton,Divider,
7
-    Typography, List, Toolbar, AppBar as MuiAppBar, Box, Drawer as MuiDrawer,
8
-    CssBaseline, 
7
+    Typography, List, Toolbar, Box, CssBaseline,useMediaQuery as Size
9 8
 } from '@mui/material'
10
-
11 9
 import {
12 10
     Mail as MailIcon, Notifications as NotificationsIcon, Fullscreen as FullscreenIcon,
13 11
     Menu as MenuIcon,
@@ -18,105 +16,29 @@ import ProfilePicture from '../Images/man.png';
18 16
 
19 17
 import useAuth from '../Auth/useAuth';
20 18
 import { Outlet, useNavigate} from "react-router-dom";
21
-// import { MenuMovil } from '../Components/MenuMovil';
22 19
 import { MenuMovil } from '../Components/Navigation/MenuMovil';
23 20
 import Footer from "../Components/Footer";
24
-
25
-
26
-const drawerWidth = 240;
27
-
28
-const AppBar = styled(MuiAppBar, {
29
-    shouldForwardProp: (prop) => prop !== 'open',
30
-})(({ theme, open }) => ({
31
-    zIndex: theme.zIndex.drawer + 1,
32
-    transition: theme.transitions.create(['width', 'margin'], {
33
-        easing: theme.transitions.easing.sharp,
34
-        duration: theme.transitions.duration.leavingScreen,
35
-    }),
36
-    ...(open && {
37
-        marginLeft: drawerWidth,
38
-        width: `calc(100% - ${drawerWidth}px)`,
39
-        transition: theme.transitions.create(['width', 'margin'], {
40
-            easing: theme.transitions.easing.sharp,
41
-            duration: theme.transitions.duration.enteringScreen,
42
-        }),
43
-    }),
44
-}));
45
-
46
-const useCheckMobileScreen = () => {
47
-    const [width, setWidth] = useState(window.innerWidth);
48
-    const handleWindowSizeChange = () => {
49
-        let size = window.innerWidth;
50
-        setWidth(size);
51
-    }
52
-
53
-    useEffect(() => {
54
-        window.addEventListener('resize', handleWindowSizeChange);
55
-        return () => {
56
-            window.removeEventListener('resize', handleWindowSizeChange);
57
-            document.getElementById("mySidebar").style.display = "block";
58
-        }
59
-    }, []);
60
-
61
-    let isMobile = width <= 1000
62
-
63
-    return (isMobile);
64
-}
65
-
66
-const Drawer = styled(MuiDrawer, { shouldForwardProp: (prop) => prop !== 'open' })(
67
-    ({ theme, open }) => ({
68
-        '& .MuiDrawer-paper': {
69
-            position: 'relative',
70
-            whiteSpace: 'nowrap',
71
-            width: drawerWidth,
72
-            transition: theme.transitions.create('width', {
73
-                easing: theme.transitions.easing.sharp,
74
-                duration: theme.transitions.duration.enteringScreen,
75
-            }),
76
-            boxSizing: 'border-box',
77
-            ...(!open && {
78
-                overflowX: 'hidden',
79
-                transition: theme.transitions.create('width', {
80
-                    easing: theme.transitions.easing.sharp,
81
-                    duration: theme.transitions.duration.leavingScreen,
82
-                }),
83
-                width: theme.spacing(7),
84
-                [theme.breakpoints.up('sm')]: {
85
-                    width: theme.spacing(9),
86
-                },
87
-            }),
88
-        },
89
-    }),
90
-);
21
+import { Drawer, AppBar } from "../Components/Navigation/AppBar"
91 22
 
92 23
 const mdTheme = createTheme();
93 24
 
94 25
 function DashboardContent() {
95 26
 
96 27
     const [open, setOpen] = React.useState(false);
97
-    const elRef = useRef();
98
-
28
+    const isMovil = Size('(min-width:770px)');
99 29
 
100 30
     const toggleDrawer = () => setOpen(!open);
101 31
     const auth = useAuth();
102 32
     const navigate = useNavigate()
103 33
 
104 34
     const [anchorEl, setAnchorEl] = React.useState(null);
105
-
106 35
     const open_profile = Boolean(anchorEl);
107 36
     const handleClick = (event) => setAnchorEl(event.currentTarget);
108 37
     const handleClose = () => setAnchorEl(null)
109 38
 
110 39
     const [anchorElMovil, setAnchorElMov] = React.useState(false);
111 40
 
112
-    const handleCloseMov = () => {
113
-        setAnchorElMov(null);
114
-    };
115
-
116 41
     const MenuResponsive = ()  => {
117
-        if(!anchorElMovil){
118
-            // document.getElementsByTagName("MuiToolbar-root ").style.display = "none";
119
-        }
120 42
         setAnchorElMov(!anchorElMovil);
121 43
     } 
122 44
 
@@ -128,39 +50,27 @@ function DashboardContent() {
128 50
 
129 51
     return (
130 52
         <ThemeProvider theme={mdTheme}>
131
-
132 53
             <MenuMovil anchor={anchorElMovil}/>
133
-
134
-
135 54
             <Box sx={{ display: 'flex' }}>
136 55
                 <CssBaseline/>
137
-                <AppBar style={{ backgroundColor : '#fff', boxShadow : 'None' }} position="absolute" open={useCheckMobileScreen() ? false : open}>
138
-
56
+                <AppBar style={{ backgroundColor : '#fff', boxShadow : 'None' }} position="absolute" open={ !isMovil ? open : false}>
139 57
                     <Toolbar sx={{ pr: '24px' ,  borderBottom : "1px solid #ec5e69"}} >
140
-
141
-                        <div ref={elRef}>
142
-
143
-                            <IconButton 
144
-                                edge="start" 
145
-                                color="inherit" 
146
-                                aria-label="open drawer" 
147
-                                onClick={ useCheckMobileScreen() ? MenuResponsive : toggleDrawer } 
148
-                                sx={{ marginRight: '36px', ...( !useCheckMobileScreen() && open && { display: 'none' }), }} >
149
-                                <MenuIcon  style={{
150
-                                    background: '#ec5e69',
151
-                                    fontSize: "40",
152
-                                    color: "#fff"
153
-                                }}/>
154
-                            </IconButton>
155
-
156
-
157
-
158
-
159
-                        </div>
160
-
58
+                        {/* boton para activar navegacion */}
59
+                        <IconButton 
60
+                            edge="start" 
61
+                            color="inherit" 
62
+                            aria-label="open drawer" 
63
+                            onClick={ !isMovil ? MenuResponsive : toggleDrawer } 
64
+                            sx={{ marginRight: '36px', ...( !isMovil && open && { display: 'none' }), }} >
65
+                            <MenuIcon  style={{
66
+                                background: '#ec5e69',
67
+                                fontSize: "40",
68
+                                color: "#fff"
69
+                            }}/>
70
+                        </IconButton>
161 71
                         <Typography component="h1" variant="h6" color="inherit" noWrap sx={{ flexGrow: 1 }} >
162 72
                             {
163
-                            !useCheckMobileScreen() && open ? (
73
+                            !isMovil && open ? (
164 74
                                 <React.Fragment>
165 75
 
166 76
                                     <IconButton onClick={toggleDrawer}>

+ 48 - 0
src/Components/Navigation/AppBar.js

@@ -0,0 +1,48 @@
1
+
2
+import { styled } from '@mui/material/styles';
3
+import { AppBar as MuiAppBar, Drawer  as MuiDrawer } from '@mui/material'
4
+
5
+const drawerWidth = 240;
6
+
7
+export const AppBar = styled(MuiAppBar, {
8
+    shouldForwardProp: (prop) => prop !== 'open', })(({ theme, open }) => ({
9
+    zIndex: theme.zIndex.drawer + 1,
10
+    transition: theme.transitions.create(['width', 'margin'], {
11
+        easing: theme.transitions.easing.sharp,
12
+        duration: theme.transitions.duration.leavingScreen,
13
+    }),
14
+    ...(open && {
15
+        marginLeft: drawerWidth,
16
+        width: `calc(100% - ${drawerWidth}px)`,
17
+        transition: theme.transitions.create(['width', 'margin'], {
18
+            easing: theme.transitions.easing.sharp,
19
+            duration: theme.transitions.duration.enteringScreen,
20
+        }),
21
+    }),
22
+}));
23
+
24
+export const Drawer = styled(MuiDrawer, { shouldForwardProp: (prop) => prop !== 'open' })(
25
+    ({ theme, open }) => ({
26
+        '& .MuiDrawer-paper': {
27
+            position: 'relative',
28
+            whiteSpace: 'nowrap',
29
+            width: drawerWidth,
30
+            transition: theme.transitions.create('width', {
31
+                easing: theme.transitions.easing.sharp,
32
+                duration: theme.transitions.duration.enteringScreen,
33
+            }),
34
+            boxSizing: 'border-box',
35
+            ...(!open && {
36
+                overflowX: 'hidden',
37
+                transition: theme.transitions.create('width', {
38
+                    easing: theme.transitions.easing.sharp,
39
+                    duration: theme.transitions.duration.leavingScreen,
40
+                }),
41
+                width: theme.spacing(7),
42
+                [theme.breakpoints.up('sm')]: {
43
+                    width: theme.spacing(9),
44
+                },
45
+            }),
46
+        },
47
+    }),
48
+);