@appbuckets/react-ui
Version:
Just Another React UI Framework
114 lines (107 loc) • 2.69 kB
JavaScript
;
var tslib = require('tslib');
var clsx = require('clsx');
var React = require('react');
var RxTable_context = require('../RxTable.context.js');
function _interopDefaultLegacy(e) {
return e && typeof e === 'object' && 'default' in e ? e : { default: e };
}
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(
n,
k,
d.get
? d
: {
enumerable: true,
get: function () {
return e[k];
},
}
);
}
});
}
n['default'] = e;
return Object.freeze(n);
}
var clsx__default = /*#__PURE__*/ _interopDefaultLegacy(clsx);
var React__namespace = /*#__PURE__*/ _interopNamespace(React);
/* --------
* 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 = RxTable_context.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__default['default'](
column.textAlign && 'has-text-'.concat(column.textAlign),
className,
column.className,
classes.BodyCell
);
// ----
// Get Column Width
// ----
var columnWidth = React__namespace.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: tslib.__assign(tslib.__assign({}, styles.BodyCell), {
width: columnWidth,
flexBasis: columnWidth,
}),
tableData: tableData,
};
// ----
// If an overridden Content exists, use it to render the Cell
// ----
if (overrideContent) {
return React__namespace.createElement(
BodyCell,
tslib.__assign({}, bodyCellProps),
overrideContent
);
}
// ----
// Render the Body Cell
// ----
return React__namespace.createElement(
BodyCell,
tslib.__assign({}, bodyCellProps)
);
};
Cell.displayName = 'Cell';
module.exports = Cell;