@sap-ux/ui-components
Version:
SAP UI Components Library
105 lines • 4.05 kB
JavaScript
import React from 'react';
import { UIFlexibleTableLayout } from './types.js';
import { composeClassNames } from './utils.js';
/**
* Get cell title element.
*
* @param {UIFlexibleTableProps<T>} tableProps
* @param {React.ReactNode} title
* @param {boolean} inRowLayout
* @param {string} tooltip
* @returns {React.ReactNode}
*/
function getCellTitleElement(tableProps, title, inRowLayout, tooltip) {
const wrappingLayout = tableProps.layout === UIFlexibleTableLayout.Wrapping;
const isFlexContent = wrappingLayout || !inRowLayout || tableProps.showColumnTitlesInCells;
if (tableProps.showColumnTitles && isFlexContent) {
return (React.createElement("div", { className: "flexible-table-content-table-row-item-title", title: tooltip }, title));
}
else {
return React.createElement(React.Fragment, null);
}
}
/**
* Gets row data cells.
*
* @param {RowDataCellsProps<T>} props
* @returns {Array<React.ReactNode>}
*/
function getRowDataCells(props) {
const { isInRowLayout, row, rowIndex, tableProps } = props;
const result = [];
for (let i = 0; i < tableProps.columns.length; i++) {
const column = tableProps.columns[i];
if (column.hidden) {
continue;
}
const colKey = column.key;
const { content, isSpan, cellClassNames, title, tooltip } = tableProps.onRenderCell({
cells: row.cells,
colIndex: i,
colKey,
readonly: !!tableProps.readonly,
rowIndex,
rowKey: row.key,
value: row.cells[colKey],
isInRowLayout
});
if (tableProps.layout === UIFlexibleTableLayout.InlineFlex || content) {
const classNameStr = composeClassNames('flexible-table-content-table-row-item-data-cells-wrapper', [
cellClassNames,
column.className
]);
const cellId = `cell-${colKey}`;
result.push(React.createElement("div", { key: isSpan ? `cell-unknown` : `cell-${colKey}-${i}`, className: classNameStr, id: cellId },
getCellTitleElement(tableProps, title || column.title, isInRowLayout, tooltip || column.tooltip),
React.createElement("div", { className: "flexible-table-content-table-row-item-data-cells-value" }, content)));
}
if (isSpan) {
break;
}
}
return result;
}
/**
* RowDataCells component.
*
* @param {RowDataCellsProps<T>} props
* @returns {React.ReactElement}
*/
export function RowDataCells(props) {
const { isInRowLayout, row, rowIndex, tableProps } = props;
const rowCells = [];
const rowCellsData = [];
let alternativeContent;
if (tableProps.onRenderRowDataContent) {
alternativeContent = tableProps.onRenderRowDataContent({
cells: row.cells,
readonly: !!tableProps.readonly,
rowIndex,
rowKey: row.key
});
}
if (tableProps.showIndexColumn) {
// Add index cell
rowCells.push(React.createElement("div", { key: `cell-index-${rowIndex}`, className: "flexible-table-content-table-row-item-index" },
React.createElement("span", { className: "flexible-table-content-table-row-item-index-value" }, row.key)));
}
if (!alternativeContent) {
rowCellsData.push(...getRowDataCells(props));
}
else {
rowCellsData.push(alternativeContent);
}
// Add data cells
const classNames = ['flexible-table-content-table-row-item-data-cells'];
if (tableProps.layout === UIFlexibleTableLayout.Wrapping) {
classNames.push('dynamic');
}
else {
classNames.push(isInRowLayout ? 'in-row' : 'in-column');
}
rowCells.push(React.createElement("div", { key: `flexible-table-content-table-row-item-${rowIndex}`, className: classNames.join(' ') }, rowCellsData));
return React.createElement("div", { className: "flexible-table-content-table-row-item-wrapper" }, rowCells);
}
//# sourceMappingURL=RowData.js.map