@appbuckets/react-ui
Version:
Just Another React UI Framework
171 lines (165 loc) • 4.24 kB
JavaScript
'use strict';
var React = require('react');
var reactUiCore = require('@appbuckets/react-ui-core');
var useCellElementContent = require('../lib/useCellElementContent.js');
var TableCell = require('../../Table/TableCell.js');
var TableCellContent = require('../../Table/TableCellContent.js');
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);
/* --------
* Component Definition
* -------- */
var RxTableBodyCell = function (props) {
var children = props.children,
className = props.className,
column = props.column,
isVirtualized = props.isVirtualized,
tableData = props.tableData,
rowIndex = props.rowIndex,
row = props.row,
style = props.style;
var Content = column.Content,
render = column.render,
cell = column.cell,
key = column.key;
// ----
// Memoize Cell Element Content
// ----
var metaContent = useCellElementContent(
cell === null || cell === void 0 ? void 0 : cell.meta,
row,
rowIndex,
tableData
);
var headerContent = useCellElementContent(
cell === null || cell === void 0 ? void 0 : cell.header,
row,
rowIndex,
tableData
);
var contentContent = useCellElementContent(
cell === null || cell === void 0 ? void 0 : cell.content,
row,
rowIndex,
tableData
);
var renderedContent = useCellElementContent(render, row, rowIndex, tableData);
// ----
// Build the Wrapper
// ----
var Wrapper = React__namespace.useCallback(
function (_a) {
var wrapperChildren = _a.children;
if (!isVirtualized) {
return React__namespace.createElement(
TableCell,
{ className: className, style: style },
wrapperChildren
);
}
return React__namespace.createElement(
'div',
{ className: className, style: style },
React__namespace.createElement(
'div',
{ className: 'virtualized cell-content' },
wrapperChildren
)
);
},
[isVirtualized, className, style]
);
// ----
// Render Children if they are declared
// ----
if (!reactUiCore.childrenUtils.isNil(children)) {
return React__namespace.createElement(Wrapper, null, children);
}
// ----
// If Content Component has been declared, use it
// ----
if (Content) {
return React__namespace.createElement(
Wrapper,
null,
React__namespace.createElement(Content, {
column: column,
data: tableData,
rowIndex: rowIndex,
row: row,
})
);
}
// ----
// If a render function has been declared, use it
// ----
if (typeof render === 'function') {
return React__namespace.createElement(Wrapper, null, renderedContent);
}
// ----
// Render the Content using Shorthand
// ----
if (cell) {
return React__namespace.createElement(
Wrapper,
null,
TableCellContent.create(metaContent, {
autoGenerateKey: false,
overrideProps: {
type: 'meta',
},
}),
TableCellContent.create(headerContent, {
autoGenerateKey: false,
overrideProps: {
type: 'title',
},
}),
TableCellContent.create(contentContent, {
autoGenerateKey: false,
overrideProps: {
type: 'content',
},
})
);
}
// ----
// Render the Content using column key
// ----
return React__namespace.createElement(
Wrapper,
null,
TableCellContent.create(row[key] || '', {
autoGenerateKey: false,
overrideProps: {
type: 'title',
},
})
);
};
RxTableBodyCell.displayName = 'RxTableBodyCell';
module.exports = RxTableBodyCell;