office-ui-fabric-react
Version:
Reusable React components for building experiences for Office 365.
48 lines • 2.78 kB
JavaScript
import * as tslib_1 from "tslib";
import * as React from 'react';
import { BaseComponent, css } from '../../Utilities';
import * as stylesImport from './DetailsRow.scss';
var styles = stylesImport;
var INNER_PADDING = 16; // Account for padding around the cell.
var ISPADDED_WIDTH = 24;
var DetailsRowFields = /** @class */ (function (_super) {
tslib_1.__extends(DetailsRowFields, _super);
function DetailsRowFields(props) {
var _this = _super.call(this, props) || this;
_this.state = _this._getState(props);
return _this;
}
DetailsRowFields.prototype.componentWillReceiveProps = function (newProps) {
this.setState(this._getState(newProps));
};
DetailsRowFields.prototype.render = function () {
var _a = this.props, columns = _a.columns, columnStartIndex = _a.columnStartIndex;
var cellContent = this.state.cellContent;
return (React.createElement("div", { className: css('ms-DetailsRow-fields', styles.fields), "data-automationid": 'DetailsRowFields', role: 'presentation' }, columns.map(function (column, columnIndex) { return (React.createElement("div", { key: columnIndex, role: column.isRowHeader ? 'rowheader' : 'gridcell', "aria-colindex": columnIndex + columnStartIndex, className: css('ms-DetailsRow-cell', styles.cell, column.className, column.isMultiline && 'is-multiline', column.isRowHeader && styles.isRowHeader, column.isPadded && styles.isPadded, column.isMultiline && styles.isMultiline), style: { width: column.calculatedWidth + INNER_PADDING + (column.isPadded ? ISPADDED_WIDTH : 0) }, "data-automationid": 'DetailsRowCell', "data-automation-key": column.key }, cellContent[columnIndex])); })));
};
DetailsRowFields.prototype._getState = function (props) {
var _this = this;
var item = props.item, itemIndex = props.itemIndex, onRenderItemColumn = props.onRenderItemColumn;
return {
cellContent: props.columns.map(function (column) {
var cellContent;
try {
var render = column.onRender || onRenderItemColumn;
cellContent = render ? render(item, itemIndex, column) : _this._getCellText(item, column);
}
catch (e) { }
return cellContent;
})
};
};
DetailsRowFields.prototype._getCellText = function (item, column) {
var value = (item && column && column.fieldName) ? item[column.fieldName] : '';
if (value === null || value === undefined) {
value = '';
}
return value;
};
return DetailsRowFields;
}(BaseComponent));
export { DetailsRowFields };
//# sourceMappingURL=DetailsRowFields.js.map