forked from vkbansal/react-contextmenu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontextmenu-layer.js
More file actions
70 lines (60 loc) · 2.13 KB
/
Copy pathcontextmenu-layer.js
File metadata and controls
70 lines (60 loc) · 2.13 KB
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
67
68
69
70
"use strict";
import React from "react";
import invariant from "invariant";
import _isObject from "lodash.isobject";
import store from "./redux/store";
export default function(identifier, configure) {
return function(Component) {
const displayName = Component.displayName
|| Component.name
|| "Component";
invariant(
identifier && (typeof identifier === "string"
|| typeof identifier === "symbol"
|| typeof identifier === "function"),
"Expected identifier to be string, symbol or function. See %s",
displayName
);
if (configure) {
invariant(
typeof configure === "function",
"Expected configure to be a function. See %s",
displayName
);
}
return React.createClass({
displayName: `${displayName}ContextMenuLayer`,
getDefaultProps() {
return {
renderTag: "div"
};
},
handleContextClick(event) {
let currentItem = typeof configure === "function"
? configure(this.props)
: {};
invariant(
_isObject(currentItem),
"Expected configure to return an object. See %s",
displayName
);
event.preventDefault();
store.dispatch({
type: "SET_PARAMS",
data: {
x: event.clientX,
y: event.clientY,
currentItem,
isVisible: typeof identifier === "function" ? identifier(this.props) : identifier
}
});
},
render() {
return React.createElement(this.props.renderTag, {
className: "react-context-menu-wrapper",
onContextMenu: this.handleContextClick
}, React.createElement(Component, this.props));
}
});
};
}