@atlaskit/renderer
Version:
Renderer component
84 lines • 3.98 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
import React from 'react';
import { compose } from '@atlaskit/editor-common/utils';
import { SortOrder } from '@atlaskit/editor-common/types';
import { RendererCssClassName } from '../../consts';
// Ignored via go/ees005
// eslint-disable-next-line @repo/internal/react/no-class-components
var TableRow = /*#__PURE__*/function (_React$Component) {
function TableRow() {
var _this;
_classCallCheck(this, TableRow);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _callSuper(this, TableRow, [].concat(args));
_defineProperty(_this, "state", {
colGroupWidths: []
});
_defineProperty(_this, "addSortableColumn", function (childrenArray) {
var _this$props = _this.props,
allowColumnSorting = _this$props.allowColumnSorting,
rowIndex = _this$props.index;
var isHeaderRow = !rowIndex;
if (allowColumnSorting && isHeaderRow) {
childrenArray = childrenArray.map(function (child, index) {
if ( /*#__PURE__*/React.isValidElement(child)) {
var tableOrderStatus = _this.props.tableOrderStatus;
var sortOrdered = SortOrder.NO_ORDER;
if (tableOrderStatus) {
sortOrdered = index === tableOrderStatus.columnIndex ? tableOrderStatus.order : SortOrder.NO_ORDER;
}
return /*#__PURE__*/React.cloneElement(child, {
columnIndex: index,
onSorting: _this.props.onSorting,
sortOrdered: sortOrdered,
isHeaderRow: isHeaderRow
});
}
});
}
return childrenArray;
});
_defineProperty(_this, "addColGroupWidth", function (childrenArray) {
var _this$state$colGroupW;
if ((_this$state$colGroupW = _this.state.colGroupWidths) !== null && _this$state$colGroupW !== void 0 && _this$state$colGroupW.length) {
childrenArray = childrenArray.map(function (child, index) {
if ( /*#__PURE__*/React.isValidElement(child)) {
return /*#__PURE__*/React.cloneElement(child, {
colGroupWidth: _this.state.colGroupWidths[index]
});
}
});
}
return childrenArray;
});
return _this;
}
_inherits(TableRow, _React$Component);
return _createClass(TableRow, [{
key: "render",
value: function render() {
var _this$props2 = this.props,
children = _this$props2.children,
innerRef = _this$props2.innerRef;
var childrenArray = React.Children.toArray(children);
return /*#__PURE__*/React.createElement("tr", {
ref: innerRef
}, this.props.isNumberColumnEnabled &&
/*#__PURE__*/
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
React.createElement("td", {
className: RendererCssClassName.NUMBER_COLUMN
}, this.props.index), compose(this.addSortableColumn, this.addColGroupWidth)(childrenArray));
}
}]);
}(React.Component);
export { TableRow as default };