From ee560e1984b83da9c9a60dbce3f99cba77ebaf9d Mon Sep 17 00:00:00 2001 From: J Francisco Rader Date: Sat, 22 Aug 2020 14:14:32 -0300 Subject: [PATCH] Context Menu!!! --- src/apps/settings/components/Settings.js | 15 +++++++- src/config/default.json | 7 +++- src/locale/en.json | 3 +- src/os/components/NavigationBar.js | 3 +- src/os/components/NotificationBar.js | 1 + src/ui/components/AppContent.js | 37 +++++++++++++++++-- src/ui/components/AppWrapper.js | 3 +- src/ui/components/ContextMenu.js | 47 ++++++++++++++++++++++++ src/ui/hooks/useContextMenu.js | 9 +++++ 9 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 src/ui/components/ContextMenu.js create mode 100644 src/ui/hooks/useContextMenu.js diff --git a/src/apps/settings/components/Settings.js b/src/apps/settings/components/Settings.js index 7edb2d5..bf4b6c0 100644 --- a/src/apps/settings/components/Settings.js +++ b/src/apps/settings/components/Settings.js @@ -1,10 +1,12 @@ import React from "react"; import { AppWrapper } from "../../../ui/components"; -import { makeStyles } from "@material-ui/core"; +import { makeStyles, List, ListItem } from "@material-ui/core"; import { AppTitle } from "../../../ui/components/AppTitle"; import { AppContent } from "../../../ui/components/AppContent"; import { useTranslation } from "react-i18next"; import { grey } from "@material-ui/core/colors"; +import { useContextMenu } from "../../../ui/hooks/useContextMenu"; +import { useConfig } from "../../../config/hooks/useConfig"; const useStyles = makeStyles(() => ({ root: { @@ -18,10 +20,19 @@ const useStyles = makeStyles(() => ({ export const SettingsApp = () => { const classes = useStyles(); const { t } = useTranslation(); + const [config] = useConfig(); + const [openMenu, closeMenu, ContextMenu, isMenuOpen] = useContextMenu(config.wallpapers.map(w => ({ label: w }))); return ( {t("APPS_SETTINGS")} - {t("COMING_SOON")} + + + + {t("APPS_SETTINGS_OPTIONS_WALLPAPER")} + + + + ); }; diff --git a/src/config/default.json b/src/config/default.json index 91875d2..aad8e36 100644 --- a/src/config/default.json +++ b/src/config/default.json @@ -1,4 +1,9 @@ { "4gNetowrk": "AT&T", - "language": "en_US" + "language": "en_US", + "wallpapers": [ + "default.png", + "dragon.jpg", + "legacy.jpg" + ] } \ No newline at end of file diff --git a/src/locale/en.json b/src/locale/en.json index 99bccb5..12c410e 100644 --- a/src/locale/en.json +++ b/src/locale/en.json @@ -4,6 +4,7 @@ "APPS_CONTACTS": "Contacts", "APPS_MESSAGES": "Messages", - "APPS_SETTINGS": "Settings" + "APPS_SETTINGS": "Settings", + "APPS_SETTINGS_OPTIONS_WALLPAPER": "Wallpaper" } } \ No newline at end of file diff --git a/src/os/components/NavigationBar.js b/src/os/components/NavigationBar.js index 4e473d3..8cc5ea1 100644 --- a/src/os/components/NavigationBar.js +++ b/src/os/components/NavigationBar.js @@ -12,8 +12,9 @@ import { useHistory } from "react-router-dom"; const useStyles = makeStyles(() => ({ root: { - backgroundColor: fade(grey[800], 0.7), + backgroundColor: grey[800], color: "white", + zIndex: 2 }, icon: { color: "white" diff --git a/src/os/components/NotificationBar.js b/src/os/components/NotificationBar.js index c81d3ea..ba782b4 100644 --- a/src/os/components/NotificationBar.js +++ b/src/os/components/NotificationBar.js @@ -10,6 +10,7 @@ const useStyles = makeStyles(() => ({ height: "25px", width: "100%", color: "white", + zIndex: 2 }, item: { margin: "0 6px", diff --git a/src/ui/components/AppContent.js b/src/ui/components/AppContent.js index c3d4e9f..d90a103 100644 --- a/src/ui/components/AppContent.js +++ b/src/ui/components/AppContent.js @@ -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 ( - - {children} + + + {children} ); }; diff --git a/src/ui/components/AppWrapper.js b/src/ui/components/AppWrapper.js index 8424ee3..70a2619 100644 --- a/src/ui/components/AppWrapper.js +++ b/src/ui/components/AppWrapper.js @@ -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 (
({ + root: { + width: "100%", + backgroundColor: theme.palette.background.default, + color: "black", + zIndex: 2 + }, +})); + +export const ContextMenu = ({ open, onClose, handleClickAway, options }) => { + const classes = useStyles(); + return ( + + +
+ + {options.map((option) => ( + { + option.onClick(e, option); + onClose(); + }} + > + {option.icon} + + + ))} + +
+
+
+ ); +}; diff --git a/src/ui/hooks/useContextMenu.js b/src/ui/hooks/useContextMenu.js new file mode 100644 index 0000000..456fd27 --- /dev/null +++ b/src/ui/hooks/useContextMenu.js @@ -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, () => , open] +}; \ No newline at end of file