|
1 | 1 | "use strict"; |
2 | 2 |
|
3 | | -import React from "react"; |
| 3 | +import React, { PropTypes } from "react"; |
4 | 4 | import classnames from "classnames"; |
5 | | -import _merge from "lodash.merge"; |
6 | | - |
7 | | -let { PropTypes } = React; |
| 5 | +import assign from "object-assign"; |
| 6 | +import flux from "./flux"; |
| 7 | +import monitor from "./monitor"; |
8 | 8 |
|
9 | 9 | const MenuItem = React.createClass({ |
10 | 10 | displayName: "MenuItem", |
11 | 11 | propTypes: { |
| 12 | + data: PropTypes.object, |
12 | 13 | disabled: PropTypes.bool, |
13 | | - selected: PropTypes.bool, |
14 | 14 | divider: PropTypes.bool, |
15 | | - data: PropTypes.object, |
| 15 | + onClick: PropTypes.func, |
16 | 16 | onSelect: PropTypes.func, |
17 | | - onClick: PropTypes.func |
| 17 | + selected: PropTypes.bool |
18 | 18 | }, |
19 | 19 | getDefaultProps() { |
20 | 20 | return { |
21 | 21 | disabled: false, |
22 | 22 | selected: false, |
23 | | - data: null |
| 23 | + data: {} |
24 | 24 | }; |
25 | 25 | }, |
26 | 26 | handleClick(event) { |
27 | | - let { disabled, onSelect, onClick, currentItem, data } = this.props; |
| 27 | + let { disabled, onSelect, onClick, data } = this.props; |
28 | 28 |
|
29 | 29 | if (disabled) { |
30 | 30 | event.preventDefault(); |
31 | 31 | return; |
32 | 32 | } |
33 | 33 |
|
| 34 | + assign(data, monitor.getItem()); |
| 35 | + |
34 | 36 | if (typeof onSelect === "function") { |
35 | 37 | event.preventDefault(); |
36 | | - onSelect(_merge(currentItem, data)); |
37 | | - this.props.hideMenu(); |
| 38 | + onSelect(data); |
| 39 | + this.hideMenu(); |
38 | 40 | return; |
39 | 41 | } |
40 | 42 |
|
41 | 43 | if (typeof onClick === "function") { |
42 | | - onClick(event, _merge(currentItem, data)); |
| 44 | + onClick(event, data); |
43 | 45 | } |
44 | 46 |
|
45 | | - this.props.hideMenu(); |
| 47 | + this.hideMenu(); |
| 48 | + }, |
| 49 | + hideMenu() { |
| 50 | + flux.getActions("menu").setParams({ |
| 51 | + isVisible: false, |
| 52 | + currentItem: {} |
| 53 | + }); |
46 | 54 | }, |
47 | 55 | render() { |
48 | 56 | let { divider, disabled, selected, children } = this.props; |
|
0 commit comments