react-context-menus
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -108,2 +108,4 @@ Overview | ||
show: props.show // The show property will determine whether to show the menu (if you want to do it manually) | ||
container: { zIndex: 1 } // The container property will adjust the menu container (the fixed element that's attached to your component). | ||
// Current, the only option is to adjust its zIndex if needed. | ||
} | ||
@@ -110,0 +112,0 @@ } |
@@ -38,3 +38,3 @@ 'use strict'; | ||
var ContextMenu = function ContextMenu(menu_items) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
var _options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
@@ -50,8 +50,13 @@ return function (ChildComponent) { | ||
_this.options = typeof options === 'function' ? options(props) : options; | ||
_this.options = typeof _options === 'function' ? function (_props) { | ||
return _options(_props); | ||
} : function (_props) { | ||
return _options; | ||
}; | ||
var options = _this.options(props); | ||
_this.state = { | ||
showContextMenu: _this.options.show !== undefined && _this.options.show, | ||
x: _this.options.at !== undefined && _this.options.at.x, | ||
y: _this.options.at !== undefined && _this.options.at.y | ||
showContextMenu: options.show !== undefined && options.show, | ||
x: options.at !== undefined && options.at.x, | ||
y: options.at !== undefined && options.at.y | ||
}; | ||
@@ -69,2 +74,4 @@ | ||
Container.prototype.componentDidMount = function componentDidMount() { | ||
var options = this.options(this.props); | ||
this.child = _reactDom2.default.findDOMNode(this); | ||
@@ -77,2 +84,3 @@ this.container = document.createElement('div'); | ||
this.container.style.height = 0; | ||
this.updateContainer(options); | ||
this.child.appendChild(this.container); | ||
@@ -110,6 +118,13 @@ | ||
Container.prototype.updateContainer = function updateContainer(options) { | ||
if (options.container !== undefined && this.container !== undefined) { | ||
if (options.container.zIndex !== undefined) this.container.style.zIndex = options.container.zIndex; | ||
} | ||
}; | ||
Container.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { | ||
if (typeof options === 'function') this.options = options(nextProps); | ||
if (this.options.show !== undefined) this._mounted && this.setState({ showContextMenu: this.options.show }); | ||
if (this.options.at !== undefined) this._mounted && this.setState(_extends({}, this.options.at)); | ||
var options = this.options(nextProps); | ||
if (options.show !== undefined) this._mounted && this.setState({ showContextMenu: options.show }); | ||
if (options.at !== undefined) this._mounted && this.setState(_extends({}, options.at)); | ||
this.updateContainer(options); | ||
}; | ||
@@ -154,4 +169,6 @@ | ||
var theme = this.options.theme || {}; | ||
var style = this.options.style || {}; | ||
var options = this.options(this.props); | ||
console.log(options); | ||
var theme = options.theme || {}; | ||
var style = options.style || {}; | ||
// Finally, render it to the container | ||
@@ -215,4 +232,2 @@ _reactDom2.default.render(_react2.default.createElement(_reactMenus2.default, { | ||
var bounds = this.child.getBoundingClientRect(); | ||
//let x = event.clientX - bounds.left; | ||
//let y = event.clientY - bounds.top; | ||
var x = event.clientX; | ||
@@ -219,0 +234,0 @@ var y = event.clientY; |
{ | ||
"name": "react-context-menus", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Better context menus for React", | ||
@@ -5,0 +5,0 @@ "main": "lib/context_menu.js", |
21572
201