💄 Passe la navigation de vue à React
This commit is contained in:
47
resources/js/components/user/BasicMenu.tsx
Normal file
47
resources/js/components/user/BasicMenu.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import * as React from 'react';
|
||||
import Button from '@mui/material/Button';
|
||||
import Menu from '@mui/material/Menu';
|
||||
import MenuItem from '@mui/material/MenuItem';
|
||||
|
||||
export default function BasicMenu({nickname}) {
|
||||
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
|
||||
const open = Boolean(anchorEl);
|
||||
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
||||
setAnchorEl(event.currentTarget);
|
||||
};
|
||||
const handleClose = () => {
|
||||
setAnchorEl(null);
|
||||
};
|
||||
|
||||
function logout() {
|
||||
const logoutForm: HTMLFormElement = document.getElementById("logout-form") as HTMLFormElement;
|
||||
logoutForm.submit();
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Button
|
||||
id="basic-button"
|
||||
aria-controls={open ? 'basic-menu' : undefined}
|
||||
aria-haspopup="true"
|
||||
aria-expanded={open ? 'true' : undefined}
|
||||
onClick={handleClick}
|
||||
className={"flex items-center text-sm font-medium text-gray-500 hover:text-gray-700 hover:border-gray-300 focus:outline-none focus:text-gray-700 focus:border-gray-300 transition duration-150 ease-in-out"}
|
||||
>
|
||||
{nickname}
|
||||
</Button>
|
||||
<Menu
|
||||
id="basic-menu"
|
||||
anchorEl={anchorEl}
|
||||
open={open}
|
||||
onClose={handleClose}
|
||||
MenuListProps={{
|
||||
'aria-labelledby': 'basic-button',
|
||||
}}
|
||||
>
|
||||
{/*<MenuItem onClick={handleClose}>My account</MenuItem>*/}
|
||||
<MenuItem onClick={logout}>Logout</MenuItem>
|
||||
</Menu>
|
||||
</div>
|
||||
);
|
||||
}
|
76
resources/js/components/user/MobileMenu.tsx
Normal file
76
resources/js/components/user/MobileMenu.tsx
Normal file
@@ -0,0 +1,76 @@
|
||||
import * as React from 'react';
|
||||
import Box from '@mui/material/Box';
|
||||
import SwipeableDrawer from '@mui/material/SwipeableDrawer';
|
||||
import Button from '@mui/material/Button';
|
||||
import List from '@mui/material/List';
|
||||
import Divider from '@mui/material/Divider';
|
||||
import ListItem from '@mui/material/ListItem';
|
||||
import ListItemIcon from '@mui/material/ListItemIcon';
|
||||
import ListItemText from '@mui/material/ListItemText';
|
||||
import InboxIcon from '@mui/icons-material/MoveToInbox';
|
||||
import MailIcon from '@mui/icons-material/Mail';
|
||||
|
||||
export default function MobileMenu({nickname}) {
|
||||
const [state, setState] = React.useState(false);
|
||||
|
||||
const toggleDrawer =
|
||||
(open: boolean) =>
|
||||
(event: React.KeyboardEvent | React.MouseEvent) => {
|
||||
if (
|
||||
event &&
|
||||
event.type === 'keydown' &&
|
||||
((event as React.KeyboardEvent).key === 'Tab' ||
|
||||
(event as React.KeyboardEvent).key === 'Shift')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState( open );
|
||||
};
|
||||
|
||||
function logout() {
|
||||
const logoutForm: HTMLFormElement = document.getElementById("logout-form") as HTMLFormElement;
|
||||
logoutForm.submit();
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Button onClick={toggleDrawer(true)}>
|
||||
<svg className="h-6 w-6" stroke="currentColor" fill="none" viewBox="0 0 24 24">
|
||||
<path className="inline-flex" strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M4 6h16M4 12h16M4 18h16" />
|
||||
</svg>
|
||||
</Button>
|
||||
<SwipeableDrawer
|
||||
anchor={"right"}
|
||||
open={state}
|
||||
onClose={toggleDrawer(false)}
|
||||
onOpen={toggleDrawer(true)}
|
||||
>
|
||||
<Box
|
||||
sx={{ width: 250 }}
|
||||
role="presentation"
|
||||
onClick={toggleDrawer(false)}
|
||||
onKeyDown={toggleDrawer(false)}
|
||||
>
|
||||
<List>
|
||||
<ListItem button key={"user"}>
|
||||
<ListItemIcon>
|
||||
<MailIcon />
|
||||
</ListItemIcon>
|
||||
<ListItemText primary={nickname} />
|
||||
</ListItem>
|
||||
</List>
|
||||
<Divider />
|
||||
<List>
|
||||
<ListItem button key={"user.logout"} onClick={logout}>
|
||||
<ListItemIcon>
|
||||
<InboxIcon />
|
||||
</ListItemIcon>
|
||||
<ListItemText primary={"Logout"} />
|
||||
</ListItem>
|
||||
</List>
|
||||
</Box>
|
||||
</SwipeableDrawer>
|
||||
</div>
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user