@@ -10,7 +10,7 @@ The wrapper of jsTree (jstree.com) for React
1010## Getting Started
1111
1212If you want to find a ** tree view** component for React, this module is what you need.
13- It supports ** ES6** and backward compatible with ** ES5** .
13+ ** It supports ES6 and backward compatible with ES5. **
1414
1515## Installation
1616
@@ -26,27 +26,33 @@ import/require `ReactTree` to your React source code:
2626import ReactTree from ' react-tree-es6' ;
2727```
2828
29- ### tree
29+ ### core
3030
31- ** tree** is the node object or and array of node object. This is an example of data of a node:
31+ ` core ` is the jsTree object contains basic data and configurations of the tree.
32+ This is an example of ` core ` object:
3233
3334``` js
3435{
35- text: ' Root node 2' ,
36- state: {
37- opened: true ,
38- selected: true
39- },
40- children: [
36+ data: [ // data can be an array or object.
37+ ' Simple root node' ,
4138 {
42- text: ' Child 1'
43- },
44- ' Child 2'
39+ text: ' Root node 2' ,
40+ state: {
41+ opened: true ,
42+ selected: true
43+ },
44+ children: [
45+ {
46+ text: ' Child 1'
47+ },
48+ ' Child 2'
49+ ]
50+ }
4551 ]
4652}
4753```
4854
49- Here is the full structure of a node:
55+ As you know, a tree has one or many nodes, here is the full structure of a node:
5056
5157``` js
5258// Alternative format of the node (id & parent are required)
@@ -65,54 +71,60 @@ Here is the full structure of a node:
6571}
6672```
6773
68- You can define a tree and then parse it to ` tree ` property:
74+ You can define a ` core ` object and then parse it to ` core ` property:
6975
7076``` js
71- const TREE = [
72- ' Simple root node' ,
73- {
74- text: ' Root node 2' ,
75- state: {
76- opened: true ,
77- selected: true
78- },
79- children: [
80- {
81- text: ' Child 1'
77+ const CORE = {
78+ data: [
79+ ' Simple root node' ,
80+ {
81+ text: ' Root node 2' ,
82+ state: {
83+ opened: true ,
84+ selected: true
8285 },
83- ' Child 2'
84- ]
85- }
86- ];
86+ children: [
87+ {
88+ text: ' Child 1'
89+ },
90+ ' Child 2'
91+ ]
92+ }
93+ ]
94+ };
8795
8896class ExampleApp extends React .Component {
8997 render () {
90- return (< ReactTree tree = { TREE } / > );
98+ return (< ReactTree core = { CORE } / > );
9199 }
92100}
93101```
94102
103+ > To make sure you can find what you need, go to [ jsTree API] ( https://www.jstree.com/api ) for more details.
104+
95105### onChanged
96106
97107This is an event to handle when a node is clicked:
98108
99109``` js
100- const TREE = [
101- ' Simple root node' ,
102- {
103- text: ' Root node 2' ,
104- state: {
105- opened: true ,
106- selected: true
107- },
108- children: [
109- {
110- text: ' Child 1'
110+ const CORE = {
111+ data: [
112+ ' Simple root node' ,
113+ {
114+ text: ' Root node 2' ,
115+ state: {
116+ opened: true ,
117+ selected: true
111118 },
112- ' Child 2'
113- ]
114- }
115- ];
119+ children: [
120+ {
121+ text: ' Child 1'
122+ },
123+ ' Child 2'
124+ ]
125+ }
126+ ]
127+ };
116128
117129class ExampleApp extends React .Component {
118130 constructor (props ) {
@@ -132,7 +144,7 @@ class ExampleApp extends React.Component {
132144 render () {
133145 return (
134146 < div>
135- < ReactTree tree = { TREE } onChanged= {this .handleOnChanged } / >
147+ < ReactTree core = { CORE } onChanged= {this .handleOnChanged } / >
136148 < div> Selected items: {this .state .items }< / div>
137149 < / div>
138150 );
@@ -144,11 +156,37 @@ If you need detailed example, go to [example](example) folder.
144156
145157### Themes
146158
147- If user want to apply css for ** ReactTree** , consider to include these files:
159+ If user want to apply css for ** ReactTree** , consider to include these files to your web app :
148160
149161* node_modules/jstree/dist/themes/default/style.min.css
150162* node_modules/jstree/dist/themes/default-dark/style.min.css
151163
164+ with additional options in ` core ` object, for instance with ** default-dark** theme:
165+
166+ ``` js
167+ const CORE = {
168+ data: [
169+ ' Simple root node' ,
170+ {
171+ text: ' Root node 2' ,
172+ state: {
173+ opened: true ,
174+ selected: true
175+ },
176+ children: [
177+ {
178+ text: ' Child 1'
179+ },
180+ ' Child 2'
181+ ]
182+ }
183+ ],
184+ themes: {
185+ name: ' default-dark'
186+ }
187+ };
188+ ```
189+
152190## License
153191
154192MIT (< http://www.opensource.org/licenses/mit-license.php > )
0 commit comments