ucsc-xena-client
Version:
UCSC Xena Client. Functional genomics visualizations.
114 lines (94 loc) • 4.54 kB
JavaScript
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
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 React = require('react');
var Resizable = require('react-resizable').Resizable;
var _ = require('../underscore_ext');
// Styles
require('./ResizeOverlay.css');
var max = function max(x, y) {
return x > y ? x : y;
};
var minWidthSize = function minWidthSize(minWidth, _ref) {
var width = _ref.width,
height = _ref.height;
return { width: max(minWidth, width), height: height };
};
var ResizeOverlay = function (_React$Component) {
_inherits(ResizeOverlay, _React$Component);
function ResizeOverlay() {
var _ref2;
var _temp, _this, _ret;
_classCallCheck(this, ResizeOverlay);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref2 = ResizeOverlay.__proto__ || Object.getPrototypeOf(ResizeOverlay)).call.apply(_ref2, [this].concat(args))), _this), _this.state = { zooming: false }, _this.onResizeStart = function () {
var _this$props = _this.props,
width = _this$props.width,
height = _this$props.height,
minWidth = _this.props.minWidth();
_this.setState({ zooming: true, zoomSize: { width: width, height: height }, minWidth: minWidth });
}, _this.onResize = function (ev, _ref3) {
var size = _ref3.size;
var width = size.width,
height = size.height,
minWidth = _this.state.minWidth;
_this.setState({ zoomSize: { width: max(width, minWidth), height: height } });
}, _this.onResizeStop = function (ev, _ref4) {
var size = _ref4.size;
var onResizeStop = _this.props.onResizeStop,
minWidth = _this.state.minWidth;
_this.setState({ zooming: false });
if (onResizeStop) {
onResizeStop(minWidthSize(minWidth, size));
}
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(ResizeOverlay, [{
key: 'render',
value: function render() {
var _state = this.state,
zooming = _state.zooming,
zoomSize = _state.zoomSize,
_props = this.props,
width = _props.width,
height = _props.height,
children = _props.children,
enable = _props.enable,
content = React.createElement(
'div',
{ style: { position: 'relative', cursor: 'none', zIndex: 0 } },
children
);
return React.createElement(
'div',
{ className: enable ? 'resize-enable' : '', style: { position: 'relative' } },
React.createElement('div', { style: {
display: zooming ? 'block' : 'none',
width: _.get(zoomSize, 'width', 0),
height: _.get(zoomSize, 'height', 0),
position: 'absolute',
top: 0,
left: 0,
zIndex: 999,
backgroundColor: 'rgba(0, 0, 0, 0.12)' } }),
React.createElement(
Resizable,
{ handleSize: [20, 20],
axis: 'both',
onResizeStop: this.onResizeStop,
onResize: this.onResize,
onResizeStart: this.onResizeStart,
width: width,
height: height },
content
)
);
}
}]);
return ResizeOverlay;
}(React.Component);
module.exports = ResizeOverlay;