From aac17fd4af7b5ca9dfe9e2c63e8ca15099322f63 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 20 Jan 2023 12:26:50 +0100 Subject: [PATCH] refactor(web/menu): move planet menu styling --- web/src/features/menu/planet/index.tsx | 130 ++++++++++++++----------- 1 file changed, 71 insertions(+), 59 deletions(-) diff --git a/web/src/features/menu/planet/index.tsx b/web/src/features/menu/planet/index.tsx index ef3fc09..b6bd0df 100644 --- a/web/src/features/menu/planet/index.tsx +++ b/web/src/features/menu/planet/index.tsx @@ -1,4 +1,4 @@ -import { ActionIcon, Box, Stack, Text, Transition } from '@mantine/core'; +import { ActionIcon, Box, createStyles, Stack, Text, Transition } from '@mantine/core'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { IconProp } from '@fortawesome/fontawesome-svg-core'; import { useState } from 'react'; @@ -31,13 +31,75 @@ debugData<{ items: MenuItem[]; sub?: boolean }>([ { icon: 'palette', label: 'Paint' }, { icon: 'warehouse', label: 'Garage' }, { icon: 'handcuffs', label: 'Arrest' }, + { icon: 'handcuffs', label: 'Arrest' }, ], sub: false, }, }, ]); +const useStyles = createStyles((theme) => ({ + wrapper: { + position: 'absolute', + top: '50%', + left: '50%', + transform: 'translate(-50%, -50%)', + }, + centerButton: { + width: 50, + height: 50, + zIndex: 99, + }, + buttonsContainer: { + position: 'absolute', + top: '50%', + left: '50%', + transform: 'translate(-50%, -50%)', + width: 120, + height: 120, + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + }, + button: { + position: 'absolute', + width: 40, + height: 40, + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + borderRadius: '50%', + backgroundColor: theme.colors.dark[6], + color: theme.colors.dark[0], + boxShadow: theme.shadows.sm, + padding: 12, + '&:hover': { + backgroundColor: theme.colors.dark[5], + cursor: 'pointer', + }, + }, + labelWrapper: { + marginTop: 120, + position: 'absolute', + width: '100%', + top: '50%', + left: '50%', + transform: 'translate(-50%, -50%)', + }, + labelContainer: { + backgroundColor: theme.colors.dark[6], + color: theme.colors.dark[2], + padding: 8, + borderRadius: theme.radius.sm, + fontWeight: 500, + fontSize: 14, + boxShadow: theme.shadows.sm, + textAlign: 'center', + }, +})); + const PlanetMenu: React.FC = () => { + const { classes } = useStyles(); const [visible, setVisible] = useState(false); const [menu, setMenu] = useState<{ items: MenuItem[]; sub?: boolean }>({ items: [], @@ -57,56 +119,23 @@ const PlanetMenu: React.FC = () => { return ( <> - + <> {visible && ( <> - + - + {menu.items.map((item, index) => ( setCurrentItem({ label: item.label, visible: true })} onMouseLeave={() => setCurrentItem((prevState) => ({ ...prevState, visible: false }))} onClick={() => handleItemClick(index)} - sx={(theme) => ({ + sx={{ transform: getTransform(index, menu.items.length), - position: 'absolute', - width: 40, - height: 40, - display: 'flex', - alignItems: 'center', - justifyContent: 'center', - borderRadius: '50%', - backgroundColor: theme.colors.dark[6], - color: theme.colors.dark[0], - boxShadow: theme.shadows.sm, - padding: 12, - '&:hover': { - backgroundColor: theme.colors.dark[5], - cursor: 'pointer', - }, - })} + }} + className={classes.button} > @@ -116,27 +145,10 @@ const PlanetMenu: React.FC = () => { )} - + {(styles) => ( - ({ - backgroundColor: theme.colors.dark[6], - color: theme.colors.dark[2], - padding: 8, - borderRadius: theme.radius.sm, - fontWeight: 500, - fontSize: 14, - boxShadow: theme.shadows.sm, - textAlign: 'center', - })} - > + {currentItem.label} )}