UNPKG

terra-clinical-data-grid

Version:

An organizational component that renders a collection of data in a grid-like format.

111 lines (110 loc) 7.18 kB
"use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireDefault(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _bind = _interopRequireDefault(require("classnames/bind")); var _reactDraggable = require("react-draggable"); var _terraThemeContext = _interopRequireDefault(require("terra-theme-context")); var _ResizeHandleModule = _interopRequireDefault(require("./ResizeHandle.module.scss")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } var cx = _bind.default.bind(_ResizeHandleModule.default); var propTypes = { /** * String identifer for the ResizeHandle. This value will be provided to the `onResizeStop` function prop as a parameter for * identification purposes. */ id: _propTypes.default.string.isRequired, /** * Function called upon release of the ResizeHandle. The id, as well as the new ResizeHandle position, will be provided * as arguments. Parameters: `onResizeStop(resizeHandleId, positionDelta)` */ onResizeStop: _propTypes.default.func }; var ResizeHandle = /*#__PURE__*/function (_React$Component) { _inherits(ResizeHandle, _React$Component); function ResizeHandle(props) { var _this; _classCallCheck(this, ResizeHandle); _this = _callSuper(this, ResizeHandle, [props]); _this.handleDragMove = _this.handleDragMove.bind(_assertThisInitialized(_this)); _this.handleDragStart = _this.handleDragStart.bind(_assertThisInitialized(_this)); _this.handleDragStop = _this.handleDragStop.bind(_assertThisInitialized(_this)); return _this; } _createClass(ResizeHandle, [{ key: "handleDragMove", value: function handleDragMove(event, data) { var handleNode = data.node; this.resizeHandleDragPosition += data.deltaX; handleNode.style.transform = "translate3d(".concat(this.resizeHandleDragPosition, "px, 0, 0)"); } }, { key: "handleDragStart", value: function handleDragStart(event, data) { var handleNode = data.node; this.resizeHandleDragPosition = 0; handleNode.classList.add(cx('dragging')); } }, { key: "handleDragStop", value: function handleDragStop(event, data) { var _this$props = this.props, id = _this$props.id, onResizeStop = _this$props.onResizeStop; var handleNode = data.node; handleNode.classList.remove(cx('dragging')); handleNode.style.transform = ''; if (onResizeStop) { onResizeStop(id, this.resizeHandleDragPosition); } } }, { key: "render", value: function render() { var theme = this.context; return ( /*#__PURE__*/ /* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */ _react.default.createElement(_reactDraggable.DraggableCore, { onStart: this.handleDragStart, onStop: this.handleDragStop, onDrag: this.handleDragMove }, /*#__PURE__*/_react.default.createElement("div", { className: cx('resize-handle', theme.className), onClick: ResizeHandle.preventClickEvent })) /* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */ ); } }], [{ key: "preventClickEvent", value: /** * Click events that occur on the ResizeHandle are not propagated. This prevents clicks on the ResizeHandle from registering * as clicks on the elements over which the ResizeHandle is rendered. */ function preventClickEvent(event) { event.stopPropagation(); } }]); return ResizeHandle; }(_react.default.Component); ResizeHandle.propTypes = propTypes; ResizeHandle.contextType = _terraThemeContext.default; var _default = exports.default = ResizeHandle;