Skip to content

Commit

Permalink
refactor: use draggable
Browse files Browse the repository at this point in the history
- helps maintain landscape fixed positioning
  • Loading branch information
thenick775 committed Jan 18, 2025
1 parent c800c9a commit f64c74c
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions gbajs3/src/components/navigation-menu/navigation-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useMediaQuery } from '@mui/material';
import { useId, useState } from 'react';
import { useId, useRef, useState } from 'react';
import Draggable from 'react-draggable';
import toast from 'react-hot-toast';
import {
BiInfoCircle,
Expand All @@ -22,7 +23,6 @@ import {
BiMenu,
BiFileFind
} from 'react-icons/bi';
import { Rnd } from 'react-rnd';
import { styled, useTheme } from 'styled-components';

import { NavigationMenuWidth } from './consts.tsx';
Expand Down Expand Up @@ -165,6 +165,7 @@ const NavigationMenuClearDismiss = styled.button`

export const NavigationMenu = () => {
const [isExpanded, setIsExpanded] = useState(true);
const menuButtonRef = useRef<HTMLButtonElement | null>(null);
const { setModalContent, setIsModalOpen } = useModalContext();
const { isAuthenticated } = useAuthContext();
const { canvas, emulator } = useEmulatorContext();
Expand All @@ -184,18 +185,18 @@ export const NavigationMenu = () => {

return (
<>
<Rnd
dragAxis="y"
disableDragging={!areItemsDraggable}
enableResizing={false}
bounds="body"
<Draggable
nodeRef={menuButtonRef}
bounds="parent"
position={layouts?.hamburgerButton?.position ?? { x: 0, y: 0 }}
style={{ zIndex: 200 }}
onDragStop={(_, data) =>
setLayout('hamburgerButton', { position: { x: data.x, y: data.y } })
disabled={!areItemsDraggable}
onStop={(_, data) =>
setLayout('hamburgerButton', { position: { x: 0, y: data.y } })
}
axis="y"
>
<HamburgerButton
ref={menuButtonRef}
id="menu-btn"
$isExpanded={isExpanded}
onClick={() => setIsExpanded((prevState) => !prevState)}
Expand All @@ -206,7 +207,7 @@ export const NavigationMenu = () => {
style={{ height: '29px', width: '29px', verticalAlign: 'middle' }}
/>
</HamburgerButton>
</Rnd>
</Draggable>
<NavigationMenuWrapper
data-testid="menu-wrapper"
id="menu-wrapper"
Expand Down

0 comments on commit f64c74c

Please sign in to comment.