All Projects β†’ shunjizhan β†’ react-folder-tree

shunjizhan / react-folder-tree

Licence: other
A versatile react treeview library that supports custom icons and event handlers

Programming Languages

javascript
184084 projects - #8 most used programming language
SCSS
7915 projects

Projects that are alternatives of or similar to react-folder-tree

Recursion-Tree-Visualizer
A simple python package that helps to visualise any recursive function by adding a single line of code.
Stars: ✭ 89 (+58.93%)
Mutual labels:  recursion, recursion-tree, recursion-tree-visualiser, recursion-tree-visualizer
Singlespotify
🎡 Create Spotify playlists based on one artist through the command line
Stars: ✭ 254 (+353.57%)
Mutual labels:  npm-package, npm-module
Ts ci
βœ… Continuous integration setup for TypeScript projects via GitHub Actions.
Stars: ✭ 225 (+301.79%)
Mutual labels:  npm-package, npm-module
Unity-IMGUI-TreeView
Simple Tree View implementation for IMGUI (Editor GUI) in Unity. Includes a special type for working with asset paths, but base data structure and view can be easily extended to support anything.
Stars: ✭ 73 (+30.36%)
Mutual labels:  tree-structure, treeview
Jsonexport
{} β†’ πŸ“„ it's easy to convert JSON to CSV
Stars: ✭ 208 (+271.43%)
Mutual labels:  npm-package, npm-module
Abort Controller
An implementation of WHATWG AbortController interface.
Stars: ✭ 213 (+280.36%)
Mutual labels:  npm-package, npm-module
vue-virtualised
Blazing fast scrolling and updating for any amount of list and hierarchical data.
Stars: ✭ 18 (-67.86%)
Mutual labels:  tree-structure, treeview
Homebridge Wol
A Wake on Lan plugin for Homebridge
Stars: ✭ 150 (+167.86%)
Mutual labels:  npm-package, npm-module
js-stack-from-scratch
🌺 Russian translation of "JavaScript Stack from Scratch" from the React-Theming developers https://github.com/sm-react/react-theming
Stars: ✭ 394 (+603.57%)
Mutual labels:  npm-package, npm-module
intersection-wasm
Mesh-Mesh and Triangle-Triangle Intersection tests based on the algorithm by Tomas Akenine-MΓΆller
Stars: ✭ 17 (-69.64%)
Mutual labels:  npm-package, npm-module
arcscord
A Discord library written in typescript
Stars: ✭ 18 (-67.86%)
Mutual labels:  npm-package, npm-module
Darkmode.js
πŸŒ“ Add a dark-mode / night-mode to your website in a few seconds
Stars: ✭ 2,339 (+4076.79%)
Mutual labels:  npm-package, npm-module
Node Regedit
Read, Write, List and do all sorts of funky stuff to the windows registry using node.js and windows script host
Stars: ✭ 178 (+217.86%)
Mutual labels:  npm-package, npm-module
Eslint Plugin Eslint Comments
Additional ESLint rules for directive comments of ESLint.
Stars: ✭ 221 (+294.64%)
Mutual labels:  npm-package, npm-module
Reactopt
A CLI React performance optimization tool that identifies potential unnecessary re-rendering
Stars: ✭ 1,975 (+3426.79%)
Mutual labels:  npm-package, npm-module
micro-signals
A tiny typed messaging system inspired by js-signals that uses ES2015 sets
Stars: ✭ 39 (-30.36%)
Mutual labels:  npm-package, npm-module
Tplink Cloud Api
A node.js npm module to remotely control TP-Link smartplugs (HS100, HS110) and smartbulbs (LB100, LB110, LB120, LB130) using their cloud web service (no need to be on the same wifi/lan)
Stars: ✭ 96 (+71.43%)
Mutual labels:  npm-package, npm-module
React Ckeditor
CKEditor component for React with plugin and custom event listeners support
Stars: ✭ 124 (+121.43%)
Mutual labels:  npm-package, npm-module
react-tree
Hierarchical tree component for React in Typescript
Stars: ✭ 174 (+210.71%)
Mutual labels:  tree-structure, treeview
MinifyAllCli
πŸ“¦ A lightweight, simple and easy npm tool to π—Ίπ—Άπ—»π—Άπ—³π˜† JSON/C, HTML and CSS! Also known as MinifyAll core! ⭐ Usable as π‘ͺ𝑳𝑰 tool or π’Šπ’Žπ’‘π’π’“π’•π’‚π’ƒπ’π’† in TS/JS as a 𝑴𝑢𝑫𝑼𝑳𝑬 πŸ₯°
Stars: ✭ 21 (-62.5%)
Mutual labels:  npm-package, npm-module

React Folder Tree

travis build codecov npm bundle size
npm npm GitHub top language

A versatile and customizable react treeview library. Features:
βœ… custom icons
βœ… custom event handlers
βœ… inline add, modify, and delete tree nodes
βœ… checkbox with half check (indeterminate check)
βœ… read-only mode

It uses use-tree-state hook internally for convenient state management.

Quick Preview

folder-tree-demo

Live Demos

live demos and code examples can be found here


Basic Usage

πŸŒ€ install

$ yarn add react-folder-tree
$ npm install react-folder-tree --save

πŸŒ€ basic tree

import FolderTree, { testData } from 'react-folder-tree';
import 'react-folder-tree/dist/style.css';

const BasicTree = () => {
  const onTreeStateChange = (state, event) => console.log(state, event);

  return (
    <FolderTree
      data={ testData }
      onChange={ onTreeStateChange }
    />
  );
};

πŸŒ€ custom initial state

