Skip to content

Commit

Permalink
fix menu hiddenBottom
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Bulat committed Mar 5, 2024
1 parent 31c0781 commit d986aff
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/contexts/Menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export const MenuProvider = ({ children }: { children: ReactNode }) => {
// position.
const bodyRect = document.body.getBoundingClientRect();
const menuRect = ref.current.getBoundingClientRect();
const hiddenRight = menuRect.right > bodyRect.right;
const hiddenBottom = menuRect.bottom > bodyRect.bottom;
const hiddenRight = menuRect.right > bodyRect.right - DocumentPadding;
const hiddenBottom = menuRect.bottom > bodyRect.bottom - DocumentPadding;

const x = hiddenRight
? window.innerWidth - menuRect.width - DocumentPadding
Expand Down
24 changes: 14 additions & 10 deletions src/library/ContextMenu/Wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ import { motion } from 'framer-motion';
import styled from 'styled-components';

export const Wrapper = styled(motion.div)`
border: 1px solid var(--border-secondary-color);
background: var(--background-default);
border-radius: 0.4rem;
display: flex;
flex-flow: column wrap;
/* TODO: make theme variable + dark mode support */
box-shadow:
0 4px 6px -1px rgba(0, 0, 0, 0.07),
0 2px 4px -2px rgba(0, 0, 0, 0.07);
width: 256px;
> .inner {
border: 1px solid var(--border-secondary-color);
background: var(--background-default);
border-radius: 0.4rem;
display: flex;
flex-flow: column wrap;
/* TODO: make theme variable + dark mode support */
box-shadow:
0 4px 6px -1px rgba(0, 0, 0, 0.07),
0 2px 4px -2px rgba(0, 0, 0, 0.07);
width: 100%;
}
`;

export const ListWrapper = styled.ul`
Expand Down
40 changes: 23 additions & 17 deletions src/library/ContextMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useEffect, useRef, useState } from 'react';
import { useMenu } from 'contexts/Menu';
import { Wrapper } from './Wrappers';
import { useOutsideAlerter } from 'hooks/useOutsideAlerter';
import { motion } from 'framer-motion';

export const ContextMenu = () => {
const {
Expand Down Expand Up @@ -58,30 +59,35 @@ export const ContextMenu = () => {
open && (
<Wrapper
ref={menuRef}
animate={!hidden ? 'show' : 'hidden'}
variants={{
hidden: {
opacity: 0,
transform: 'scale(0.93)',
},
show: {
opacity: 1,
transform: 'scale(1)',
},
}}
transition={{
duration: TRANSITION_DURATION_MS * 0.001,
ease: [0.1, 1, 0.1, 1],
}}
onAnimationComplete={() => checkMenuPosition(menuRef)}
style={{
position: 'absolute',
left: `${x}px`,
top: `${y}px`,
zIndex: 999,
opacity: show ? 1 : 0,
zIndex: 99,
}}
>
{inner}
<motion.div
animate={!hidden ? 'show' : 'hidden'}
variants={{
hidden: {
opacity: 0,
transform: 'scale(0.93)',
},
show: {
opacity: 1,
transform: 'scale(1)',
},
}}
transition={{
duration: TRANSITION_DURATION_MS * 0.001,
ease: [0.1, 1, 0.1, 1],
}}
className="inner"
>
{inner}
</motion.div>
</Wrapper>
)
);
Expand Down

0 comments on commit d986aff

Please sign in to comment.