linkmore-design
Version:
π πlmη»δ»ΆεΊγπ
45 lines β’ 2.33 kB
JavaScript
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["children"];
import React, { useEffect, useMemo } from 'react';
import { useStore } from "./context";
var VirtualWrapper = /*#__PURE__*/React.memo(function (wrapperProps) {
var _virtualItems$, _virtualItems;
var children = wrapperProps.children,
resetProps = _objectWithoutProperties(wrapperProps, _excluded);
var _useStore = useStore(),
state = _useStore.state,
dispatch = _useStore.dispatch,
instance = _useStore.instance;
var _instance$rowVirtual = instance.rowVirtual,
virtualItems = _instance$rowVirtual.virtualItems,
totalSize = _instance$rowVirtual.totalSize;
var contents = useMemo(function () {
return children[1];
}, [children]);
var contentsLen = useMemo(function () {
var _contents$length;
return (_contents$length = contents === null || contents === void 0 ? void 0 : contents.length) !== null && _contents$length !== void 0 ? _contents$length : 0;
}, [contents]);
useEffect(function () {
if (state.totalLen !== contentsLen) {
dispatch({
type: 'changeTotalLen',
totalLen: contentsLen !== null && contentsLen !== void 0 ? contentsLen : 0
});
}
}, [contentsLen, dispatch, state.totalLen]);
var paddingTop = virtualItems.length > 0 ? (virtualItems === null || virtualItems === void 0 ? void 0 : (_virtualItems$ = virtualItems[0]) === null || _virtualItems$ === void 0 ? void 0 : _virtualItems$.start) || 0 : 0;
var paddingBottom = virtualItems.length > 0 ? totalSize - ((virtualItems === null || virtualItems === void 0 ? void 0 : (_virtualItems = virtualItems[virtualItems.length - 1]) === null || _virtualItems === void 0 ? void 0 : _virtualItems.end) || 0) : 0;
return /*#__PURE__*/React.createElement("tbody", resetProps, paddingTop > 0 && /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("td", {
style: {
height: "".concat(paddingTop, "px")
}
})), children[0], virtualItems.map(function (virtualRow) {
return contents[virtualRow.index];
}), paddingBottom > 0 && /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("td", {
style: {
height: "".concat(paddingBottom, "px")
}
})));
});
export default VirtualWrapper;