choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
113 lines (94 loc) • 4.56 kB
JavaScript
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 _createSuper from "@babel/runtime/helpers/createSuper";
var _excluded = ["className", "width", "height", "top", "style", "isHeaderRow", "headerHeight", "rowRef", "classPrefix", "children", "rowDraggable", "provided", "snapshot"];
// @ts-nocheck
import * as React from 'react';
import classNames from 'classnames';
import { defaultClassPrefix, getUnhandledProps, prefix } from './utils';
import TableContext from './TableContext';
var propTypeKeys = ['width', 'height', 'headerHeight', 'top', 'isHeaderRow', 'rowDraggable', 'rowRef', 'className', 'classPrefix', 'style', 'provided', 'snapshot'];
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, _excluded);
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(propTypeKeys, rest);
return /*#__PURE__*/React.createElement(TableContext.Consumer, null, function (_ref) {
var translateDOMPositionXY = _ref.translateDOMPositionXY;
if (translateDOMPositionXY) {
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(_objectSpread({}, styles), {}, {
top: 'auto !important',
left: 'auto !important',
cursor: 'move',
transform: transform
});
}
return /*#__PURE__*/React.createElement("div", _extends({}, providedProps, {
role: "row"
}, unhandledProps, {
ref: rowRef,
className: classes,
style: styles
}), children);
});
}
}]);
return Row;
}(React.PureComponent);
Row.defaultProps = {
classPrefix: defaultClassPrefix('performance-table-row'),
height: 46,
headerHeight: 40
};
export default Row;
//# sourceMappingURL=Row.js.map