@talend/react-components
Version:
Set of react components.
71 lines (70 loc) • 2.76 kB
JavaScript
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { Component } from 'react';
import { AutoSizer, CellMeasurerCache, List } from 'react-virtualized';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import TreeCellMeasurer from '../TreeCellMeasurer';
import theme from './VirtualizedTree.module.scss';
import { jsx as _jsx } from "react/jsx-runtime";
const DEFAULT_HEIGHT = 40;
/**
* Help to use react-virtualized.
*/
export default class VirtualizedTree extends Component {
constructor(..._args) {
super(..._args);
_defineProperty(this, "lazyLoadingCallBack", ({
startIndex,
stopIndex
}) => {
if (this.props.onVerticalScroll) {
this.props.onVerticalScroll({}, {
firstDisplayedRowIndex: startIndex,
lastDisplayedRowIndex: stopIndex
});
}
});
_defineProperty(this, "renderTreeCellMeasurer", args => /*#__PURE__*/_jsx(TreeCellMeasurer, {
...args,
className: this.props.cellMeasurerClassName,
cellRenderer: this.props.cellRenderer
}));
}
render() {
const cache = new CellMeasurerCache({
fixedWidth: true,
defaultHeight: DEFAULT_HEIGHT
});
return /*#__PURE__*/_jsx("div", {
className: classNames(theme['tc-virtualized-tree'], 'tc-virtualized-tree', this.props.className),
children: /*#__PURE__*/_jsx(AutoSizer, {
disableHeight: this.props.disableHeight,
children: ({
height,
width
}) => /*#__PURE__*/_jsx(List, {
...this.props,
cache: cache,
deferredMeasurementCache: cache,
height: height,
onRowsRendered: this.lazyLoadingCallBack,
rowCount: this.props.rowCount,
rowHeight: cache.rowHeight,
rowRenderer: this.renderTreeCellMeasurer,
width: width
})
})
});
}
}
_defineProperty(VirtualizedTree, "propTypes", {
cellRenderer: PropTypes.func.isRequired,
className: PropTypes.string,
onVerticalScroll: PropTypes.func,
rowCount: PropTypes.number,
cellMeasurerClassName: PropTypes.string,
disableHeight: PropTypes.bool
});
//# sourceMappingURL=VirtualizedTree.component.js.map