Skip to content

Instantly share code, notes, and snippets.

@Xananax
Created October 21, 2015 14:15
Show Gist options
  • Save Xananax/3f6ef7f6e260f28f30de to your computer and use it in GitHub Desktop.
Save Xananax/3f6ef7f6e260f28f30de to your computer and use it in GitHub Desktop.
class Directory extends Component{
renderDirectories(){
const {directories} = this.props;
if(!directories || !directories.length){
return false;
}
return directories.map((dir,key)=>
<tr key={key}><td>
<Directory {...dir}/>
</td></tr>
)
}
renderFiles(){
const {files} = this.props;
if(!files || !files.length){
return false;
}
return files.map((file,key)=>
<tr key={key}>
<td>{file}</td>
</tr>
)
}
render(){
const {name} = this.props;
return (<table name={name}>
<thead><tr><td>{name}</td></tr></thead>
<tbody>
{this.renderDirectories()}
{this.renderFiles()}
</tbody>
</table>)
}
}
const props = {
name:'Root'
directories:[
{
name:'dirA'
, directories:[
{
name:'dirB'
files:[
'dirA/dirB/fileA'
, 'dirA/dirB/fileB'
]
}
]
, files:[
'dirA/fileA'
]
}
]
, files:[
'rootFile'
]
}
<table name="Root">
<thead>Root</thead>
<tbody>
<tr><td>
<table name="DirA">
<thead>DirA</thead>
<tbody>
<tr><td>
<table name="DirB">
<thead>DirB</thead>
<tbody>
<tr><td>
dirA/dirB/fileA
</td></tr>
<tr><td>
dirA/dirB/fileB
</td></tr>
</tbody>
</table>
</td></tr>
<tr><td>
dirA/fileA
</td></tr>
</tbody>
</table>
</td></tr>
<tr><td>
rootFile
</td></tr>
</tbody>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment