Context Menu!!!

This commit is contained in:
J Francisco Rader committed 2020-08-22 14:17:43 -03:00
1 parent b40d00a260
commit ee560e1984
9 files changed
+115 -10

No files matched your search

+33 -4
View File
@@ -1,10 +1,39 @@
import React from "react";
import { Box } from "@material-ui/core";
import { Box, makeStyles, Backdrop } from "@material-ui/core";
export const AppContent = ({ children, style, ...props }) => {
const useStyles = makeStyles((theme) => ({
box: {
width: "100%",
position: "relative",
},
backdrop: {
position: "absolute",
zIndex: 1,
},
}));
export const AppContent = ({
children,
style,
backdrop,
onClickBackdrop,
...props
}) => {
const classes = useStyles();
return (
<Box px={2} pt={1} style={{ width: '100%', ...props }} {...props}>
{children}
<Box
px={2}
pt={1}
flexGrow={1}
style={{ width: "100%", ...props }}
{...props}
>
<Backdrop
className={classes.backdrop}
open={backdrop}
onClick={onClickBackdrop}
></Backdrop>
{children}
</Box>
);
};
+2 -1
View File
@@ -1,6 +1,7 @@
import React from "react";
import { ClickAwayListener } from "@material-ui/core";
export const AppWrapper = ({ children, style, ...props }) => {
export const AppWrapper = ({ children, style, handleClickAway, ...props }) => {
return (
<div
{...props}
+47
View File
@@ -0,0 +1,47 @@
import React from "react";
import {
Drawer,
ListItem,
List,
ListItemIcon,
ListItemText,
Slide,
makeStyles,
ClickAwayListener,
} from "@material-ui/core";
const useStyles = makeStyles((theme) => ({
root: {
width: "100%",
backgroundColor: theme.palette.background.default,
color: "black",
zIndex: 2
},
}));
export const ContextMenu = ({ open, onClose, handleClickAway, options }) => {
const classes = useStyles();
return (
<ClickAwayListener onClickAway={handleClickAway}>
<Slide direction="up" in={open} mountOnEnter unmountOnExit>
<div className={classes.root}>
<List component="nav" aria-label="context menu">
{options.map((option) => (
<ListItem
button
key={option.key}
onClick={(e) => {
option.onClick(e, option);
onClose();
}}
>
<ListItemIcon>{option.icon}</ListItemIcon>
<ListItemText primary={option.label} />
</ListItem>
))}
</List>
</div>
</Slide>
</ClickAwayListener>
);
};
+9
View File
@@ -0,0 +1,9 @@
import React, { useState } from "react";
import { ContextMenu } from "../components/ContextMenu";
export const useContextMenu = (options = []) => {
const [open, setOpen] = useState();
const onClose = () => setOpen(false);
const onOpen = () => setOpen(true);
return [onOpen, onClose, () => <ContextMenu open={open} onClose={onClose} options={options} />, open]
};