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

Commit 57d39d9

Browse files
committed
Update documentation
1 parent f621ce8 commit 57d39d9

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,56 @@ const theme = {
6767

6868
![](http://cl.ly/image/330o2L1J3V0h/screenshot%202015-08-26%20at%2010.48.24%20AM.png)
6969

70+
### Customization
71+
72+
#### Customize CSS
73+
74+
You can pass the following properties to customize styling (all optional):
75+
76+
```js
77+
<JSONTree getArrowStyle={(type, expanded) => ({})}
78+
getItemStringStyle={(type, expanded) => ({})}
79+
getListStyle={(type, expanded) => ({})}
80+
getLabelStyle={(type, expanded) => ({})}
81+
getValueStyle={(type, expanded) => ({})} />
82+
```
83+
84+
Here `type` is a string representing type of data, `expanded` is a current state for expandable items. Each function returns a style object, which extends corresponding default style.
85+
86+
For example, if you pass the following function:
87+
88+
```js
89+
const getStyle = (type, expanded) =>
90+
(expanded ? { textTransform: 'uppercase' } :
91+
{ textTransform: 'lowercase' });
92+
```
93+
94+
Then expanded nodes will all be in uppercase:
95+
96+
![](http://cl.ly/image/460Y0P3C453Q/screenshot%202015-10-07%20at%203.38.33%20PM.png)
97+
98+
#### Customize Labels for Arrays, Objects, and Iterables
99+
100+
You can pass `getItemString` to customize the way arrays, objects, and iterable nodes are displayed (optional).
101+
102+
By default, it'll be:
103+
104+
```js
105+
<JSONTree getArrowStyle={(type, data, itemType, itemString)
106+
=> <span>{itemType} {itemString}</span>}
107+
```
108+
109+
But if you pass the following:
110+
111+
```js
112+
const getItemString = (type, data, itemType, itemString)
113+
=> (<span> // {type}</span>);
114+
```
115+
116+
Then the preview of child elements now look like this:
117+
118+
![](http://cl.ly/image/1J1a0b0T0K3c/screenshot%202015-10-07%20at%203.44.31%20PM.png)
119+
70120
### Credits
71121
72122
- All credits to [Dave Vedder](http://www.eskimospy.com/) ([veddermatic@gmail.com](mailto:veddermatic@gmail.com)), who wrote the original code as [JSONViewer](https://bitbucket.org/davevedder/react-json-viewer/).

examples/src/App.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,33 @@ export default class App extends Component {
3636
base0F: '#cc6633'
3737
};
3838

39+
const getStyle = (type, expanded) => {};
40+
const getItemString = (type, data, itemType, itemString) => (<span> // {type}</span>);
41+
3942
return (
4043
<div>
4144
<JSONTree data={ data } />
4245
<br />
46+
<h3>Dark Theme</h3>
4347
<div style={{ backgroundColor: theme.base00 }}>
4448
<JSONTree data={ data } theme={ theme } />
4549
</div>
50+
<br />
51+
<h3>Style Customization</h3>
52+
<ul>
53+
<li>Text changes between uppercase/lowercase based on the expanded state.</li>
54+
<li>The labels of objects, arrays, and iterables are customized as "// type".</li>
55+
<li>See code for details.</li>
56+
</ul>
57+
<div>
58+
<JSONTree data={ data } theme={ theme }
59+
getArrowStyle={ getStyle }
60+
getItemStringStyle={ getStyle }
61+
getListStyle={ getStyle }
62+
getLabelStyle={ getStyle }
63+
getValueStyle={ getStyle }
64+
getItemString={ getItemString }/>
65+
</div>
4666
</div>
4767
);
4868
}

0 commit comments

Comments
 (0)