浏览代码

new form test 2

amenpunk 2 年之前
父节点
当前提交
b93579540a
共有 2 个文件被更改,包括 68 次插入110 次删除
  1. 20 110
      src/Components/Dashboard.js
  2. 48 0
      src/Components/Navigation/AppBar.js

+ 20 - 110
src/Components/Dashboard.js

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
 import { MainListItems, secondaryListItems } from './listItems';
4
 import { MainListItems, secondaryListItems } from './listItems';
5
 import { 
5
 import { 
6
     Menu,MenuItem,Container,Avatar, Badge,IconButton,Divider,
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
 } from '@mui/material'
8
 } from '@mui/material'
10
-
11
 import {
9
 import {
12
     Mail as MailIcon, Notifications as NotificationsIcon, Fullscreen as FullscreenIcon,
10
     Mail as MailIcon, Notifications as NotificationsIcon, Fullscreen as FullscreenIcon,
13
     Menu as MenuIcon,
11
     Menu as MenuIcon,
18
 
16
 
19
 import useAuth from '../Auth/useAuth';
17
 import useAuth from '../Auth/useAuth';
20
 import { Outlet, useNavigate} from "react-router-dom";
18
 import { Outlet, useNavigate} from "react-router-dom";
21
-// import { MenuMovil } from '../Components/MenuMovil';
22
 import { MenuMovil } from '../Components/Navigation/MenuMovil';
19
 import { MenuMovil } from '../Components/Navigation/MenuMovil';
23
 import Footer from "../Components/Footer";
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
 const mdTheme = createTheme();
23
 const mdTheme = createTheme();
93
 
24
 
94
 function DashboardContent() {
25
 function DashboardContent() {
95
 
26
 
96
     const [open, setOpen] = React.useState(false);
27
     const [open, setOpen] = React.useState(false);
97
-    const elRef = useRef();
98
-
28
+    const isMovil = Size('(min-width:770px)');
99
 
29
 
100
     const toggleDrawer = () => setOpen(!open);
30
     const toggleDrawer = () => setOpen(!open);
101
     const auth = useAuth();
31
     const auth = useAuth();
102
     const navigate = useNavigate()
32
     const navigate = useNavigate()
103
 
33
 
104
     const [anchorEl, setAnchorEl] = React.useState(null);
34
     const [anchorEl, setAnchorEl] = React.useState(null);
105
-
106
     const open_profile = Boolean(anchorEl);
35
     const open_profile = Boolean(anchorEl);
107
     const handleClick = (event) => setAnchorEl(event.currentTarget);
36
     const handleClick = (event) => setAnchorEl(event.currentTarget);
108
     const handleClose = () => setAnchorEl(null)
37
     const handleClose = () => setAnchorEl(null)
109
 
38
 
110
     const [anchorElMovil, setAnchorElMov] = React.useState(false);
39
     const [anchorElMovil, setAnchorElMov] = React.useState(false);
111
 
40
 
112
-    const handleCloseMov = () => {
113
-        setAnchorElMov(null);
114
-    };
115
-
116
     const MenuResponsive = ()  => {
41
     const MenuResponsive = ()  => {
117
-        if(!anchorElMovil){
118
-            // document.getElementsByTagName("MuiToolbar-root ").style.display = "none";
119
-        }
120
         setAnchorElMov(!anchorElMovil);
42
         setAnchorElMov(!anchorElMovil);
121
     } 
43
     } 
122
 
44
 
128
 
50
 
129
     return (
51
     return (
130
         <ThemeProvider theme={mdTheme}>
52
         <ThemeProvider theme={mdTheme}>
131
-
132
             <MenuMovil anchor={anchorElMovil}/>
53
             <MenuMovil anchor={anchorElMovil}/>
133
-
134
-
135
             <Box sx={{ display: 'flex' }}>
54
             <Box sx={{ display: 'flex' }}>
136
                 <CssBaseline/>
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
                     <Toolbar sx={{ pr: '24px' ,  borderBottom : "1px solid #ec5e69"}} >
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
                         <Typography component="h1" variant="h6" color="inherit" noWrap sx={{ flexGrow: 1 }} >
71
                         <Typography component="h1" variant="h6" color="inherit" noWrap sx={{ flexGrow: 1 }} >
162
                             {
72
                             {
163
-                            !useCheckMobileScreen() && open ? (
73
+                            !isMovil && open ? (
164
                                 <React.Fragment>
74
                                 <React.Fragment>
165
 
75
 
166
                                     <IconButton onClick={toggleDrawer}>
76
                                     <IconButton onClick={toggleDrawer}>

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

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
+);