@bartaxyz/react-tree-list

Tree list UI component for React

Usage no npm install needed!

<script type="module">
  import bartaxyzReactTreeList from 'https://cdn.skypack.dev/@bartaxyz/react-tree-list';
</script>

README

React Tree List

Node.js CI

A draggable & sortable tree list UI component for React.

React Tree List Component Showcase

Demo  ·  See Features  ·  Request Feature

Usage

Installation with NPM

npm install @bartaxyz/react-tree-list

This package additionaly requires you having react and react-dom dependencies.

Importing

You can import the component directly as ReactTreeList

import { ReactTreeList } from '@bartaxyz/react-tree-list';

Typescript

For Typescript the imports additionaly include types like ReactTreeListProps which is a type of properties for ReactTreeList component.

import { ReactTreeList, ReactTreeListProps } from '@bartaxyz/react-tree-list';

Simple Example

This is a simple implementation with some items (one nested item) and defaults for each of the items.

import React, { useState } from 'react';
import { ReactTreeList } from '@bartaxyz/react-tree-list';


const Component = () => {
  const [data, setData] = useState([
    {
      label: 'Item #1',
      open: true,
      children: [{ label: 'Item #2' }],
    },
    {
      label: 'Item #3',
    },
  ]);
  
  const onTreeListChange = (data) => {
    setData(data);
  }
  
  return (
    <ReactTreeList
      data={data}
      onChange={onTreeListChange}
      itemDefaults={{ open: false, arrow: "▸" }}
    />
  );
}

See Advanced Examples

License

React Tree List is licensed under the MIT License.

Authors

Ondřej Bárta · website · twitter