@@ -7,72 +7,114 @@ class App extends Component {
77 constructor ( props ) {
88 super ( props ) ;
99
10+ const renderDepthTitle = ( { path } ) => `Depth: ${ path . length } `
11+
1012 this . state = {
1113 treeData : [
1214 {
13- id : 'b12314' ,
14- title : 'Beast Man' ,
15- subtitle : 'Pancakes' ,
15+ title : '`title`' ,
16+ subtitle : '`subtitle`' ,
1617 expanded : true ,
1718 children : [
1819 {
19- id : 1 ,
20- title : 'Joe' ,
21- subtitle : 'Pancakes' ,
22- children : [ ] , // null or undefined also ok
20+ title : 'Child Node' ,
21+ subtitle : 'Defined in `children` array belonging to parent' ,
2322 } ,
2423 {
25- title : 'Plain Jane' ,
24+ title : 'Nested structure is rendered virtually' ,
25+ subtitle : (
26+ < span >
27+ The tree uses
28+ < a href = "https://github.com/bvaughn/react-virtualized" >
29+ react-virtualized
30+ </ a >
31+ and the relationship lines are more of a visual trick.
32+ </ span >
33+ ) ,
2634 } ,
2735 ] ,
2836 } ,
2937 {
30- id : 'b12315' ,
31- title : (
32- < div >
33- < div
34- style = { {
35- backgroundColor : 'gray' ,
36- display : 'inline-block' ,
37- borderRadius : 10 ,
38- color : '#FFF' ,
39- padding : '0 5px' ,
40- } }
41- >
42- Custom
43- </ div >
44-
45- Element
46- </ div >
47- ) ,
38+ expanded : true ,
39+ title : 'Any node can be the parent or child of any other node' ,
40+ children : [
41+ {
42+ expanded : true ,
43+ title : 'Chicken' ,
44+ children : [
45+ { title : 'Egg' } ,
46+ ] ,
47+ } ,
48+ ] ,
49+ } ,
50+ {
51+ title : 'Button(s) can be added to the node' ,
52+ subtitle : 'Node info is passed when generating so you can use it in your onClick handler' ,
4853 } ,
4954 {
50- id : 'b12316' ,
51- title : 'Really Long Name Nicholas Who Always Got' +
52- ' Picked on in School For His Really Long Name' ,
53- subtitle : 'Really good icebreaker, though' ,
55+ title : 'Show node children by setting `expanded`' ,
5456 children : [
5557 {
5658 title : 'Bruce' ,
5759 children : [
5860 { title : 'Bruce Jr.' } ,
59- { title : 'Brucette Jr. ' } ,
61+ { title : 'Brucette' } ,
6062 ] ,
6163 } ,
64+ ] ,
65+ } ,
66+ {
67+ title : 'Advanced' ,
68+ subtitle : 'Settings, behavior, etc.' ,
69+ children : [
70+ {
71+ title : (
72+ < div >
73+ < div
74+ style = { {
75+ backgroundColor : 'gray' ,
76+ display : 'inline-block' ,
77+ borderRadius : 10 ,
78+ color : '#FFF' ,
79+ padding : '0 5px' ,
80+ } }
81+ >
82+ Any Component
83+ </ div >
84+
85+ can be used for `title`
86+ </ div >
87+ ) ,
88+ } ,
6289 {
63- title : 'Trevor' ,
90+ expanded : true ,
91+ title : 'Limit nesting with `maxDepth`' ,
92+ subtitle : 'It\'s set to 5 for this example' ,
6493 children : [
65- { title : 'Trevor Jr.' } ,
66- { title : 'Trevor Jr. 2' } ,
94+ {
95+ expanded : true ,
96+ title : renderDepthTitle ,
97+ children : [
98+ {
99+ expanded : true ,
100+ title : renderDepthTitle ,
101+ children : [
102+ { title : renderDepthTitle } ,
103+ {
104+ title : 'This cannot be dragged deeper' ,
105+ } ,
106+ ] ,
107+ } ,
108+ ] ,
109+ } ,
67110 ] ,
68111 } ,
112+ {
113+ title : 'When node contents are really long, it will cause a horizontal scrollbar' +
114+ ' to appear. Deeply nested elements will also trigger the scrollbar.' ,
115+ } ,
69116 ] ,
70117 } ,
71- {
72- id : 'b12336' ,
73- title : 'Tracy Page' ,
74- subtitle : 'Waffles' ,
75- } ,
76118 ] ,
77119 } ;
78120
@@ -108,6 +150,24 @@ class App extends Component {
108150 const authorUrl = 'https://github.com/fritz-c' ;
109151 const githubUrl = 'https://github.com/fritz-c/react-sortable-tree' ;
110152
153+ const alertNodeInfo = ( {
154+ node,
155+ path,
156+ treeIndex,
157+ lowerSiblingCounts : _lowerSiblingCounts ,
158+ } ) => {
159+ const objectString = Object . keys ( node )
160+ . map ( k => ( k === 'children' ? 'children: Array' : `${ k } : '${ node [ k ] } '` ) )
161+ . join ( `,\n ` ) ;
162+
163+ alert ( // eslint-disable-line no-alert
164+ `Info passed to the button generator:\n\n` +
165+ `node: {\n ${ objectString } \n},\n` +
166+ `path: ${ path . join ( ', ' ) } ,\n` +
167+ `treeIndex: ${ treeIndex } `
168+ ) ;
169+ } ;
170+
111171 return (
112172 < div >
113173 < section className = { styles [ 'page-header' ] } >
@@ -137,22 +197,13 @@ class App extends Component {
137197 treeData = { this . state . treeData }
138198 updateTreeData = { this . updateTreeData }
139199 maxDepth = { 5 }
140- generateNodeProps = { ( {
141- node,
142- path,
143- treeIndex,
144- lowerSiblingCounts : _lowerSiblingCounts ,
145- } ) => ( {
200+ generateNodeProps = { ( rowInfo ) => ( {
146201 buttons : [
147202 < button
148203 style = { {
149204 verticalAlign : 'middle' ,
150205 } }
151- onClick = { ( ) => alert ( // eslint-disable-line no-alert
152- `title: ${ node . title } \n` +
153- `path: ${ path . join ( ', ' ) } \n` +
154- `treeIndex: ${ treeIndex } `
155- ) }
206+ onClick = { ( ) => alertNodeInfo ( rowInfo ) }
156207 >
157208 ℹ
158209 </ button > ,
0 commit comments