Skip to content

Commit d26e8da

Browse files
author
Fabian Nickel
committed
highlight
1 parent de0e9dd commit d26e8da

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

src/components/MuiTreeView/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const tree = [
1313
{
1414
value: 'Parent C',
1515
nodes: [
16-
{ value: 'Child D' },
16+
{ value: 'Child D', id: 'test' },
1717
{ value: 'Child E' },
1818
{ value: 'Child F' },
1919
],
@@ -24,8 +24,8 @@ const tree = [
2424
2525
<MuiTreeView
2626
defaultExpanded
27-
onLeafClick={(node, parent, fullPath) => alert(`${node} clicked, full path: ${JSON.stringify(fullPath)}`)}
28-
highlightItem={['Parent B', 'Parent C', 'Child D']}
27+
onLeafClick={(node) => alert(`${JSON.stringify(node)}`)}
28+
highlightId="test"
2929
tree={tree}
3030
/>
3131
```

src/components/MuiTreeView/index.jsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { Component } from 'react';
2-
import { arrayOf, shape, number, string, func, oneOfType, object } from 'prop-types';
2+
import {
3+
arrayOf,
4+
shape,
5+
number,
6+
string,
7+
func,
8+
oneOfType,
9+
object,
10+
} from 'prop-types';
311
import classNames from 'classnames';
412
import { prop } from 'ramda';
513
import memoize from 'fast-memoize';
@@ -14,7 +22,7 @@ const pickClassName = prop('className');
1422
/** Prop-type for a recursive data structure */
1523
const tree = {
1624
value: string.isRequired,
17-
id: oneOfType[string, number],
25+
id: oneOfType[(string, number)],
1826
};
1927

2028
Object.assign(tree, {
@@ -54,7 +62,7 @@ const styles = theme => ({
5462
},
5563
expandIcon: {},
5664
highlightItem: {
57-
backgroundColor: 'rgb(220, 227, 239)',
65+
backgroundColor: 'rgb(138, 138, 138)',
5866
},
5967
});
6068

@@ -76,7 +84,7 @@ class MuiTreeView extends Component {
7684
/** Properties applied to the ListItem element. */
7785
listItemProps: object,
7886
/** Id of a leaf which will be highlighted by adding the class */
79-
highlightId: oneOfType[string, number],
87+
highlightId: oneOfType[(string, number)],
8088
};
8189

8290
static defaultProps = {
@@ -96,7 +104,7 @@ class MuiTreeView extends Component {
96104
}
97105
);
98106

99-
handleLeafClick = (leaf) => {
107+
handleLeafClick = leaf => {
100108
if (this.props.onLeafClick) {
101109
this.props.onLeafClick(leaf);
102110
}
@@ -171,9 +179,7 @@ class MuiTreeView extends Component {
171179
{...expansionPanelDetailsProps}
172180
classes={{ root: classes.panelDetails }}
173181
className={classNames(pickClassName(expansionPanelDetailsProps))}>
174-
{node.nodes.map(l =>
175-
this.renderNode(l, node, depth + 1)
176-
)}
182+
{node.nodes.map(l => this.renderNode(l, node, depth + 1))}
177183
</ExpansionPanelDetails>
178184
</ExpansionPanel>
179185
);

src/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ const tree = [
3030

3131
class App extends Component {
3232
/* eslint-disable-next-line no-alert */
33-
handleLeafClick = (node, parent, fullPath) =>
33+
handleLeafClick = node =>
3434
/* eslint-disable-next-line no-alert */
35-
alert(`${node} clicked, full path: ${JSON.stringify(fullPath)}`);
35+
alert(`${JSON.stringify(node)} clicked`);
3636

3737
render() {
3838
return (

0 commit comments

Comments
 (0)