
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
react-virtualized-sticky-tree
Advanced tools
A React component for efficiently rendering tree like structures with support for position: sticky
A React component for efficiently rendering tree like structures with support for position: sticky. react-virtualized-sticky-tree
uses a similar API to react-virtualized.
https://marchaos.github.io/react-virtualized-sticky-tree/
npm install react-virtualized-sticky-tree --save
import StickyTree from 'react-virtualized-sticky-tree';
const tree = {
root: { name: 'Root', children: ['child1', 'child2', 'child3'], depth: 0 },
child1: { name: 'Child 1', children: ['child4'], depth: 1 },
child2: { name: 'Child 2', depth: 2 },
child3: { name: 'Child 3', depth: 2 },
child4: { name: 'Child 4', depth: 3 },
};
const getChildren = (id) => {
return tree[id].children.map(id => ({ id }));
};
const rowRenderer = ({ id, style }) => {
const node = tree[id];
return <div style={style}>{node.name}</div>
};
const getHeight = () => 30;
render(
<StickyTree
root={{ id: 'root' }}
width={width}
height={height}
getChildren={getChildren}
getHeight={getHeight}
rowRenderer={rowRenderer}
renderRoot={true}
overscanRowCount={20}
/>
);
StickyTree renders the component within a nested structure so that the header's position may be 'stuck' at different levels (see demo). When passing the root node or items in the children array, specifying isSticky: true will make the item sticky.
Every nested sticky level should have a top which is at the bottom of the sticky level above it. For example. If your root node is 30px high and has a top of 0, the next sticky node should have a top of 30px. The z-index of the node should also be lower than the nodes above it (so that it is scrolled out of view underneath its parent node). If your root node is z-index 4, then the node below could be 3, below that 2 and so on.
An implementation of this would look like:
const getChildren = (id) => {
if (shouldBeSticky(id)) {
return tree[id].children.map(childId => ({
id: childId,
isSticky: true,
stickyTop: 10,
zIndex: 2,
height: 10
}))
}
return tree[id].children.map(childId => ({ id: childId, isSticky: false, height: 10 }))
};
/**
* Here, style will include the styles to make the node sticky in the right position.
*/
const rowRenderer = ({ id, style }) => {
return <div className="row" style={style}>{mytree[id].name}</div>;
};
Be sure to pass a sticky root node to StickyTree if it should be sticky
<StickyTree
className="treee"
root={{ id: 'root', isSticky: true, stickyTop: 0, zIndex: 3, height: 10 }}
rowRenderer={rowRenderer}
getChildren={getChildren}
/>
If the containing element of your tree has a dynamic height, you can use react-measure to provide the width and height to sticky-tree so that it can resize to the available width.
For Simplicity, [react-virtualized-sticky-tree] includes a component which uses react-measure to acieve this:
import { AutoSizedStickyTree } from 'react-virtualized-sticky-tree';
<AutoSizedStickyTree
className="tree"
root={{ id: 'root', isSticky: true, stickyTop: 0, zIndex: 300, height: PARENT_NODE_HEIGHT }}
rowRenderer={rowRenderer}
getChildren={getChildren}
...
/>
If you want to do this yourself, you can install react-measure:
npm install react-measure --save
as a HOC:
const MeasuredTree = withContentRect('bounds')(({ measureRef, measure, contentRect }) => (
<div ref={measureRef} className="sticky-wrapper">
<StickyTree
root="root"
getChildren={getChildren}
getHeight={getHeight}
rowRenderer={rowRenderer}
renderRoot={true}
width={contentRect.bounds.width}
height={contentRect.bounds.height}
overscanRowCount={20}
/>
</div>
));
or within render()
<Measure
bounds={true}
onResize={(contentRect) => {this.setState({ dimensions: contentRect.bounds });}}
>
{({ measureRef }) =>
<div ref={measureRef} className="sticky-tree-wrapper">
<StickyTree
width={this.state.dimensions.width}
height={this.state.dimensions.height}
root={0}
renderRoot={true}
rowRenderer={this.rowRenderer}
getChildren={this.getChildren}
getHeight={() => 30}
overscanRowCount={20}
/>
</div>
}
</Measure>
Rendering tree structures is supported in all modern browsers. position: sticky has only been tested in Chrome 59 and Firefox 54, but should work in Edge, Safari and Opera. See http://caniuse.com/#search=position%3Asticky
FAQs
A React component for efficiently rendering tree like structures with support for position: sticky
The npm package react-virtualized-sticky-tree receives a total of 994 weekly downloads. As such, react-virtualized-sticky-tree popularity was classified as not popular.
We found that react-virtualized-sticky-tree demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.