UNPKG

react-virtualized-sticky-tree

Version:

A React component for efficiently rendering tree like structures with support for position: sticky

21 lines (20 loc) 1.12 kB
import React, { useCallback, useMemo } from 'react'; import StickyTree from './StickyTree.js'; const StickyList = ({ items, rowRenderer, width, height, treeRef, getRowHeight, wrapAllLeafNodes = false, ...rest }) => { const root = useMemo(() => ({ node: { id: 'root' }, height: 0 }), []); const getChildren = useCallback((node) => { if (node.id === 'root') { return items.map((item) => ({ node: item, // If they don't specify a getHeight function, they must be using either a height on the node or the rowHeight prop to StickyList. height: getRowHeight ? getRowHeight(item) : item.height, isSticky: item.isSticky, stickyTop: item.stickyTop, zIndex: item.zIndex, })); } return undefined; }, [items, getRowHeight]); return (React.createElement(StickyTree, { ref: treeRef, getChildren: getChildren, renderRoot: false, wrapAllLeafNodes: wrapAllLeafNodes, root: root, rowRenderer: rowRenderer, width: width, height: height, ...rest })); }; export default StickyList;