Skip to content

Commit 23457ba

Browse files
committed
Refactor ContextMenu to use styled components
1 parent 3b6d917 commit 23457ba

3 files changed

Lines changed: 10 additions & 12 deletions

File tree

src/components/ContextMenu/ContextMenu.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useRef } from "react";
22
import MenuItems, { MenuItemProps } from "../MenuItems";
33
import useDetectMouseDownOutside from "../../hooks/useDetectMouseDownOutside";
44

5-
import "./ContextMenu.scss";
5+
import { StyledContextMenu } from "./styles";
66

77
interface ContextMenuProps {
88
items: Array<MenuItemProps>;
@@ -16,20 +16,13 @@ function ContextMenu({ items, position, close }: ContextMenuProps) {
1616
useDetectMouseDownOutside({ elementRef, onMouseDown: close });
1717

1818
return (
19-
<div
20-
className="context-menu"
21-
ref={elementRef}
22-
style={{
23-
left: position.x,
24-
top: position.y,
25-
}}
26-
>
19+
<StyledContextMenu position={position} ref={elementRef}>
2720
<MenuItems
2821
items={items}
2922
position={{ x: 0, y: 0 }}
3023
positionType="relative"
3124
/>
32-
</div>
25+
</StyledContextMenu>
3326
);
3427
}
3528

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
.context-menu {
1+
import styled from "@emotion/styled";
2+
import { Position } from "../../hooks/useDragToResize";
3+
4+
export const StyledContextMenu = styled.div<{ position: Position }>`
25
position: fixed;
36
// Kind of hacky - we need the context menu to always
47
// display on top of everything else. We could use the zIndex that's
58
// stored in global state, but this is fine for now.
69
// It will hit an issue in a very rare case, when window zindexes have
710
// been switched enough and the bordered app hits or exceeds this number.
811
z-index: 9999;
9-
}
12+
left: ${(props) => props.position.x}px;
13+
top: ${(props) => props.position.y}px;
14+
`;

0 commit comments

Comments
 (0)