@appbuckets/react-ui
Version:
Just Another React UI Framework
124 lines (117 loc) • 3.22 kB
JavaScript
;
var tslib = require('tslib');
var React = require('react');
var clsx = require('clsx');
var RxTable_context = require('../RxTable.context.js');
var Cell = require('../atoms/Cell.js');
var SingleRowSelector = require('../atoms/SingleRowSelector.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 React__namespace = /*#__PURE__*/ _interopNamespace(React);
var clsx__default = /*#__PURE__*/ _interopDefaultLegacy(clsx);
/* --------
* Component Definition
* -------- */
var BodyRow = function (props) {
/** Extract row index from props */
var index = props.index,
style = props.style;
// ----
// Get Context Props
// ----
var _a = RxTable_context.useRxTable(),
classes = _a.classes,
columns = _a.columns,
BodyRowComponent = _a.Components.BodyRow,
isVirtualized = _a.layout.isVirtualized,
tableData = _a.tableData,
_b = _a.interaction,
isRowClickEnabled = _b.isRowClickEnabled,
superHandleRowClick = _b.handleRowClick,
_c = _a.selection,
isDataSelectable = _c.enabled,
isRowSelected = _c.isRowSelected,
styles = _a.styles;
// ----
// Extract Data from Array
// ----
var row = tableData[index];
// ----
// Build Default row Class
// ----
var bodyRowClasses = clsx__default['default'](
{
last: index === tableData.length - 1,
first: index === 0,
clickable: isRowClickEnabled,
selected: isRowSelected(row),
},
classes.BodyRow
);
// ----
// Handlers
// ----
var handleRowClick = React__namespace.useCallback(
function () {
superHandleRowClick(index);
},
[superHandleRowClick, index]
);
// ----
// Render the Row
// ----
return React__namespace.createElement(
BodyRowComponent,
{
className: bodyRowClasses,
columns: columns.current,
onClick: isRowClickEnabled ? handleRowClick : undefined,
isVirtualized: isVirtualized,
rowIndex: index,
row: row,
style: tslib.__assign(tslib.__assign({}, style), styles.BodyRow),
},
columns.current.map(function (column, columnIndex) {
return React__namespace.createElement(Cell, {
key: column.key,
className:
isDataSelectable && columnIndex === 0 ? 'selector' : undefined,
column: column,
row: row,
rowIndex: index,
overrideContent:
isDataSelectable && columnIndex === 0
? React__namespace.createElement(SingleRowSelector, { row: row })
: undefined,
});
})
);
};
BodyRow.displayName = 'BodyRow';
module.exports = BodyRow;