Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import TreeView from 'react-expandable-treeview';
```javascript
{
id: 0,
hasChildren: true,
children: [
//...all the children elements*/
],
Expand All @@ -31,21 +32,27 @@ And an example of the `data` prop o be passed to `TreeView` component.
const data = [
{
id: 0,
hasChildren: true,
children: [
{
id: 1
id: 1,
hasChildren: false
},
{
id: 2
id: 2,
hasChildren: false
}
],
id: 3,
hasChildren: true,
children: [
{
id: 4,
hasChildren: true,
children: [
{
id: 5
id: 5,
hasChildren: false
}
]
}
Expand All @@ -60,26 +67,32 @@ In the example we add a custom `label` attribute to our `data` elements and we w
const data = [
{
id: 0,
label: 'A Father'
label: 'A Father',
hasChildren: true,
children: [
{
id: 1,
label: 'A Son'
label: 'A Son',
hasChildren: false
},
{
id: 2,
label: 'Another Son'
label: 'Another Son',
hasChildren: false
}
],
id: 3,
label: 'Another Father',
hasChildren: true,
children: [
{
id: 4,
hasChildren: true,
children: [
{
id: 5,
label: 'Yet Another Son',
hasChildren: false
}
]
}
Expand Down
12 changes: 4 additions & 8 deletions src/demo/testData.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@ const testData = [
{
id: 0,
name: "Felidae",
hasChildren: true,
children: [
{
id: 1,
name: "Pantherinae",
hasChildren: true,
children: [
{
id: 2,
name: "Neofelis",
},
{
id: 3,
name: "Panthera",
}
]
},
{
id: 4,
name: "Felinae",
hasChildren: true,
children: [
{
id: 5,
Expand All @@ -28,6 +23,7 @@ const testData = [
{
id: 6,
name: "Felis",
hasChildren: true,
children: [{
name: "Fatty Oscar",
}]
Expand Down
10 changes: 6 additions & 4 deletions src/lib/components/Row.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,15 @@ export default class Row extends React.Component {
nodeSize,
nodeIcon,
} = this.props;
const hasChildren = element.children && element.children.length > 0;
const showJunction = element.hasChildren

return (
<RowWrapper
first={depth === 0}
nodeSize={nodeSize}
>
<FirstColumn nodeSize={nodeSize}>
{this.renderJunction(hasChildren)}
{this.renderJunction(showJunction)}
{!isLastParent &&
<VerticalLine
nodeSize={nodeSize}
Expand All @@ -187,7 +188,7 @@ export default class Row extends React.Component {
src={nodeIcon}
nodeSize={nodeSize}
/>
{hasChildren && isExpanded ?
{showJunction && isExpanded ?
<VerticalLine
nodeSize={nodeSize}
lineWidth={lineWidth}
Expand All @@ -200,7 +201,7 @@ export default class Row extends React.Component {
</Connector>
<Node>{renderNode(element)}</Node>
</NodeWrapper>
{hasChildren && isExpanded && element.children.map((child, i) =>
{showJunction && isExpanded && element.children.map((child, i) =>
(
<Row
key={shortid.generate()}
Expand All @@ -217,6 +218,7 @@ export default class Row extends React.Component {
lineAlpha={lineAlpha}
expandButtonColor={expandButtonColor}
nodeSize={nodeSize}
nodeIcon={nodeIcon}
/>
)
)}
Expand Down