-
Notifications
You must be signed in to change notification settings - Fork 899
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add onDragStateChanged callback
Thanks to @wuweiweiwu for the contribution! onDragStateChanged is called when dragging begins and ends, so you can easily track the current state of dragging.
- Loading branch information
Showing
6 changed files
with
446 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React, { Component } from 'react'; | ||
import SortableTree from '../../src'; | ||
|
||
export default class App extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
treeData: [ | ||
{ title: 'A', expanded: true, children: [{ title: 'B' }] }, | ||
{ title: 'C' }, | ||
], | ||
lastMovePrevPath: null, | ||
lastMoveNextPath: null, | ||
lastMoveNode: null, | ||
}; | ||
} | ||
|
||
render() { | ||
const { lastMovePrevPath, lastMoveNextPath, lastMoveNode } = this.state; | ||
|
||
const recordCall = (name, args) => { | ||
// eslint-disable-next-line no-console | ||
console.log(`${name} called with arguments:`, args); | ||
}; | ||
|
||
return ( | ||
<div> | ||
Open your console to see callback parameter info | ||
<div style={{ height: 300 }}> | ||
<SortableTree | ||
treeData={this.state.treeData} | ||
onChange={treeData => this.setState({ treeData })} | ||
// Need to set getNodeKey to get meaningful ids in paths | ||
getNodeKey={({ node }) => `node${node.title}`} | ||
onVisibilityToggle={args => recordCall('onVisibilityToggle', args)} | ||
onMoveNode={args => { | ||
recordCall('onMoveNode', args); | ||
const { prevPath, nextPath, node } = args; | ||
this.setState({ | ||
lastMovePrevPath: prevPath, | ||
lastMoveNextPath: nextPath, | ||
lastMoveNode: node, | ||
}); | ||
}} | ||
onDragStateChanged={args => recordCall('onDragStateChanged', args)} | ||
/> | ||
</div> | ||
{lastMoveNode && ( | ||
<div> | ||
Node "{lastMoveNode.title}" moved from path [{lastMovePrevPath.join( | ||
',' | ||
)}] to path [{lastMoveNextPath.join(',')}]. | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} | ||
} |
Oops, something went wrong.