go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/projects/nodes/static/_nextjs/src/components/flowPaneContextMenu.tsx (about)

     1  /**
     2   * Copyright (c) 2024 - Present. Will Charczuk. All rights reserved.
     3   * Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     4   */
     5  import { Intent, Menu, MenuDivider, MenuItem } from "@blueprintjs/core";
     6  
     7  export interface FlowPaneContextMenuProps {
     8    top: number;
     9    left: number;
    10    right?: number;
    11    bottom?: number;
    12    onClick?: (e: any) => void;
    13  
    14    onAddNode: () => void;
    15    onRefresh: () => void;
    16    onStabilize: () => void;
    17  }
    18  
    19  export function FlowPaneContextMenu({ top, left, right, bottom, ...props }: FlowPaneContextMenuProps) {
    20    const onMenuItemClick = (handler: () => void) => {
    21      return (e: any) => {
    22        handler()
    23        if (props.onClick) {
    24          props.onClick(e)
    25        }
    26      }
    27    }
    28    return (
    29      <Menu small={true} style={{ top, left, right, bottom, position: 'fixed', zIndex: 100, width: '200px' }} className="flow-pane-context-menu">
    30        <MenuItem onClick={onMenuItemClick(() => props.onAddNode())} icon="add" intent={Intent.SUCCESS} text="Add node" />
    31        <MenuDivider />
    32        <MenuItem onClick={onMenuItemClick(() => props.onRefresh())} icon="refresh" text="Refresh" />
    33        <MenuItem onClick={onMenuItemClick(() => props.onStabilize())} icon="refresh" intent={Intent.PRIMARY} text="Stabilize" />
    34      </Menu>
    35    )
    36  }