forked from vkbansal/react-contextmenu
-
Notifications
You must be signed in to change notification settings - Fork 2
/
MultipleMenus.js
54 lines (48 loc) · 2.05 KB
/
MultipleMenus.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React, { Component } from 'react';
import ContextMenuTrigger from 'src/ContextMenuTrigger';
import ContextMenu from 'src/ContextMenu';
import MenuItem from 'src/MenuItem';
const MENU_1 = 'MENU_1';
const MENU_2 = 'MENU_2';
export default class MultipleMenus extends Component {
constructor(props) {
super(props);
this.state = { logs: [] };
}
handleClick = (e, data) => {
this.setState(({ logs }) => ({
logs: [`Clicked on menu ${data.menu} item ${data.item}`, ...logs]
}));
};
render() {
return (
<div>
<h3>Multiple Menus</h3>
<p>This demo shows usage of multiple menus on multiple targets.</p>
<div className='pure-g'>
<div className='pure-u-1-2'>
<ContextMenuTrigger id={MENU_1} holdToDisplay={1000}>
<div className='well'>right click to see the menu</div>
</ContextMenuTrigger>
</div>
<div className='pure-u-1-2'>
<ContextMenuTrigger id={MENU_2} holdToDisplay={1000}>
<div className='well'>right click to see the menu</div>
</ContextMenuTrigger>
</div>
</div>
<div>
{this.state.logs.map((log, i) => <p key={i}>{log}</p>)}
</div>
<ContextMenu id={MENU_1}>
<MenuItem onClick={this.handleClick} data={{ menu: 1, item: 1 }}>Menu 1 Item 1</MenuItem>
<MenuItem onClick={this.handleClick} data={{ menu: 1, item: 2 }}>Menu 1 Item 2</MenuItem>
</ContextMenu>
<ContextMenu id={MENU_2}>
<MenuItem onClick={this.handleClick} data={{ menu: 2, item: 1 }}>Menu 2 Item 1</MenuItem>
<MenuItem onClick={this.handleClick} data={{ menu: 2, item: 2 }}>Menu 2 Item 2</MenuItem>
</ContextMenu>
</div>
);
}
}