UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

157 lines (133 loc) 5.7 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectSpread from "@babel/runtime/helpers/objectSpread2"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; function _createSuper(Derived) { function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } return function () { var Super = _getPrototypeOf(Derived), result; if (isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } // @ts-nocheck import * as React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { defaultClassPrefix, getUnhandledProps, prefix } from './utils'; import TableContext from './TableContext'; var propTypes = { width: PropTypes.number, height: PropTypes.number, headerHeight: PropTypes.number, top: PropTypes.number, isHeaderRow: PropTypes.bool, rowDraggable: PropTypes.bool, rowRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), className: PropTypes.string, classPrefix: PropTypes.string, style: PropTypes.object, provided: PropTypes.object, snapshot: PropTypes.object }; var Row = /*#__PURE__*/ function (_React$PureComponent) { _inherits(Row, _React$PureComponent); var _super = _createSuper(Row); function Row() { _classCallCheck(this, Row); return _super.apply(this, arguments); } _createClass(Row, [{ key: "render", value: function render() { var _this$props = this.props, className = _this$props.className, width = _this$props.width, height = _this$props.height, top = _this$props.top, style = _this$props.style, isHeaderRow = _this$props.isHeaderRow, headerHeight = _this$props.headerHeight, rowRef = _this$props.rowRef, classPrefix = _this$props.classPrefix, children = _this$props.children, rowDraggable = _this$props.rowDraggable, provided = _this$props.provided, snapshot = _this$props.snapshot, rest = _objectWithoutProperties(_this$props, ["className", "width", "height", "top", "style", "isHeaderRow", "headerHeight", "rowRef", "classPrefix", "children", "rowDraggable", "provided", "snapshot"]); var addPrefix = prefix(classPrefix); var classes = classNames(classPrefix, className, _defineProperty({}, addPrefix('header'), isHeaderRow)); var styles = _objectSpread({ minWidth: width, height: isHeaderRow ? headerHeight : height }, style); var unhandledProps = getUnhandledProps(propTypes, rest); return React.createElement(TableContext.Consumer, null, function (_ref) { var translateDOMPositionXY = _ref.translateDOMPositionXY; translateDOMPositionXY === null || translateDOMPositionXY === void 0 ? void 0 : translateDOMPositionXY(styles, 0, top); var providedProps = {}; var transform = styles.transform; if (rowDraggable && provided) { var regex = new RegExp('translate\\((.*?)px, (.*?)px\\)'); var regex3d = new RegExp('translate3d\\((.*?)px,(.*?)px,(.*?)\\)'); // the transform property of parent style gotten through reference and passed in as a prop var parentValues = regex3d.exec(styles.transform || ''); var childValues = regex.exec(provided.draggableProps.style.transform || ''); // if both the parent (the nested list) and the child (item beeing dragged) has transform values, recalculate the child items transform to account for position fixed not working if (childValues != null && parentValues != null) { var x = parseFloat(childValues[1], 10); var y = parseFloat(childValues[2], 10); var p_x = parseFloat(parentValues[1], 10); var p_y = parseFloat(parentValues[2], 10); var p_z = parseFloat(parentValues[3], 10); transform = "translate3d(".concat(x + p_x, "px, ").concat(y + p_y, "px, ").concat(p_z, "px)"); } _extends(providedProps, provided.draggableProps, provided.dragHandleProps); styles = _objectSpread({}, styles, { top: 'auto !important', left: 'auto !important', cursor: 'move', transform: transform }); } return React.createElement("div", _extends({}, providedProps, { role: "row" }, unhandledProps, { ref: rowRef, className: classes, style: styles }), children); }); } }]); return Row; }(React.PureComponent); Row.propTypes = propTypes; Row.defaultProps = { classPrefix: defaultClassPrefix('performance-table-row'), height: 46, headerHeight: 40 }; export default Row; //# sourceMappingURL=Row.js.map