forked from vkbansal/react-contextmenu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Customization.js
66 lines (58 loc) · 1.9 KB
/
Customization.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
55
56
57
58
59
60
61
62
63
64
65
66
import React, { Component } from 'react';
import ContextMenuTrigger from 'src/ContextMenuTrigger';
import ContextMenu from 'src/ContextMenu';
import MenuItem from 'src/MenuItem';
const MENU_TYPE = 'SIMPLE';
const targets = [{
name: 'Banana'
}, {
name: 'Apple'
}, {
name: 'Papaya'
}, {
name: 'Mango'
}, {
name: 'Orange'
}, {
name: 'Pineapple'
}];
function collect(props) {
return { name: props.name };
}
export default class Customization extends Component {
constructor(props) {
super(props);
this.state = { logs: [] };
}
handleClick = (e, data) => {
this.setState(({logs}) => ({
logs: [`Clicked on ${data.name} menu ${data.item}`, ...logs]
}));
}
render() {
return (
<div>
<h3>Custom Wrappers</h3>
<p>This demo shows usage of customization. Instead of using <code>div</code>s by default, we are using <code>tr</code>s</p>
<table className='table table-bordered'>
<tbody>
{targets.map((item, i) => (
<ContextMenuTrigger renderTag='tr' name={item.name}
id={MENU_TYPE} holdToDisplay={1000} key={i}
collect={collect}>
<td>{item.name}</td>
</ContextMenuTrigger>
))}
</tbody>
</table>
<div>
{this.state.logs.map((log, i) => (<p key={i}>{log}</p>))}
</div>
<ContextMenu id={MENU_TYPE}>
<MenuItem onClick={this.handleClick} data={{item: 'item 1'}}>Menu Item 1</MenuItem>
<MenuItem onClick={this.handleClick} data={{item: 'item 2'}}>Menu Item 2</MenuItem>
</ContextMenu>
</div>
);
}
}