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
138 changes: 72 additions & 66 deletions src/lib/components/Row.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export default class Row extends React.Component {
expandedElements,
onNodeClick,
renderNode,
renderNodeIcon,
lineColor,
lineWidth,
lineStyle,
Expand All @@ -157,72 +158,77 @@ export default class Row extends React.Component {
} = this.props;
const hasChildren = element.children && element.children.length > 0;
return (
<RowWrapper
first={depth === 0}
nodeSize={nodeSize}
>
<FirstColumn nodeSize={nodeSize}>
{this.renderJunction(hasChildren)}
{!isLastParent &&
<VerticalLine
nodeSize={nodeSize}
lineWidth={lineWidth}
lineColor={lineColor}
lineStyle={lineStyle}
lineAlpha={lineAlpha}
/>}
</FirstColumn>
<SecondColumn>
<NodeWrapper>
<HorizontalLine
nodeSize={nodeSize}
lineWidth={lineWidth}
lineStyle={lineStyle}
lineColor={lineColor}
lineAlpha={lineAlpha}
/>
<Connector>
<NodeIcon
alt="node icon"
src={nodeIcon}
nodeSize={nodeSize}
/>
{hasChildren && isExpanded ?
<VerticalLine
nodeSize={nodeSize}
lineWidth={lineWidth}
lineColor={lineColor}
lineStyle={lineStyle}
lineAlpha={lineAlpha}
/>
:
<Separator nodeSize={nodeSize} />}
</Connector>
<Node>{renderNode(element)}</Node>
</NodeWrapper>
{hasChildren && isExpanded && element.children.map((child, i) =>
(
<Row
key={shortid.generate()}
element={child}
depth={depth + 1}
isLastParent={i === element.children.length - 1}
isExpanded={expandedElements.has(child.id)}
expandedElements={expandedElements}
onNodeClick={onNodeClick}
renderNode={renderNode}
lineColor={lineColor}
lineWidth={lineWidth}
lineStyle={lineStyle}
lineAlpha={lineAlpha}
expandButtonColor={expandButtonColor}
nodeSize={nodeSize}
nodeIcon={nodeIcon}
/>
)
)}
</SecondColumn>
</RowWrapper>
<RowWrapper first={depth === 0} nodeSize={nodeSize}>
<FirstColumn nodeSize={nodeSize}>
{this.renderJunction(hasChildren)}
{!isLastParent && (
<VerticalLine
nodeSize={nodeSize}
lineWidth={lineWidth}
lineColor={lineColor}
lineStyle={lineStyle}
lineAlpha={lineAlpha}
/>
)}
</FirstColumn>
<SecondColumn>
<NodeWrapper>
<HorizontalLine
nodeSize={nodeSize}
lineWidth={lineWidth}
lineStyle={lineStyle}
lineColor={lineColor}
lineAlpha={lineAlpha}
/>
<Connector>
{renderNodeIcon ? (
renderNodeIcon({ element, nodeIcon })
) : (
<NodeIcon
alt="node icon"
src={nodeIcon}
nodeSize={nodeSize}
/>
)}

{hasChildren && isExpanded ? (
<VerticalLine
nodeSize={nodeSize}
lineWidth={lineWidth}
lineColor={lineColor}
lineStyle={lineStyle}
lineAlpha={lineAlpha}
/>
) : (
<Separator nodeSize={nodeSize} />
)}
</Connector>
<Node>{renderNode(element)}</Node>
</NodeWrapper>
{hasChildren &&
isExpanded &&
element.children.map((child, i) => (
<Row
key={shortid.generate()}
element={child}
depth={depth + 1}
isLastParent={i === element.children.length - 1}
isExpanded={expandedElements.has(child.id)}
expandedElements={expandedElements}
onNodeClick={onNodeClick}
renderNode={renderNode}
lineColor={lineColor}
lineWidth={lineWidth}
lineStyle={lineStyle}
lineAlpha={lineAlpha}
expandButtonColor={expandButtonColor}
nodeSize={nodeSize}
nodeIcon={nodeIcon}
renderNodeIcon={renderNodeIcon}
/>
))}
</SecondColumn>
</RowWrapper>
);
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/lib/components/TreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class TreeView extends React.Component {
const {
data,
renderNode,
renderNodeIcon,
lineColor,
lineWidth,
lineStyle,
Expand Down Expand Up @@ -69,6 +70,7 @@ class TreeView extends React.Component {
expandButtonColor={expandButtonColor}
nodeSize={nodeSize}
nodeIcon={nodeIcon}
renderNodeIcon={renderNodeIcon}
/>
))}
</div>
Expand All @@ -79,6 +81,7 @@ class TreeView extends React.Component {
TreeView.propTypes = {
data: PropTypes.array.isRequired,
renderNode: PropTypes.func.isRequired,
renderNodeIcon: PropTypes.func,
lineColor: PropTypes.string,
lineWidth: PropTypes.number,
lineStyle: PropTypes.string,
Expand All @@ -95,7 +98,7 @@ TreeView.defaultProps = {
lineAlpha: 0.4,
expandButtonColor: '#4B6DAA',
nodeSize: 20,
nodeIcon: defaultNodeIcon,
nodeIcon: defaultNodeIcon
}

export default TreeView;