UNPKG

@intuitionrobotics/thunderstorm

Version:
39 lines 1.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ClickToDrag = void 0; const React = require("react"); const BaseComponent_1 = require("../../core/BaseComponent"); const OverlayWithDocumentListener_1 = require("./OverlayWithDocumentListener"); class ClickToDrag extends BaseComponent_1.BaseComponent { constructor(props) { super(props); this.handleMouseDown = () => { this.setState({ isDragging: true }); }; this.onMouseMove = (e) => { if (!this.state.isDragging) return; if (this.props.onMouseMove) this.props.onMouseMove(e); }; this.onMouseUp = (e) => { this.setState({ isDragging: false }); if (this.props.onMouseUp) this.props.onMouseUp(e); }; this.render = () => { return (React.createElement("div", { style: { display: "contents" }, onMouseDown: this.handleMouseDown }, this.props.children, this.renderOverlay())); }; this.renderOverlay = () => { return this.state.isDragging && React.createElement(OverlayWithDocumentListener_1.OverlayWithDocumentListener, { documentOnMouseMove: this.onMouseMove, documentOnMouseUp: this.onMouseUp, zIndex: this.props.overlayZIndex }); }; this.state = { isDragging: false }; } } exports.ClickToDrag = ClickToDrag; //# sourceMappingURL=ClickToDrag.js.map