-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(refactor): Menu refresh with mouse-based position (#1945)
- Loading branch information
Ross Bulat
authored
Feb 13, 2024
1 parent
b168bdd
commit bf856d0
Showing
9 changed files
with
156 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,29 @@ | ||
// Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
import type { ReactNode, RefObject } from 'react'; | ||
import type { | ||
ReactNode, | ||
RefObject, | ||
MouseEvent as ReactMouseEvent, | ||
} from 'react'; | ||
|
||
export interface MenuContextInterface { | ||
openMenu: () => void; | ||
open: boolean; | ||
show: boolean; | ||
inner: ReactNode | null; | ||
position: [number, number]; | ||
openMenu: (ev: MenuMouseEvent, newInner?: ReactNode) => void; | ||
closeMenu: () => void; | ||
setMenuPosition: (ref: RefObject<HTMLDivElement>) => void; | ||
setMenuInner: (items: ReactNode) => void; | ||
checkMenuPosition: (ref: RefObject<HTMLDivElement>) => void; | ||
setMenuItems: (items: MenuItem[]) => void; | ||
open: number; | ||
show: number; | ||
position: [number, number]; | ||
items: MenuItem[]; | ||
} | ||
|
||
export interface MenuItem { | ||
icon: ReactNode; | ||
title: string; | ||
cb: () => void; | ||
} | ||
|
||
export type MenuMouseEvent = | ||
| MouseEvent | ||
| ReactMouseEvent<HTMLButtonElement, MouseEvent>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { MenuItem } from 'contexts/Menu/types'; | ||
import { ItemWrapper } from './Wrappers'; | ||
import { useMenu } from 'contexts/Menu'; | ||
|
||
export const MenuList = ({ items }: { items: MenuItem[] }) => { | ||
const { closeMenu } = useMenu(); | ||
|
||
return ( | ||
<> | ||
{items.map((item, i: number) => { | ||
const { icon, title, cb } = item; | ||
|
||
return ( | ||
<ItemWrapper | ||
key={`menu_item_${i}`} | ||
onClick={() => { | ||
cb(); | ||
closeMenu(); | ||
}} | ||
> | ||
{icon} | ||
<div className="title">{title}</div> | ||
</ItemWrapper> | ||
); | ||
})} | ||
</> | ||
); | ||
}; |
Oops, something went wrong.