react-treebeard vs react-sortable-tree
Reactツリーライブラリ
react-treebeardreact-sortable-tree類似パッケージ:
Reactツリーライブラリ

Reactツリーライブラリは、ユーザーが階層的なデータを視覚的に表示し、操作できるようにするためのコンポーネントです。これらのライブラリは、ツリー構造を簡単に作成し、ユーザーがノードをドラッグアンドドロップで並べ替えたり、展開したりする機能を提供します。これにより、データの管理や表示が直感的に行えるようになります。

npmのダウンロードトレンド
3 年
GitHub Starsランキング
統計詳細
パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
react-treebeard128,1331,690-726年前MIT
react-sortable-tree64,9844,976-3475年前MIT
機能比較: react-treebeard vs react-sortable-tree

ドラッグアンドドロップ機能

  • react-treebeard:

    react-treebeardは、基本的なツリー表示を提供しますが、ドラッグアンドドロップ機能は標準ではサポートされていません。したがって、シンプルなツリー表示が必要な場合に適していますが、並べ替え機能は別途実装する必要があります。

  • react-sortable-tree:

    react-sortable-treeは、ノードをドラッグアンドドロップで簡単に並べ替えることができる機能を提供します。この機能により、ユーザーは直感的にツリーの構造を変更でき、動的なデータの管理が容易になります。

カスタマイズ性

  • react-treebeard:

    react-treebeardは、シンプルなAPIを提供し、ノードのスタイルや表示方法を簡単にカスタマイズできます。特に、CSSを使用して視覚的なスタイルを変更するのが容易です。

  • react-sortable-tree:

    react-sortable-treeは、ノードのレンダリングやスタイルをカスタマイズするための多くのオプションを提供しています。これにより、開発者はアプリケーションのニーズに合わせた独自のツリーを作成できます。

パフォーマンス

  • react-treebeard:

    react-treebeardは、軽量なライブラリであり、少量のデータを扱う場合に非常に高速です。ただし、大規模なデータセットの場合、パフォーマンスが低下する可能性があります。

  • react-sortable-tree:

    react-sortable-treeは、パフォーマンスを最適化するために、仮想化技術を使用して大規模なデータセットを効率的に処理できます。これにより、数千のノードを持つツリーでもスムーズに動作します。

使用シナリオ

  • react-treebeard:

    react-treebeardは、静的な階層データを表示する場合に適しており、ユーザーがデータを操作する必要がない場合に最適です。たとえば、設定メニューや情報の表示などに利用できます。

  • react-sortable-tree:

    react-sortable-treeは、ユーザーがデータを頻繁に並べ替える必要があるアプリケーションに最適です。たとえば、タスク管理アプリやファイル管理システムなど、動的なデータ操作が求められる場合に適しています。

学習曲線

  • react-treebeard:

    react-treebeardは、シンプルなAPIを持ち、基本的なツリー表示を作成するのが容易です。そのため、初学者にとっては学習がしやすいライブラリです。

  • react-sortable-tree:

    react-sortable-treeは、ドラッグアンドドロップ機能を実装するために、やや複雑な設定が必要です。そのため、初学者には少し学習曲線があるかもしれませんが、豊富なドキュメントが提供されています。

選び方: react-treebeard vs react-sortable-tree
  • react-treebeard:

    react-treebeardは、シンプルで軽量なツリー表示を提供しており、カスタマイズ性が高いです。複雑な操作が不要な場合や、視覚的に美しいツリーを簡単に作成したい場合に適しています。

  • react-sortable-tree:

    react-sortable-treeは、ノードのドラッグアンドドロップ機能を重視しているため、ユーザーがデータを簡単に並べ替えたり、階層を変更したりする必要がある場合に最適です。特に、動的なデータの管理が必要なアプリケーションに適しています。

react-treebeard のREADME

react-treebeard

Build Status Coverage Status

React Tree View Component. Data-Driven, Fast, Efficient and Customisable.

Install

npm install react-treebeard --save

Example

An online example from the /example directory can be found here: Here

Quick Start

import React, {PureComponent} from 'react';
import ReactDOM from 'react-dom';
import {Treebeard} from 'react-treebeard';

