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
2 changes: 2 additions & 0 deletions src/components/MuiTreeView/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const tree = [
<MuiTreeView
defaultExpanded
onLeafClick={node => alert(JSON.stringify(node))}
highlightId="example-id"
// highlightClass="highlightedClass"
tree={tree}
/>
```
23 changes: 23 additions & 0 deletions src/components/MuiTreeView/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ const styles = theme => ({
maxWidth: '75vw',
},
expandIcon: {},
highlightItem: {
backgroundColor: 'rgb(138, 138, 138)',
},
});

/**
Expand All @@ -82,6 +85,12 @@ class MuiTreeView extends Component {
expansionPanelDetailsProps: object,
/** Properties applied to the ListItem element. */
listItemProps: object,
/** Id of a leaf which will be highlighted by adding the class highlightItem
* or a style given by the hightlightStyle prop.
*/
highlightId: oneOfType([string, number]),
/* styling of the highlighted item */
highlightClass: string,
};

static defaultProps = {
Expand All @@ -90,6 +99,7 @@ class MuiTreeView extends Component {
expansionPanelSummaryProps: null,
expansionPanelDetailsProps: null,
listItemProps: null,
highlightClass: null,
};

createFilteredTree = memoize(
Expand Down Expand Up @@ -117,11 +127,23 @@ class MuiTreeView extends Component {
expansionPanelSummaryProps,
expansionPanelDetailsProps,
listItemProps,
highlightId,
highlightClass,
...props
} = this.props;
const value = this.getNodeValue(node);
const id = this.getNodeId(node);
const isLeaf = this.isLeaf(node);
let additionalClasses = {};

if (highlightId === node.id) {
if (highlightClass) {
additionalClasses = { root: highlightClass };
} else {
additionalClasses = { root: classes.highlightItem };
}
}

const textIndent = isLeaf
? depth * unit + unit + (parent ? unit : 0)
: unit * depth + unit;
Expand All @@ -140,6 +162,7 @@ class MuiTreeView extends Component {
value={value}
onClick={() => this.handleLeafClick({ value, parent, id })}
button
classes={additionalClasses}
{...listItemProps}>
<div className={classes.text}>{value}</div>
</ListItem>
Expand Down