Skip to content

Commit

Permalink
TreeView updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
emirhankudevi committed May 6, 2019
1 parent 2535c6b commit e91722c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 9 deletions.
15 changes: 12 additions & 3 deletions packages/components/src/TreeView/TreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ class TreeView extends ComponentBase {
* Row height of the treeview nodes.
*/
rowHeight: PropTypes.oneOfType([PropTypes.number]),

/**
* If `false`, the parent node hasn't icon.
*/
showFolderIcon: PropTypes.bool,
/**
* If `true`, footer of the treeview is visible.
*/
Expand All @@ -88,6 +93,7 @@ class TreeView extends ComponentBase {
* Width of the treeview.
*/
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),

};

static defaultProps = {
Expand All @@ -104,6 +110,7 @@ class TreeView extends ComponentBase {
showIcons: true,
showSearch: true,
canCheckChildsByParent: true,
showFolderIcon: true,
};

state = {
Expand Down Expand Up @@ -239,6 +246,8 @@ class TreeView extends ComponentBase {
{this.props.showIcons && (
<NodeIcon
state={toggleState}
hasChildren={hasChildren}
showFolderIcon={this.props.showFolderIcon}
context={this.props.context}
icon={node.icon}
rowHeight={this.props.rowHeight}
Expand Down Expand Up @@ -274,8 +283,8 @@ class TreeView extends ComponentBase {
</span>
</span>
) : (
this.highlightSearchTerm(node)
)}
this.highlightSearchTerm(node)
)}
</span>
</TreeNode>
);
Expand All @@ -285,7 +294,7 @@ class TreeView extends ComponentBase {
// eslint-disable-next-line max-len
return `<span style="color: ${
this.props.context.theme.boaPalette.pri500
}; background-color: #b618ce29">${match}</span>`;
}; background-color: #b618ce29">${match}</span>`;
}

highlightSearchTerm(node) {
Expand Down
8 changes: 5 additions & 3 deletions packages/components/src/TreeView/components/NodeIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ class NodeIcon extends ComponentBase {
content = this.props.icon;
} else if (this.props.icon) {
content = Icon.getIcon(this.props.icon);
} else {
} else if (this.props.hasChildren && this.props.showFolderIcon) {
content = (
<div>
{{
opened: <FolderOpen style={{ color: this.props.context.theme.boaPalette.pri500 }} />,
closed: <FolderSpecial style={{ color: this.props.context.theme.boaPalette.pri500 }} />,
}[this.props.state] || (
<FolderSpecial style={{ color: this.props.context.theme.boaPalette.pri500 }} />
)}
<FolderSpecial style={{ color: this.props.context.theme.boaPalette.pri500 }} />
)}
</div>
);
} else {
content = (<div />);
}
return <div style={this.getStyle()}>{content}</div>;
}
Expand Down
39 changes: 36 additions & 3 deletions packages/components/src/TreeView/components/NodeIcon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ describe('TreeView:NodeIcon', () => {
});

it('should render opened', () => {
const wrapper = shallow(<NodeIcon state="opened" context={context} rowHeight={10} />);
const wrapper = shallow(
<NodeIcon
state="opened"
context={context}
rowHeight={10}
showFolderIcon
hasChildren />);
assert.strictEqual(
wrapper
.childAt(0)
Expand All @@ -41,7 +47,13 @@ describe('TreeView:NodeIcon', () => {
});

it('should render closed', () => {
const wrapper = shallow(<NodeIcon state="closed" context={context} rowHeight={10} />);
const wrapper = shallow(
<NodeIcon
state="closed"
context={context}
rowHeight={10}
showFolderIcon
hasChildren />);
assert.strictEqual(
wrapper
.childAt(0)
Expand All @@ -52,7 +64,12 @@ describe('TreeView:NodeIcon', () => {
});

it('should render default', () => {
const wrapper = shallow(<NodeIcon context={context} rowHeight={10} />);
const wrapper = shallow(
<NodeIcon
context={context}
rowHeight={10}
showFolderIcon
hasChildren />);
assert.strictEqual(
wrapper
.childAt(0)
Expand All @@ -62,6 +79,22 @@ describe('TreeView:NodeIcon', () => {
);
});


it('should render noFolderIcon', () => {
const wrapper = shallow(
<NodeIcon
context={context}
rowHeight={10}
showFolderIcon={false}
hasChildren={false} />);
assert.strictEqual(
wrapper
.childAt(0)
.type(),
'div',
);
});

it('should render dynamicIcon', () => {
const wrapper = shallow(
<NodeIcon context={context} icon={{ dynamicIcon: 'Home' }} rowHeight={10} />,
Expand Down
11 changes: 11 additions & 0 deletions stories/TreeView/doc.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,17 @@
"computed": false
}
},
"showFolderIcon": {
"type": {
"name": "bool"
},
"required": false,
"description": "If `false`, the parent node hasn't icon.",
"defaultValue": {
"value": true,
"computed": true
}
},
"footerStyle": {
"type": {
"name": "object"
Expand Down

0 comments on commit e91722c

Please sign in to comment.