UNPKG

@up-group/react-controls

Version:

We know that there are a ton of react UI library projects to choose from. Our hope with this one is to provide the next generation of react components that you can use to bootstrap your next project, or as a reference for building a UIKit. Read on to get

149 lines 5.99 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var React = require("react"); var assign = require("object-assign"); var helpers_1 = require("../../../Common/utils/helpers"); var actions_1 = require("./actions"); var UpContextMenuTrigger = (function (_super) { __extends(UpContextMenuTrigger, _super); function UpContextMenuTrigger() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.mouseDown = false; _this.handleMouseDown = function (event) { if (event.which === 3 || event.button === 2) { _this.mouseDown = true; _this.handleContextClick(event); } }; _this.handleMouseUp = function (event) { if (event.which === 3 || event.button === 2) { _this.mouseDown = false; } }; _this.handleContextClick = function (event) { event.preventDefault(); event.stopPropagation(); var x = event.clientX; var y = event.clientY; actions_1.hideMenu(); actions_1.showMenu({ position: { x: x, y: y }, target: _this.element, id: _this.props.id, data: helpers_1.callIfExists(_this.props.collect, _this.props) }); }; _this.setElement = function (element) { _this.element = element; }; return _this; } UpContextMenuTrigger.prototype.render = function () { var _a = this.props, renderTag = _a.renderTag, attributes = _a.attributes, children = _a.children; var newAttrs = assign({}, attributes, { onContextMenu: this.handleContextClick, onMouseDown: this.handleMouseDown, onMouseUp: this.handleMouseUp, ref: this.setElement }); return React.createElement(renderTag, newAttrs, children); }; UpContextMenuTrigger.defaultProps = { attributes: {}, holdToDisplay: null, renderTag: 'div' }; return UpContextMenuTrigger; }(React.PureComponent)); exports.UpContextMenuTrigger = UpContextMenuTrigger; var UpTouchContextMenuTrigger = (function (_super) { __extends(UpTouchContextMenuTrigger, _super); function UpTouchContextMenuTrigger() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.mouseDown = false; _this.handleMouseDown = function (event) { if (_this.props.holdToDisplay >= 0 && event.button === 0) { event.persist(); _this.mouseDown = true; setTimeout(function () { if (_this.mouseDown) _this.handleContextClick(event); }, _this.props.holdToDisplay); } }; _this.handleMouseUp = function (event) { if (event.button === 0) { _this.mouseDown = false; } }; _this.handleTouchstart = function (event) { if (_this.props.holdToDisplay >= 0) { event.persist(); _this.mouseDown = true; setTimeout(function () { if (_this.mouseDown) _this.handleContextClick(event); }, _this.props.holdToDisplay); } }; _this.handleTouchEnd = function (event) { event.preventDefault(); _this.mouseDown = false; }; _this.handleContextClick = function (event) { event.preventDefault(); event.stopPropagation(); var x = event.clientX || (event.touches && event.touches[0].pageX); var y = event.clientY || (event.touches && event.touches[0].pageY); actions_1.hideMenu(); actions_1.showMenu({ position: { x: x, y: y }, target: _this.element, id: _this.props.id, data: helpers_1.callIfExists(_this.props.collect, _this.props) }); }; _this.setElement = function (element) { _this.element = element; }; return _this; } UpTouchContextMenuTrigger.prototype.render = function () { var _a = this.props, renderTag = _a.renderTag, attributes = _a.attributes, children = _a.children; var newAttrs = assign({}, attributes, { onContextMenu: this.handleContextClick, onMouseDown: this.handleMouseDown, onMouseUp: this.handleMouseUp, onTouchStart: this.handleTouchstart, onTouchEnd: this.handleTouchEnd, onMouseOut: this.handleMouseUp, ref: this.setElement }); return React.createElement(renderTag, newAttrs, children); }; UpTouchContextMenuTrigger.defaultProps = { attributes: {}, holdToDisplay: 1000, renderTag: 'div' }; return UpTouchContextMenuTrigger; }(React.PureComponent)); exports.UpTouchContextMenuTrigger = UpTouchContextMenuTrigger; var hasTouch = false; try { document.createEvent('TouchStart'); hasTouch = true; } catch (e) { } exports.default = !hasTouch ? UpContextMenuTrigger : UpTouchContextMenuTrigger; //# sourceMappingURL=UpContextMenuTrigger.js.map