@atlaskit/renderer
Version:
Renderer component
70 lines • 2.6 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
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
export default class TableRow extends React.Component {
constructor(...args) {
super(...args);
_defineProperty(this, "state", {
colGroupWidths: []
});
_defineProperty(this, "addSortableColumn", childrenArray => {
const {
allowColumnSorting,
index: rowIndex
} = this.props;
const isHeaderRow = !rowIndex;
if (allowColumnSorting && isHeaderRow) {
childrenArray = childrenArray.map((child, index) => {
if ( /*#__PURE__*/React.isValidElement(child)) {
const {
tableOrderStatus
} = this.props;
let 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,
isHeaderRow
});
}
});
}
return childrenArray;
});
_defineProperty(this, "addColGroupWidth", 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((child, index) => {
if ( /*#__PURE__*/React.isValidElement(child)) {
return /*#__PURE__*/React.cloneElement(child, {
colGroupWidth: this.state.colGroupWidths[index]
});
}
});
}
return childrenArray;
});
}
render() {
const {
children,
innerRef
} = this.props;
const 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));
}
}