Build README
This commit is contained in:
@ -53,7 +53,7 @@ class TreeView extends React.Component {
|
||||
super(props);
|
||||
this.state = {
|
||||
toggled: props.toggled
|
||||
}
|
||||
};
|
||||
this.toggle = this.toggle.bind(this);
|
||||
}
|
||||
|
||||
@ -63,26 +63,52 @@ class TreeView extends React.Component {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div style={{ 'marginLeft': this.props.isChildElement ? 16 : 4 + 'px' }} className={this.props.isParentToggled ? 'tree-element' : 'tree-element collapsed'}>
|
||||
<span className={this.state.toggled ? "toggler" : "toggler closed" } onClick={this.toggle}></span>
|
||||
{this.props.name ? <strong> {this.props.name}: </strong> : <span> </span>}
|
||||
{Array.isArray(this.props.data) ? '[' : '{'}
|
||||
{!this.state.toggled && '...'}
|
||||
<div
|
||||
style={{ marginLeft: this.props.isChildElement ? 16 : 4 + "px" }}
|
||||
className={
|
||||
this.props.isParentToggled ? "tree-element" : "tree-element collapsed"
|
||||
}
|
||||
>
|
||||
<span
|
||||
className={this.state.toggled ? "toggler" : "toggler closed"}
|
||||
onClick={this.toggle}
|
||||
/>
|
||||
{this.props.name ? (
|
||||
<strong> {this.props.name}: </strong>
|
||||
) : (
|
||||
<span> </span>
|
||||
)}
|
||||
{Array.isArray(this.props.data) ? "[" : "{"}
|
||||
{!this.state.toggled && "..."}
|
||||
{Object.keys(this.props.data).map(
|
||||
(v, i, a) =>
|
||||
typeof this.props.data[v] == "object" ? (
|
||||
<TreeView data={this.props.data[v]} isLast={i === a.length - 1} name={Array.isArray(this.props.data) ? null : v} isChildElement isParentToggled={this.props.isParentToggled && this.state.toggled} />
|
||||
<TreeView
|
||||
data={this.props.data[v]}
|
||||
isLast={i === a.length - 1}
|
||||
name={Array.isArray(this.props.data) ? null : v}
|
||||
isChildElement
|
||||
isParentToggled={
|
||||
this.props.isParentToggled && this.state.toggled
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<p style={{ 'marginLeft': 16 + 'px' }} className={this.state.toggled ? 'tree-element' : 'tree-element collapsed'}>
|
||||
{Array.isArray(this.props.data) ? '' : <strong>{v}: </strong>}
|
||||
{this.props.data[v]}{i === a.length - 1 ? '' : ','}
|
||||
</p>
|
||||
)
|
||||
<p
|
||||
style={{ marginLeft: 16 + "px" }}
|
||||
className={
|
||||
this.state.toggled ? "tree-element" : "tree-element collapsed"
|
||||
}
|
||||
>
|
||||
{Array.isArray(this.props.data) ? "" : <strong>{v}: </strong>}
|
||||
{this.props.data[v]}
|
||||
{i === a.length - 1 ? "" : ","}
|
||||
</p>
|
||||
)
|
||||
)}
|
||||
{Array.isArray(this.props.data) ? ']' : '}'}
|
||||
{!this.props.isLast ? ',' : ''}
|
||||
{Array.isArray(this.props.data) ? "]" : "}"}
|
||||
{!this.props.isLast ? "," : ""}
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user