Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit ce3e374

Browse files
committed
update docs and examples
1 parent b82b23b commit ce3e374

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ All the changes can be found below. Order used:
99
- Fixed
1010
- Security
1111

12+
## v1.2.0
13+
- Added `connect` helper to render different items based on which component was (right) clicked.
14+
1215
## v1.1.1
1316

1417
### Fixed

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ The module exports the following:
9797
- `MenuItem`
9898
- `SubMenu`
9999
- `monitor`
100+
- `connect`
100101

101102

102103
### ContextMenu(props)
@@ -223,6 +224,20 @@ Type: `Function`
223224

224225
A utility function to hide the currently active contextmenu programmatically.
225226

227+
### connect(Menu)
228+
229+
Type: `Function`
230+
231+
Returns: React Component
232+
233+
A simple wrapper to be used when different items must be rendered based on which component was (right) clicked.
234+
235+
**Menu**
236+
237+
Type: React Component
238+
239+
The `Menu` component that needs to be updated depending on the current selection. The component will receive object from `monitor.getItem()` in its props with `item` as key. All the other props will be simply passed through.
240+
226241
## Credits
227242
This project is based on the ideas from [react-dnd](https://github.com/gaearon/react-dnd) by [Dan Abramov](https://github.com/gaearon).
228243

examples/multiple-targets/menu.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
"use strict";
22

33
import React from "react";
4-
import { ContextMenu, MenuItem } from "../../src";
4+
import { ContextMenu, MenuItem, connect } from "../../src";
55
import MenuTypes from "./constants";
66

77
const Menu = React.createClass({
88
displayName: "Menu",
99
handleClick(e, data) {
1010
this.props.addLog(`Clicked on menu ${data.item} on ${data.name}`);
1111
},
12+
handleEat(e, data) {
13+
this.props.addLog(`Must Eat ${data.name}`);
14+
},
1215
render() {
16+
let { name } = this.props.item;
17+
1318
return (
1419
<ContextMenu identifier={MenuTypes.multi}>
1520
<MenuItem onClick={this.handleClick} data={{item: "item 1"}}>Menu Item 1</MenuItem>
1621
<MenuItem onClick={this.handleClick} data={{item: "item 2"}}>Menu Item 2</MenuItem>
22+
<MenuItem onClick={this.handleEat}>Eat {name}</MenuItem>
1723
</ContextMenu>
1824
);
1925
}
2026
});
2127

22-
export default Menu;
28+
export default connect(Menu);

0 commit comments

Comments
 (0)