Skip to content

Commit c5c10ff

Browse files
authored
Merge pull request #10 from yWorks/dev
Add extra props to tooltip, context-menu, and popup
2 parents b312714 + 7fc1d5e commit c5c10ff

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@yworks/react-yfiles-core",
3-
"version": "1.2.0-beta.2",
3+
"version": "1.2.0-beta.3",
44
"author": {
55
"name": "yFiles for HTML team @ yWorks GmbH",
66
"email": "[email protected]"

src/context-menu/ContextMenu.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ export interface ContextMenuProps<TDataItem> {
7474
* An optional component used for rendering a custom context menu.
7575
*/
7676
renderMenu?: ComponentType<RenderContextMenuProps<TDataItem>>
77+
/**
78+
* Optional global props that get passed to the context-menu component
79+
*/
80+
extraProps?: Record<string, any>
7781
}
7882

7983
/**
@@ -82,7 +86,8 @@ export interface ContextMenuProps<TDataItem> {
8286
*/
8387
export function ContextMenu<TDataItem>({
8488
menuItems,
85-
renderMenu
89+
renderMenu,
90+
extraProps
8691
}: ContextMenuProps<TDataItem> & PropsWithChildren) {
8792
const [menuVisible, setMenuVisible] = useState(false)
8893
const [menuLocation, setMenuLocation] = useState({ x: 0, y: 0 })
@@ -201,6 +206,7 @@ export function ContextMenu<TDataItem>({
201206
setMenuVisible(false)
202207
}}
203208
renderMenu={renderMenu}
209+
extraProps={extraProps}
204210
></ContextMenuCore>
205211
)}
206212
</>
@@ -215,7 +221,8 @@ function ContextMenuCore<TDataItem>({
215221
menuItems,
216222
menuLocation,
217223
onClose,
218-
renderMenu = DefaultRenderMenu
224+
renderMenu = DefaultRenderMenu,
225+
extraProps
219226
}: ContextMenuProps<TDataItem> & {
220227
dataItem: TDataItem | null
221228
onClose: Function
@@ -224,7 +231,8 @@ function ContextMenuCore<TDataItem>({
224231
const menu = createElement(renderMenu, {
225232
menuItems: menuItems ? menuItems(dataItem) : [],
226233
item: dataItem,
227-
onClose: onClose
234+
onClose: onClose,
235+
...extraProps
228236
})
229237
return (
230238
menu && (

src/popup/Popup.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ export interface PopupProps<TDataItem> {
7272
* The default is single-click.
7373
*/
7474
clickMode?: 'single' | 'double'
75+
76+
/**
77+
* Optional global props that get passed to the popup component
78+
*/
79+
extraProps?: Record<string, any>
7580
}
7681

7782
/**
@@ -81,7 +86,8 @@ export interface PopupProps<TDataItem> {
8186
export function Popup<TDataItem>({
8287
renderPopup,
8388
position,
84-
clickMode
89+
clickMode,
90+
extraProps
8591
}: PopupProps<TDataItem> & PropsWithChildren) {
8692
const graphComponent = useGraphComponent()!
8793
const [location, setLocation] = useState<{ x: number; y: number }>({ x: 0, y: 0 })
@@ -153,7 +159,8 @@ export function Popup<TDataItem>({
153159
item: currentItem?.tag,
154160
onClose: () => {
155161
setCurrentItem(null)
156-
}
162+
},
163+
...extraProps
157164
})
158165
: null
159166
return (

src/tooltip-component/Tooltip.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ export interface RenderTooltipProps<TDataItem> {
3434
*/
3535
export interface TooltipProps<TDataItem> {
3636
renderTooltip?: ComponentType<RenderTooltipProps<TDataItem>>
37+
extraProps?: Record<string, any>
3738
}
3839

3940
/**
4041
* The Tooltip component adds an item tooltip to its parent component. It is designed to be used inside a
4142
* parent component that displays the graph.
4243
*/
43-
export function Tooltip<TDataItem>({ renderTooltip }: TooltipProps<TDataItem>) {
44+
export function Tooltip<TDataItem>({ renderTooltip, extraProps }: TooltipProps<TDataItem>) {
4445
const graphComponent = useGraphComponent()!
4546

4647
const [tooltipRenderInfo, setTooltipRenderInfo] = useState<TooltipRenderInfo<TDataItem> | null>(
@@ -89,10 +90,10 @@ export function Tooltip<TDataItem>({ renderTooltip }: TooltipProps<TDataItem>) {
8990
createElement(
9091
TooltipWrapper,
9192
{},
92-
createElement<RenderTooltipProps<TDataItem>>(
93-
tooltipRenderInfo.component,
94-
tooltipRenderInfo.props
95-
)
93+
createElement<RenderTooltipProps<TDataItem>>(tooltipRenderInfo.component, {
94+
...tooltipRenderInfo.props,
95+
...extraProps
96+
})
9697
),
9798
tooltipRenderInfo.domNode
9899
)}

0 commit comments

Comments
 (0)