0.0.7 • Published 6 months ago

react-tree-list-alvin v0.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

⚠ Warning

This repository will only have small feature changes / additions and may not be up to date with the original repository! New Features:

  • Made the following properties work: allowChildren & allowDropInside (allowChildren currently has no effect on existing children) Everything else is left as is. Even this Readme (except for the package name)

React Tree List

A draggable & sortable tree list UI component for React.

Note These are still the links from the forked repository.

Demo  ·  See Features  ·  Request Feature

Usage

Installation with NPM

npm install @gamingklex/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 "@gamingklex/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 "@gamingklex/react-tree-list";

Simple Example

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

⚠️ If you're adding your own id parameter, it's important that it's a string and not a number or other type.

import React, { useState } from "react";
import { ReactTreeList } from "@gamingklex/react-tree-list";

const Component = () => {
  const [data, setData] = useState([
    {
      id: "1",
      label: "Item #1",
      open: true,
      children: [{ label: "Item #2" }],
    },
    {
      id: "2",
      label: "Item #3",
    },
  ]);

  const onTreeListChange = (data) => {
    setData(data);
  };

  const onTreeListSelected = (item) => {
    console.log("choosed item =", item);
  };

  const onDrop = (dragingNode, dragNode, drogType) => {
    console.log("dragingNode:", dragingNode);
    console.log("dragNode:", dragNode);
    console.log("drogType:", drogType);
  };

  return (
    <ReactTreeList
      data={data}
      draggable={true}
      onDrop={onDrop}
      onChange={onTreeListChange}
      itemDefaults={{ open: false, arrow: "▸" }}
      selectedId="1"
      onSelected={onTreeListSelected}
    />
  );
};

Open this code in Code Sandbox

Simple Style Customisation

There's a limited possibility to adjust the styles (background color, outline color, border radius, etc.) of the focused items using the itemOptions property.

const Component = () => {
  ...

  return (
    <ReactTreeList
      ...
      itemOptions={{
        focusedOutlineColor: "rgba(255, 0, 0, 0.5)",
        focusedOutlineWidth: 1,
        focusedBorderRadius: 50,
        focusedBackgroundColor: "rgba(255, 0, 0, 0.1)",
      }}
    />
  );
}

Storybook - Tree List With Custom Styles

See Advanced Examples

License

React Tree List is licensed under the MIT License.

Authors

Ondřej Bárta · GitHub · website · twitter Edited by GamingKlex · GitHub

Contributors

张威 (zhangwei900808) · GitHub

0.0.7

6 months ago

0.0.6

6 months ago

0.0.5

6 months ago

0.0.4

6 months ago

0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago