UNPKG

office-ui-fabric-react

Version:

Reusable React components for building experiences for Office 365.

58 lines (56 loc) 2.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var React = require("react"); var Utilities_1 = require("../../Utilities"); var stylesImport = require("./DetailsRow.scss"); var styles = stylesImport; var INNER_PADDING = 16; // Account for padding around the cell. var DetailsRowFields = (function (_super) { tslib_1.__extends(DetailsRowFields, _super); function DetailsRowFields(props) { var _this = _super.call(this) || 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: Utilities_1.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: Utilities_1.css('ms-DetailsRow-cell', styles.cell, column.className, (_a = { 'is-multiline': column.isMultiline }, _a[styles.isMultiline] = column.isMultiline, _a)), style: { width: column.calculatedWidth + INNER_PADDING }, "data-automationid": 'DetailsRowCell', "data-automation-key": column.key }, cellContent[columnIndex])); var _a; }))); }; 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; }(Utilities_1.BaseComponent)); exports.DetailsRowFields = DetailsRowFields; //# sourceMappingURL=DetailsRowFields.js.map