@talend/react-components
Version:
Set of react components.
107 lines (104 loc) • 3.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.insertSelectionConfiguration = insertSelectionConfiguration;
exports.toColumns = toColumns;
var _react = require("react");
var _classnames = _interopRequireDefault(require("classnames"));
var _reactVirtualized = require("react-virtualized");
var _CellCheckbox = _interopRequireDefault(require("../CellCheckbox"));
var _HeaderCheckbox = _interopRequireDefault(require("../HeaderCheckbox"));
var _resizable = require("./resizable");
var _constants = require("./constants");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
* This file contains all utility functions that applies to table
*/
/**
* Insert a checkbox column configuration to select a row.
*/
function insertSelectionConfiguration(props) {
const {
collection,
children,
getRowState,
isSelected,
isToggleAllDisabled,
onToggleAll,
selectionMode,
selectionToggle
} = props;
let contentsConfiguration = _react.Children.toArray(children);
if (selectionToggle && isSelected) {
const toggleColumn = /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactVirtualized.Column, {
id: _constants.internalIds.rowSelector,
label: "",
dataKey: "",
disableSort: true,
width: 35,
flexShrink: 0,
flexGrow: 0,
cellDataGetter: ({
rowData
}) => isSelected(rowData),
columnData: {
collection,
getRowState,
isSelected,
isToggleAllDisabled,
label: 'Select this element',
onChange: selectionToggle,
onToggleAll,
selectionMode
},
..._CellCheckbox.default,
..._HeaderCheckbox.default
});
contentsConfiguration = [toggleColumn].concat(contentsConfiguration);
} else if (process.env.NODE_ENV !== 'production' && selectionToggle || isSelected) {
console.warn('VirtualizedList : props.selectionToggle goes with props.isSelected. You defined only one of those props, selection is ignored.');
}
return contentsConfiguration;
}
/**
* Create new Columns from children, enhanced with
* - header and row fixed classnames
* - parent id (via columnData)
*/
function toColumns({
id,
theme,
children,
columnsWidths,
getRowState
}) {
return _react.Children.toArray(children).map((field, index) => {
const columnWidth = (0, _resizable.getColumnWidth)(field.props.dataKey, columnsWidths);
const colClassName = `tc-list-cell-${field.props.dataKey}`;
const colProps = {
// ...createColumnWidthProps(columnWidth),
width: -1,
...field.props,
headerClassName: (0, _classnames.default)(field.props.headerClassName, theme.header, colClassName, {
'tc-header-resizable': columnWidth && columnWidth.resizable
}),
className: (0, _classnames.default)(field.props.className, theme.cell, colClassName),
columnData: typeof field.props.columnData === 'function' ? rowData => ({
...field.props.columnData(rowData),
getRowState,
id
}) : {
...field.props.columnData,
getRowState,
id
},
...(0, _resizable.createColumnWidthProps)(columnWidth)
};
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactVirtualized.Column, {
...colProps
}, index);
});
}
//# sourceMappingURL=tablerow.js.map