const data = {
    name: 'root',
    toggled: true,
    children: [
        {
            name: 'parent',
            children: [
                { name: 'child1' },
                { name: 'child2' }
            ]
        },
        {
            name: 'loading parent',
            loading: true,
            children: []
        },
        {
            name: 'parent',
            children: [
                {
                    name: 'nested parent',
                    children: [
                        { name: 'nested child 1' },
                        { name: 'nested child 2' }
                    ]
                }
            ]
        }
    ]
};

class TreeExample extends PureComponent {
    constructor(props){
        super(props);
        this.state = {data};
    }
    
    onToggle(node, toggled){
        const {cursor, data} = this.state;
        if (cursor) {
            this.setState(() => ({cursor, active: false}));
        }
        node.active = true;
        if (node.children) { 
            node.toggled = toggled; 
        }
        this.setState(() => ({cursor: node, data: Object.assign({}, data)}));
    }
    
    render(){
        const {data} = this.state;
        return (
            <Treebeard
                data={data}
                onToggle={this.onToggle}
            />
        );
    }
}

const content = document.getElementById('content');
ReactDOM.render(<TreeExample/>, content);

If you use react-hooks you should do something like this:

import React, {useState} from 'react';
const TreeExample = () => {
    const [data, setData] = useState(data);
    const [cursor, setCursor] = useState(false);
    
    const onToggle = (node, toggled) => {
        if (cursor) {
            cursor.active = false;
        }
        node.active = true;
        if (node.children) {
            node.toggled = toggled;
        }
        setCursor(node);
        setData(Object.assign({}, data))
    }
    
    return (
       <Treebeard data={data} onToggle={onToggle}/>
    )
}

const content = document.getElementById('content');
ReactDOM.render(<TreeExample/>, content);

Prop Values

data

PropTypes.oneOfType([PropTypes.object,PropTypes.array]).isRequired

Data that drives the tree view. State-driven effects can be built by manipulating the attributes in this object. Also supports an array for multiple nodes at the root level. An example can be found in example/data.js

onToggle

PropTypes.func

Callback function when a node is toggled / clicked. Passes 2 attributes: the data node and it's toggled boolean state.

style

PropTypes.object

Sets the treeview styling. Defaults to src/themes/default.

animations

PropTypes.oneOfType([PropTypes.object, PropTypes.bool])

Sets the treeview animations. Set to false if you want to turn off animations. See velocity-react for more details. Defaults to src/themes/animations.

decorators

PropTypes.object

Decorates the treeview. Here you can use your own Container, Header, Toggle and Loading components. Defaults to src/decorators. See example below:

const decorators = {
    Loading: (props) => {
        return (
            <div style={props.style}>
                loading...
            </div>
        );
    },
    Toggle: (props) => {
        return (
            <div style={props.style}>
                <svg height={props.height} width={props.width}>
                    // Vector Toggle Here
                </svg>
            </div>
        );
    },
    Header: (props) => {
        return (
            <div style={props.style}>
                {props.node.name}
            </div>
        );
    },
    Container: (props) => {
        return (
            <div onClick={this.props.onClick}>
                // Hide Toggle When Terminal Here
                <this.props.decorators.Toggle/>
                <this.props.decorators.Header/>
            </div>
        );
    }
};

<Treebeard data={...} decorators={decorators}/>

Data Attributes

{
    id: '[optional] string',
    name: 'string',
    children: '[optional] array',
    toggled: '[optional] boolean',
    active: '[optional] boolean',
    loading: '[optional] boolean',
    decorators: '[optional] object',
    animations: '[optional] object'
},

id

The component key. If not defined, an auto-generated index is used.

name

The name prop passed into the Header component.

children

The children attached to the node. This value populates the subtree at the specific node. Each child is built from the same basic data structure. Tip: Make this an empty array, if you want to asynchronously load a potential parent.

toggled

Toggled flag. Sets the visibility of a node's children. It also sets the state for the toggle decorator.

active

Active flag. If active, the node will be highlighted. The highlight is derived from the node.activeLink style object in the theme.

loading

Loading flag. It will populate the treeview with the loading component. Useful when asynchronously pulling the data into the treeview.

decorators / animations

Attach specific decorators / animations to a node. Provides the low level functionality to create visuals on a node-by-node basis. These structures are the same as the top level props, described above.