@itwin/itwinui-react
Version:
A react component library for iTwinUI
138 lines (137 loc) • 3.78 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', {
value: true,
});
function _export(target, all) {
for (var name in all)
Object.defineProperty(target, name, {
enumerable: true,
get: all[name],
});
}
_export(exports, {
DefaultCell: function () {
return DefaultCell;
},
DefaultCellContext: function () {
return DefaultCellContext;
},
});
const _interop_require_default = require('@swc/helpers/_/_interop_require_default');
const _interop_require_wildcard = require('@swc/helpers/_/_interop_require_wildcard');
const _react = /*#__PURE__*/ _interop_require_wildcard._(require('react'));
const _reacttable = require('react-table');
const _classnames = /*#__PURE__*/ _interop_require_default._(
require('classnames'),
);
const _index = require('../../../utils/index.js');
const _utils = require('../utils.js');
const DefaultCellContext = _react.createContext({});
const DefaultCell = (props) => {
let instance = _react.useContext(_utils.TableInstanceContext);
let isCustomCell = _react.useMemo(
() =>
instance?.columns.find(({ id }) => props.cellProps.column.id === id)
?.Cell !== _reacttable.defaultColumn.Cell,
[instance, props.cellProps.column.id],
);
let defaultCellContext = _react.useContext(DefaultCellContext);
let isCellRendererChildrenCustom =
defaultCellContext.children !== props.children;
let isDefaultTextCell =
'string' == typeof props.cellProps.value &&
!isCustomCell &&
!isCellRendererChildrenCustom;
let {
cellElementProps: {
className: cellElementClassName,
style: cellElementStyle,
...cellElementProps
},
children,
startIcon,
endIcon,
cellProps,
isDisabled,
className,
style,
status,
text = isDefaultTextCell ? cellProps.value : void 0,
clamp = !!text,
...rest
} = props;
let { key: cellElementKey, ...cellElementPropsRest } = cellElementProps;
let decorations = {
start: startIcon
? _react.createElement(
_index.Box,
{
className: 'iui-table-cell-start-icon',
key: `${cellElementKey}-start`,
},
startIcon,
)
: null,
end: endIcon
? _react.createElement(
_index.Box,
{
className: 'iui-table-cell-end-icon',
key: `${cellElementKey}-end`,
},
endIcon,
)
: null,
};
return _react.createElement(
_index.Box,
{
...cellElementPropsRest,
key: cellElementKey,
...rest,
className: (0, _classnames.default)(cellElementClassName, className),
'aria-disabled': isDisabled?.(cellProps.row.original) || void 0,
'data-iui-status': status,
style: {
...cellElementStyle,
...style,
},
},
(() => {
if (text)
return _react.createElement(
_react.Fragment,
null,
decorations.start,
defaultCellContext.expander,
_react.createElement(
_index.Box,
{
className: 'iui-table-cell-default-content',
onClick: (e) => e.stopPropagation(),
},
clamp
? _react.createElement(
_index.Box,
{
className: 'iui-line-clamp',
},
text,
)
: text,
),
decorations.end,
defaultCellContext.shadows,
);
return _react.createElement(
_react.Fragment,
null,
decorations.start,
children,
decorations.end,
);
})(),
);
};
if ('development' === process.env.NODE_ENV)
DefaultCell.displayName = 'DefaultCell';