Socket
Socket
Sign inDemoInstall

react-nestable-2

Package Overview
Dependencies
24
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-nestable-2

Drag & drop hierarchical list made as a react component


Version published
Weekly downloads
39
increased by105.26%
Maintainers
1
Install size
5.55 MB
Created
Weekly downloads
 

Readme

Source

Table of Contents

  • Demo
  • Installation
  • Usage
  • Options
  • Todo
  • License

Demo

Demo

Installation

npm install -save react-nestable

Usage

import Nestable from 'react-nestable';

every item must have a unique id in order to distinguish elements

const items = [
  { id: 0, text: 'Andy' },
  {
    id: 1, text: 'Harry',
    children: [
      { id: 2, text: 'David' }
    ]
  },
  { id: 3, text: 'Lisa' }
];

const renderItem = ({ item }) => item.text;

const Example = () => (
  <Nestable
    items={items}
    renderItem={renderItem}
  />
)

Options

PropertyTypeDefaultDescription
classNamestringundefinedExtra class name which can be passed to a root element.
itemsarray[]Array of items. Every item must be of shape { id: @uniq }.
thresholdint30Amount of pixels which mouse should move horizontally before increasing/decreasing level (nesting) of current element.
maxDepthint10Maximum available level of nesting.
collapsedbooleanfalseAre groups collapsed by default.
groupstring or intrandom stringDifferent group numbers may be passed if you have more than one nestable component on a page and want some extra styles for portal instances.
handlercomponentIf you pass react component here, you may use it in your render method.
childrenPropstring"children"Optional name of property with children.
renderItemfunction({ item, index }) => item.toString()Function for rendering every item. Has a single parameter with keys: item - item from your array, index - index of the item, collapseIcon - icon for items with children (allows you to collapse group), handler - component which you have passed via the same property, but covered with some additional events.
renderCollapseIconfunction({ isCollapsed }) => <DefaultIcon />Function for rendering collapse icon. Has a single parameter with keys: isCollapsed - boolean, true if this group has children and collapsed.
onChangefunction() => {}Callback which has two parameters: items - new array after position was changed, item - item which has been moved.
confirmChangefunction() => trueCallback which has two parameters: dragItem - item which is being dragged, destinationParent - item where dragItem is about to land. Let function return false if this movement should not happen.
Public methods
MethodAcceptsDescription
collapsestring or array"NONE" - expand all groups; "ALL" - collapse all groups; [] - collapse all groups with ids from given array

Todo

  • add touch
  • cover with tests

PS: Please, make an issue or create a PR if you need any more functionality.

License

ISC

Keywords

FAQs

Last updated on 02 Jun 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc