All Projects → marchaos → React Virtualized Sticky Tree

marchaos / React Virtualized Sticky Tree

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

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Virtualized Sticky Tree

flutter sticky and expandable list
粘性头部与分组列表Sliver实现 Build a grouped list, which support expand/collapse section and sticky headers, support use it with sliver widget.
Stars: ✭ 116 (+0.87%)
Mutual labels:  sticky, sticky-headers
Consecutivescroller
ConsecutiveScrollerLayout是Android下支持多个滑动布局(RecyclerView、WebView、ScrollView等)和普通控件(TextView、ImageView、LinearLayou、自定义View等)持续连贯滑动的容器,它使所有的子View像一个整体一样连续顺畅滑动。并且支持布局吸顶功能。
Stars: ✭ 1,383 (+1102.61%)
Mutual labels:  sticky, sticky-headers
Ng Sticky
Angular 4 sticky, have header or any component sticky easy to use.
Stars: ✭ 25 (-78.26%)
Mutual labels:  sticky, sticky-headers
Flutter sticky infinite list
Multi directional infinite list with Sticky headers for Flutter applications
Stars: ✭ 189 (+64.35%)
Mutual labels:  sticky, sticky-headers
Android-sticky-navigation-layout
android sticky navigation layout
Stars: ✭ 17 (-85.22%)
Mutual labels:  sticky, sticky-headers
indexed-string-variation
Experimental JavaScript module to generate all possible variations of strings over an alphabet using an n-ary virtual tree
Stars: ✭ 16 (-86.09%)
Mutual labels:  tree, virtual
Floatthead
Fixed <thead>. Doesn't need any custom css/html. Does what position:sticky can't
Stars: ✭ 1,193 (+937.39%)
Mutual labels:  sticky, sticky-headers
Tree Node Cli
🌲 Node.js library to list the contents of directories in a tree-like format, similar to the Linux tree command
Stars: ✭ 102 (-11.3%)
Mutual labels:  tree
Chaid
A python implementation of the common CHAID algorithm
Stars: ✭ 108 (-6.09%)
Mutual labels:  tree
React Demo Storybook
create-react-app , story
Stars: ✭ 100 (-13.04%)
Mutual labels:  tree
Suffixtree
A Java implementation of a Generalized Suffix Tree using Ukkonen's algorithm
Stars: ✭ 96 (-16.52%)
Mutual labels:  tree
Owl Bt
owl-bt is editor for Behavior trees. It has been inspired by Unreal engine behavior trees in a way, that it supports special node items like decorators and services. This makes trees smaller and much more readable.
Stars: ✭ 112 (-2.61%)
Mutual labels:  tree
Aura Operating System
AuraOS, the Franco-English Operating System developed in C# using Cosmos!
Stars: ✭ 111 (-3.48%)
Mutual labels:  virtual
Gods
GoDS (Go Data Structures). Containers (Sets, Lists, Stacks, Maps, Trees), Sets (HashSet, TreeSet, LinkedHashSet), Lists (ArrayList, SinglyLinkedList, DoublyLinkedList), Stacks (LinkedListStack, ArrayStack), Maps (HashMap, TreeMap, HashBidiMap, TreeBidiMap, LinkedHashMap), Trees (RedBlackTree, AVLTree, BTree, BinaryHeap), Comparators, Iterators, …
Stars: ✭ 10,883 (+9363.48%)
Mutual labels:  tree
Json Git
A pure JS local Git to versionize any JSON
Stars: ✭ 109 (-5.22%)
Mutual labels:  tree
Vue Drag Tree
基于Vue的拖拽组织树
Stars: ✭ 98 (-14.78%)
Mutual labels:  tree
Poweradapter
Adapter for RecyclerView(only 21KB).RecyclerView万能适配器(仅21KB)
Stars: ✭ 112 (-2.61%)
Mutual labels:  sticky-headers
React Virtuoso
The most powerful virtual list component for React
Stars: ✭ 1,347 (+1071.3%)
Mutual labels:  virtual
Improved Sapling Tree Generator
A new version of Blenders sapling tree generator addon with improvements, new features, and bug fixes
Stars: ✭ 107 (-6.96%)
Mutual labels:  tree
Butterfly
🦋Butterfly,A JavaScript/React/Vue2 Diagramming library which concentrate on flow layout field. (基于JavaScript/React/Vue2的流程图组件)
Stars: ✭ 2,343 (+1937.39%)
Mutual labels:  tree

react-virtualized-sticky-tree

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.

Demo

https://marchaos.github.io/react-virtualized-sticky-tree/

Getting Started

npm install react-virtualized-sticky-tree --save

Usage

Basic Example

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) => {
  if (tree[id].children) {
    return tree[id].children.map(id => ({ id, height: 30, isSticky: true }));
  }
};

const rowRenderer = ({ id, style }) => {
  const node = tree[id];
  return <div style={style}>{node.name}</div>
};

render() {
  return (
      <StickyTree
        root={{ id: 'root', height: 30 }}
        width={width}
        height={height}
        getChildren={getChildren}
        rowRenderer={rowRenderer}
        renderRoot={true}
        overscanRowCount={20}
      />
  );
)

Nested Sticky Header Styles

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: tree[childId].depth * 10,
         zIndex: 30 - tree[childId].depth, 
         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}
/>

Dynamic Height Container

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 achieve this:

import { AutoSizedStickyTree } from 'react-virtualized-sticky-tree';

<AutoSizedStickyTree
    className="tree"
    root={{ id: 'root', isSticky: true, stickyTop: 0, zIndex: 3, height: 30 }}
    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={{id: 0}}
      getChildren={getChildren}
      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={{id: 0 }}
                  renderRoot={true}
                  rowRenderer={this.rowRenderer}
                  getChildren={this.getChildren}
                  overscanRowCount={20}
              />
          </div>
    }
</Measure>

Supported Browsers

  • Tested with Chrome 59+
  • Tested with Safari 11+
  • Tested with Firefox 54+

Rendering tree structures is supported in all modern browsers. For position: sticky, See http://caniuse.com/#search=position%3Asticky

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].