Initial tree state is an object that describes a nested tree node structure, which looks like:

{
  // reserved keys, can customize initial value
  name: 'root node',  
  checked (optional): 0 (unchecked, default) | 0.5 (half checked) | 1(checked),
  isOpen (optional): true (default) | false,
  children (optional): [array of treenode],

  // internal keys (auto generated), plz don't include them in the initial data
  path: [],    // path is an array of indexes to this node from root node
  _id: 0,

  // not reserved, can carry any extra info about this node
  nickname (optional): 'pikachu',
  url (optional): 'url of this node',
}

checked and isOpen status could be auto initialized by props initCheckedStatus and initOpenStatus. We can also provide data with custom checked and isOpen status, and set initCheckedStatus and initOpenStatus to 'custom'.

This example shows how to render a tree with custom initial state

const treeState = {
  name: 'root [half checked and opened]',
  checked: 0.5,   // half check: some children are checked
  isOpen: true,   // this folder is opened, we can see it's children
  children: [
    { name: 'children 1 [not checked]', checked: 0 },
    {
      name: 'children 2 [half checked and not opened]',
      checked: 0.5,
      isOpen: false,
      children: [
        { name: 'children 2-1 [not checked]', checked: 0 },
        { name: 'children 2-2 [checked]', checked: 1 },
      ],
    },
  ],
};

const CustomInitState = () => (
  <FolderTree
    data={ treeState }
    initCheckedStatus='custom'  // default: 0 [unchecked]
    initOpenStatus='custom'     // default: 'open'
  />
);

πŸŒ€ hate checkbox?

<FolderTree
  data={ treeState }
  showCheckbox={ false }    // default: true
/>

πŸŒ€ love indentation?

<FolderTree
  data={ treeState }
  indentPixels={ 99999 }    // default: 30
/>

πŸŒ€ read only?

we can use it as a classical view-only tree

<FolderTree
  data={ treeState }
  showCheckbox={ false }    // hiding checkbox is not required but recommended for better UX
  readOnly                  // <== here!!
/>

Advanced Usage

πŸ”₯ sync tree state

In order to perform more complex operations, we can sync and keep track of the current tree state outside.

This example shows how to download all selected files.

const SuperApp = () => {
  const [treeState, setTreeState] = useState(initState);
  const onTreeStateChange = (state, event) => setTreeState(state);

  const onDownload = () => downloadAllSelected(treeState);

  return (
    <>
      <FolderTree
        data={ initState }
        onChange={ onTreeStateChange }
      />
      <DownloadButton onClick={ onDownload } />
    </>
  );
};

πŸ”₯ custom icons

There are 9 icons and all of them are customizable.

  • FileIcon
  • FolderIcon
  • FolderOpenIcon
  • EditIcon
  • DeleteIcon
  • CancelIcon
  • CaretRightIcon
  • CaretDownIcon
  • OKIcon

This example shows how to customize the FileIcon (same interface for all other icons).

import { FaBitcoin } from 'react-icons/fa';

const BitcoinApp = () => {
  const FileIcon = ({ onClick: defaultOnClick, nodeData }) => {
    const {
      path,
      name,
      checked,
      isOpen,
      ...restData
    } = nodeData;

    // custom event handler
    const handleClick = () => {   
      doSthBad({ path, name, checked, isOpen, ...restData });

      defaultOnClick();
    };

    // custom Style
    return <FaBitcoin onClick={ handleClick } />;
  };

  return (
    <FolderTree
      data={ initState }
      iconComponents={{
        FileIcon,
        /* other custom icons ... */
      }}
    />
  );
};

πŸ”₯ hide icons / disable interaction

This usage is a subset of custom icons.

For example, if we want to disable editing, we can hide EditIcon by passing in a dummy custom icon, so nothing will be rendered.

const EditIcon = (...args) => null;

A little more complex but more flexible way is to have extra node data, say editable, then build a custom icon that utilize this data

const EditIcon = ({ onClick: defaultOnClick, nodeData }) => {
  const { editable } = nodeData;

  // if this node is editable, render an EditIcon, otherwise render air
  return editable ? (<FaEdit onClick={ defaultOnClick } />) : null;

  // or render a 'not editable' icon
  return editable ? (<FaEdit onClick={ defaultOnClick } />) : (<DontEdit />));
};

πŸ”₯ custom onClick for node names

This example shows how to download the file when click on the node name.

const dataWithUrl = {
  name: 'secret crypto file',
  url: 'polkadot.network',      // wew can provide any custom data to the FolderTree!
  // ...
};

const onNameClick = ({ defaultOnClick, nodeData }) => {
  defaultOnClick();

  const {
    // internal data
    path, name, checked, isOpen, 
    // custom data
    url, ...whateverRest
  } = nodeData;

  download(url);
};

const Downloader = () => (
  <FolderTree
    data={ dataWithUrl }
    onNameClick={ onNameClick }
  />
);

APIs Summary

prop description type options
data initial tree state data (required) object N/A
initCheckedStatus initial check status of all nodes string 'unchecked' (default) | 'checked' | 'custom'
initOpenStatus initial open status of all treenodes string 'open' (default) | 'closed' | 'custom'
iconComponents custom icon components object ant design icons (default)
onChange callback when tree state changes function console.log (default)
onNameClick callback when click treenode name function open treenode inline toolbox (default)
indentPixels ident pixels of 1x level treenode number 30 (default)
showCheckbox show check box? bool true (default)
readOnly readOnly mode? can't click/check node bool false (default)

Bugs? Questions? Contributions?

Feel free to open an issue, or create a pull request!

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].