UNPKG

@appbuckets/react-ui

Version:
76 lines (73 loc) 1.77 kB
import { __assign } from 'tslib'; import clsx from 'clsx'; import * as React from 'react'; import { useRxTable } from '../RxTable.context.js'; /* -------- * Component Definition * -------- */ var Cell = function (props) { var className = props.className, column = props.column, overrideContent = props.overrideContent, row = props.row, rowIndex = props.rowIndex; // ---- // Get Context Props // ---- var _a = useRxTable(), classes = _a.classes, BodyCell = _a.Components.BodyCell, getColumnWidth = _a.columns.getWidth, isVirtualized = _a.layout.isVirtualized, styles = _a.styles, tableData = _a.tableData; // ---- // Build Cell Classes // ---- var cellClasses = clsx( column.textAlign && 'has-text-'.concat(column.textAlign), className, column.className, classes.BodyCell ); // ---- // Get Column Width // ---- var columnWidth = React.useMemo( function () { return getColumnWidth(column.key); }, [getColumnWidth, column.key] ); // ---- // Prebuild BodyCell Props // ---- var bodyCellProps = { className: cellClasses, column: column, isVirtualized: isVirtualized, row: row, rowIndex: rowIndex, style: __assign(__assign({}, styles.BodyCell), { width: columnWidth, flexBasis: columnWidth, }), tableData: tableData, }; // ---- // If an overridden Content exists, use it to render the Cell // ---- if (overrideContent) { return React.createElement( BodyCell, __assign({}, bodyCellProps), overrideContent ); } // ---- // Render the Body Cell // ---- return React.createElement(BodyCell, __assign({}, bodyCellProps)); }; Cell.displayName = 'Cell'; export { Cell as default };