teleport / react-dnd-treeview Goto Github PK
View Code? Open in Web Editor NEWReact.js tree view component with drag-and-drop support using react-dnd
License: MIT License
React.js tree view component with drag-and-drop support using react-dnd
License: MIT License
Hi,
It would be great to implement "isDraggable" prop in the node to prevent unnecessary drags.
The usual case is to let user select text in child inputs by mouse.
Thanks.
Hi @magnushiie,
I was wondering whether there is a documentation of how to use your component. I find the working example very interesting but have problems developing my own application as I am not using TypeScript. Therefore, I will appreciate it, if you can provide me with any documentation and help.
Thanks in advance,
Marius
In your example, remove B1 & B2, then nothing can be added to B, nor any other leaf node - dragging onto a leaf not can only make it a sibling.
Hi,
I'm currently assessing this library for a project I'm working on. Is easy to get
drag'n'drop to work across two instances of the TreeView?
I started experimenting with this library as it essentially offers exactly what I need. Could you consider removing Immutable.js as a dependency given that it's not really needed but and should be up to the consumer of the library to opt-in? Looking at my webpack stats, it seems to add 139KB which is non-trivial given that it's adding no benefit for me.
Hello,
I am trying to use TreeView component without TypeScript syntax. But I have an error with my custom component in ES6 (PostCategoryList.js). Thanks in advance for your help.
import styles from './PostsCategories.css';
import React from 'react';
import * as Immutable from 'immutable';
import HTML5Backend from 'react-dnd-html5-backend';
import { DragDropContext } from 'react-dnd';
import { TreeView } from 'react-dnd-treeview';
const recursivelyUpdateList = (
list,
parentNode,
listUpdateFunc,
nodeUpdateFunc
) => {
const mappedItems = list.items.map(
item => recursivelyUpdateNode(item, listUpdateFunc, nodeUpdateFunc)
);
if (!Immutable.is(mappedItems, list.items)) {
list = Object.assign({}, list, {
items: mappedItems,
});
}
return listUpdateFunc(list, parentNode);
};
const recursivelyUpdateNode = (
node,
listUpdateFunc,
nodeUpdateFunc) => {
const updateChildren = node.children
? recursivelyUpdateList(node.children, node, listUpdateFunc, nodeUpdateFunc)
: node.children;
if (updateChildren !== node.children) {
node = Object.assign({}, node, {
children: updateChildren,
});
}
return nodeUpdateFunc(node);
};
class PostCategoryList extends React.Component {
constructor(props, context) {
super(props, context);
this.state = {
rootNodes: {
items: [{
id: 'A',
title: 'A',
children: {
items: [{
id: 'A1',
title: 'A1'
},
{
id: 'A2',
title: 'A2'
},
{
id: 'A3',
title: 'A3'
}]
},
},
{
id: 'B',
title: 'B',
children: {
items: [{
id: 'B1',
title: 'B1'
},
{
id: 'B2',
title: 'B2'
}]
},
},
{
id: 'C',
title: 'C',
children: {
items: [{
id: 'C1',
title: 'C1',
children: {
items: [{
id: 'C1x',
title: 'C1x'
},
{
id: 'C1y',
title: 'C1y'
},
{
id: 'C1z',
title: 'C1z'
},
{
id: 'C1zz',
title: 'C1zz'
},
{
id: 'C1zzz',
title: 'C1zzz'
}]
}
}]
}
}]
}
};
this.renderNode = this.renderNode.bind(this);
this.handleMoveNode = this.handleMoveNode.bind(this);
}
setStateWithLog(newState) {
console.log("new state: ", newState);
this.setState(newState);
}
handleMoveNode(args) {
this.setState(Object.assign({}, this.state, {
rootNodes: recursivelyUpdateList(
this.state.rootNodes,
null,
(list, parentNode) =>
parentNode === args.newParentNode && parentNode === args.oldParentNode
? Object.assign({}, list, {
items:
list.items
.insert(args.newParentChildIndex, args.node)
.remove(args.oldParentChildIndex + (args.newParentChildIndex < args.oldParentChildIndex ? 1 : 0))
})
: parentNode === args.newParentNode
? Object.assign({}, list, {
items: list.items.insert(args.newParentChildIndex, args.node)
})
: parentNode === args.oldParentNode
? Object.assign({}, list, {
items: list.items.remove(args.oldParentChildIndex)
})
: list,
item => item
),
}));
}
handleToggleCollapse(node) {
this.setStateWithLog(Object.assign({}, this.state, {
rootNodes: recursivelyUpdateList(
this.state.rootNodes,
null,
(list, parentNode) => list,
item => item === node ? Object.assign({}, item, {
isCollapsed: !item.isCollapsed,
}) : item
),
}));
}
renderNode(node) {
return (
<div className={ styles.nodeItem }>
{ !node.children || node.children.items.isEmpty()
? null
: <a
style={{ fontSize: '0.5em', verticalAlign: 'middle' }}
onClick={ () => this.handleToggleCollapse(node) }
>
{node.isCollapsed ? '⊕' : '⊖'}
</a>
}
Node: { node.title }
</div>
);
}
render() {
return (
<div className={styles.categoriesListing}>
<TreeView
rootNodes={ this.state.rootNodes }
classNames={ styles }
renderNode={ this.renderNode }
onMoveNode={ this.handleMoveNode }
/>
</div>
);
}
}
export default DragDropContext(HTML5Backend)(PostCategoryList);
Thanks for the wonderful plugin.. i am trying to use this in my mobile app and it working in touch devices too when i change backend. I would like to use this as a listview and like to know how to customize the styles.
Is there any way i can customize the insert target styles and other things?
Docs say cd example && npm install && npm start
but there is no start-script, so it errs at:
npm ERR! missing script: start
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.