Skip to content
This repository has been archived by the owner on May 14, 2020. It is now read-only.

Commit

Permalink
Merge pull request #29 from goloveychuk/master
Browse files Browse the repository at this point in the history
added hideRoot prop
  • Loading branch information
chibicode committed Feb 19, 2016
2 parents eb4a631 + e14e090 commit e5ab132
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ In this example the label and value will be rendered with `<strong>` and `<em>`
#### More Options
- Add `expandAll` property to expand all nodes.
- Add `hideRoot={true}` to hide a root node.
### Credits
- All credits to [Dave Vedder](http://www.eskimospy.com/) ([[email protected]](mailto:[email protected])), who wrote the original code as [JSONViewer](https://bitbucket.org/davevedder/react-json-viewer/).
Expand Down
2 changes: 1 addition & 1 deletion src/JSONObjectNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function renderItemString({

// Returns the child nodes for each entry in iterable.
// If we have generated them previously we return from cache; otherwise we create them.
function getChildNodes({
export function getChildNodes({
data,
getItemString,
labelRenderer,
Expand Down
46 changes: 32 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import React from 'react';
import grabNode from './grab-node';
import solarized from './themes/solarized';
import {getChildNodes} from './JSONObjectNode';

const styles = {
tree: {
Expand All @@ -30,12 +31,14 @@ export default class JSONTree extends React.Component {
data: React.PropTypes.oneOfType([
React.PropTypes.array,
React.PropTypes.object
]).isRequired
]).isRequired,
hideRoot: React.PropTypes.bool
};

static defaultProps = {
expandRoot: true,
expandAll: false,
hideRoot: false,
keyName: 'root',
theme: solarized,
getArrowStyle: getEmptyStyle,
Expand Down Expand Up @@ -73,25 +76,40 @@ export default class JSONTree extends React.Component {
theme
} = this.props;

const rootNode = grabNode({
getItemString,
initialExpanded,
allExpanded,
key,
previousData,
styles: getStyles,
theme,
labelRenderer,
value,
valueRenderer
});
var nodeToRender;

if (!this.props.hideRoot) {
nodeToRender = grabNode({
getItemString,
initialExpanded,
allExpanded,
key,
previousData,
styles: getStyles,
theme,
labelRenderer,
value,
valueRenderer
});
} else {
nodeToRender = getChildNodes({
data: value,
getItemString,
labelRenderer,
previousData,
styles:getStyles,
theme,
valueRenderer,
allExpanded
});
}

return (
<ul style={{
...styles.tree,
...this.props.style
}}>
{rootNode}
{nodeToRender}
</ul>
);
}
Expand Down

0 comments on commit e5ab132

Please sign in to comment.