-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Data Mapper): fixed dependency causing issue with React Flow v12 …
…upgrade (#5271) * standalone works with new component * fixed build with rename
- Loading branch information
1 parent
e002f4a
commit 9f013b7
Showing
3 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
libs/data-mapper/src/lib/components/cardContextMenu/CardContextMenu.tsx
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,66 @@ | ||
import type { MenuOpenChangeData } from '@fluentui/react-components'; | ||
import { Menu, MenuPopover, MenuList } from '@fluentui/react-components'; | ||
import { useCallback, useMemo } from 'react'; | ||
import { useIntl } from 'react-intl'; | ||
import { useOnViewportChange } from 'reactflow'; | ||
|
||
export interface CardContextMenuProps { | ||
contextMenuLocation?: { x: number; y: number }; | ||
menuItems: JSX.Element[]; | ||
open: boolean; | ||
setOpen: (open: boolean) => void; | ||
title: string; | ||
} | ||
|
||
export interface FUIReactMenuItem { | ||
key: string; | ||
text: string; | ||
subtext?: string; | ||
disabled?: boolean; | ||
icon?: JSX.Element; | ||
onClick?: (e: any) => void; | ||
} | ||
|
||
export const CardContextMenu: React.FC<CardContextMenuProps> = ({ contextMenuLocation, menuItems, open, title, setOpen }) => { | ||
const intl = useIntl(); | ||
|
||
useOnViewportChange({ | ||
onStart: useCallback(() => open && setOpen(false), [open, setOpen]), | ||
}); | ||
|
||
const CARD_CONTEXT_MENU_ARIA_LABEL = intl.formatMessage( | ||
{ | ||
defaultMessage: 'Context menu for {title} card', | ||
id: '+ZSBrq', | ||
description: 'Accessibility label', | ||
}, | ||
{ | ||
title, | ||
} | ||
); | ||
|
||
const onOpenChange = useCallback((_e: any, data: MenuOpenChangeData) => setOpen(data.open), [setOpen]); | ||
|
||
const positioning = useMemo(() => { | ||
const offset = contextMenuLocation ? { mainAxis: contextMenuLocation.y, crossAxis: contextMenuLocation.x } : undefined; | ||
const getBoundingClientRect = () => ({ | ||
x: contextMenuLocation?.x ?? 0, | ||
y: contextMenuLocation?.y ?? 0, | ||
width: 0, | ||
height: 0, | ||
top: 0, | ||
right: 0, | ||
bottom: 0, | ||
left: 0, | ||
}); | ||
return { target: { getBoundingClientRect }, offset }; | ||
}, [contextMenuLocation]); | ||
|
||
return ( | ||
<Menu open={open} aria-label={CARD_CONTEXT_MENU_ARIA_LABEL} onOpenChange={onOpenChange} positioning={positioning} closeOnScroll> | ||
<MenuPopover> | ||
<MenuList>{menuItems}</MenuList> | ||
</MenuPopover> | ||
</Menu> | ||
); | ||
}; |
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