Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from iLoveCodingOrg/chore/examples
Examples added, readme improved
- Loading branch information
Showing
14 changed files
with
1,037 additions
and
35 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,5 @@ cfg/secrets.js | |
.DS_Store | ||
*.tgz | ||
|
||
dist/ | ||
dist | ||
dist-examples |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017 Aziz Ali | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,135 @@ | ||
import React, { Component } from 'react'; | ||
import ExpandableTree from '../dist/main.js'; | ||
import { cloneDeep, find } from 'lodash'; | ||
import '../dist/style.css'; | ||
|
||
export default class extends Component { | ||
constructor (){ | ||
super(); | ||
|
||
this.state = { | ||
data: [ | ||
{ | ||
id: 1, | ||
name: 'Parent A' | ||
} | ||
] | ||
} | ||
} | ||
|
||
render(){ | ||
const { state, setState } = this; | ||
return ( | ||
<div> | ||
<h2>Load Data Asynchronously</h2> | ||
<p>You can incrementally and asynchronously load data for child nodes.</p> | ||
<p>You can trigger an API call on any event (expand, check, delete), and update the <code>data</code> prop when your API resolves.</p> | ||
<p>To show the loading sign, set the <code>isChildrenLoading</code> value to <code>true</code> of the parent node whose chilren are being loaded</p> | ||
|
||
<p>These are the options:</p> | ||
<ol> | ||
<li><code>loadingElement</code> Provide your own loading indicator. Default <code><div>loading...</div></code></li> | ||
</ol> | ||
|
||
<hr/> | ||
<div className="row"> | ||
<div className="col-xs-12 col-lg-8 col-md-8"> | ||
<div className="panel panel-default"> | ||
<div className="panel-body"> | ||
<ExpandableTree | ||
data={ this.state.data } | ||
onUpdateCb={(updatedData)=>{ | ||
this.setState({data: updatedData}); | ||
}} | ||
isExpandable={(node, depth)=>{ return (depth===0)? true : false; }} | ||
onExpandToggleCb={(node, depth)=>{ | ||
// This will show the loading sign | ||
node.isChildrenLoading = true; | ||
|
||
setTimeout(()=>{ | ||
const updatedData = cloneDeep(state.data); | ||
|
||
// Remove loading sign | ||
updatedData[0].isChildrenLoading = false; | ||
|
||
// Make sure node is expanded | ||
updatedData[0].isExpanded = true; | ||
|
||
// Set Children data that you potentially | ||
// got from an API response | ||
updatedData[0].children = [ | ||
{ | ||
id: 22, | ||
name: 'Child 1' | ||
}, | ||
{ | ||
id: 23, | ||
name: 'Child 2' | ||
} | ||
]; | ||
|
||
// Update state | ||
this.setState({data: updatedData}) | ||
|
||
}, 1700); | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<h5>Source code:</h5> | ||
<pre> | ||
{`this.state = { | ||
data: [ | ||
{ | ||
id: 1, | ||
name: 'Parent A' | ||
} | ||
] | ||
} | ||
<ExpandableTree | ||
data={ this.state.data } | ||
onUpdateCb={(updatedData)=>{ | ||
this.setState({data: updatedData}); | ||
}} | ||
isExpandable={(node, depth)=>{ return (depth===0)? true : false; }} | ||
onExpandToggleCb={(node, depth)=>{ | ||
// This will show the loading sign | ||
node.isChildrenLoading = true; | ||
setTimeout(()=>{ | ||
const updatedData = cloneDeep(state.data); | ||
// Remove loading sign | ||
updatedData[0].isChildrenLoading = false; | ||
// Make sure node is expanded | ||
updatedData[0].isExpanded = true; | ||
// Set Children data that you potentially | ||
// got from an API response | ||
updatedData[0].children = [ | ||
{ | ||
id: 22, | ||
name: 'Child 1' | ||
}, | ||
{ | ||
id: 23, | ||
name: 'Child 2' | ||
} | ||
]; | ||
// Update state | ||
this.setState({data: updatedData}) | ||
}, 1700); | ||
}} | ||
/>`} | ||
</pre> | ||
</div> | ||
) | ||
} | ||
} |
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,120 @@ | ||
import React, { Component } from 'react'; | ||
import ExpandableTree from '../dist/main.js'; | ||
import '../dist/style.css'; | ||
|
||
export default class extends Component { | ||
constructor (){ | ||
super(); | ||
|
||
this.state = { | ||
data: [ | ||
{ | ||
id: 1, | ||
name: 'Parent A' | ||
}, | ||
{ | ||
id: 2, | ||
name: 'Parent B', | ||
isExpanded: true, | ||
isChecked: true, | ||
children: [ | ||
{ | ||
id: 21, | ||
name: 'Child 1', | ||
children: [ | ||
{ | ||
id: 5, | ||
name: "Grand Child" | ||
} | ||
] | ||
}, | ||
{ | ||
id: 22, | ||
name: 'Child 2' | ||
}, | ||
{ | ||
id: 23, | ||
name: 'Child 3' | ||
}, | ||
{ | ||
id: 24, | ||
name: 'Child 4' | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
|
||
render(){ | ||
return ( | ||
<div> | ||
<h2>Basic</h2> | ||
<hr/> | ||
<div className="row"> | ||
<div className="col-xs-12 col-lg-8 col-md-8"> | ||
<div className="panel panel-default"> | ||
<div className="panel-body"> | ||
<ExpandableTree | ||
data={ this.state.data } | ||
onUpdateCb={(updatedData)=>{ | ||
this.setState({data: updatedData}) | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<h5>Source code:</h5> | ||
<pre> | ||
{`this.state = { | ||
data: [ | ||
{ | ||
id: 1, | ||
name: 'Parent A' | ||
}, | ||
{ | ||
id: 2, | ||
name: 'Parent B', | ||
isExpanded: true, | ||
isChecked: true, | ||
children: [ | ||
{ | ||
id: 21, | ||
name: 'Child 1', | ||
children: [ | ||
{ | ||
id: 5, | ||
name: "Grand Child" | ||
} | ||
] | ||
}, | ||
{ | ||
id: 22, | ||
name: 'Child 2' | ||
}, | ||
{ | ||
id: 23, | ||
name: 'Child 3' | ||
}, | ||
{ | ||
id: 24, | ||
name: 'Child 4' | ||
} | ||
] | ||
} | ||
] | ||
} | ||
<ExpandableTree | ||
data={ this.state.data } | ||
onUpdateCb={(updatedData)=>{ | ||
this.setState({data: updatedData}) | ||
}} | ||
/>`} | ||
</pre> | ||
</div> | ||
) | ||
} | ||
} |
Oops, something went wrong.