react-ctxmenu-trigger
Version:
base abstract ctx menu trigger component for react
62 lines (43 loc) • 2.72 kB
JavaScript
exports.__esModule = true;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var LazyRenderBox = function (_Component) {
_inherits(LazyRenderBox, _Component);
function LazyRenderBox() {
_classCallCheck(this, LazyRenderBox);
return _possibleConstructorReturn(this, _Component.apply(this, arguments));
}
LazyRenderBox.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
return nextProps.hiddenClassName || nextProps.visible;
};
LazyRenderBox.prototype.render = function render() {
var _props = this.props,
hiddenClassName = _props.hiddenClassName,
visible = _props.visible,
props = _objectWithoutProperties(_props, ['hiddenClassName', 'visible']);
if (hiddenClassName || _react2['default'].Children.count(props.children) > 1) {
if (!visible && hiddenClassName) {
props.className += ' ' + hiddenClassName;
}
return _react2['default'].createElement('div', props);
}
return _react2['default'].Children.only(props.children);
};
return LazyRenderBox;
}(_react.Component);
LazyRenderBox.propTypes = {
children: _propTypes2['default'].any,
className: _propTypes2['default'].string,
visible: _propTypes2['default'].bool,
hiddenClassName: _propTypes2['default'].string
};
exports['default'] = LazyRenderBox;
module.exports = exports['default'];
;