import React, { Component, ChangeEvent, MouseEvent } from 'react'; import { Menu, Item, Separator, Submenu, contextMenu, theme, animation } from './../..'; import Table from './Table'; import Select from './Select'; import { BuiltInTheme } from '../../utils/styles'; import { MenuItemEventHandler } from '../../types'; const selector = { events: ['onContextMenu', 'onClick', 'onDoubleClick'], themes: [ 'none', ...Object.keys(theme).map(k => theme[k as keyof BuiltInTheme]) ], animations: [ 'none', ...Object.keys(animation).map(k => animation[k as keyof typeof animation]) ] }; const square = { x: 50, y: 50, width: 100, height: 100 }; const menuId = 1; const MyAwesomeMenu: React.SFC<{ theme: string; animation: string; onClick: (p: any) => void; }> = ({ theme, animation, onClick }) => ( 💩 Foo Ipsum Sit {null} Dolor {null} Bar ); class App extends Component { state = { event: selector.events[0], theme: selector.themes[0], animation: selector.animations[0], payload: {} }; canvasRef!: HTMLCanvasElement; componentDidMount() { const ctx = this.canvasRef.getContext('2d')!; ctx.fillRect(square.x, square.y, square.width, square.height); ctx.font = '16px arial'; ctx.fillStyle = 'black'; ctx.fillText('only the black box', 10, 20); ctx.fillText('trigger the event', 10, 40); } handleMenuItem = (payload: MenuItemEventHandler) => { const { clientX, clientY } = payload.event; this.setState({ payload: { event: { clientX, clientY }, props: payload.props } }); }; handleClick = (e: MouseEvent) => { e.preventDefault(); if ((e.target as HTMLElement).tagName === 'CANVAS') { const rect = this.canvasRef.getBoundingClientRect(); const x = e.clientX - rect.left; const y = e.clientY - rect.top; const isColliding = x >= square.x && x <= square.x + square.width && y >= square.y && y <= square.y + square.height; if (!isColliding) { return; } } contextMenu.show({ id: menuId, event: e, props: { now: Date.now() } }); }; handleSelector = (e: ChangeEvent) => { this.setState({ [e.target.name]: e.target.value }); }; render() { return (