Skip to content
This repository has been archived by the owner on Oct 18, 2018. It is now read-only.

Commit

Permalink
Add content for docs (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
hckhanh committed Aug 18, 2016
1 parent b054551 commit 34399e8
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 2 deletions.
3 changes: 2 additions & 1 deletion book.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"root": "./book"
"root": "./book",
"version": "v1.1.0"
}
5 changes: 5 additions & 0 deletions book/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Summary

* [Overview](README.md)
* [Get Started](get-started/README.md)
* [Add core Data](get-started/add-core-data.md)
* [Add onChanged Listener](get-started/add-onchanged-listener.md)
* [Themes](get-started/themes.md)
* [Full Example](get-started/full-example.md)
* [License](license.md)
30 changes: 30 additions & 0 deletions book/get-started/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Get Started

## Installation

```js
npm install --save react-tree-es6
```

Keep in mind that this module has *two peer dependencies* (**reat** and **react-dom**).
It *only* support for **ES6 and above**, because I decide to move forward.
The source code from this module is written in ES6 and compiled to ES5.

Please upgrade to **{{ config.version }}** to support [jsTree API](https://www.jstree.com/api)
better than ~~v0.x~~.

## Usage

import `ReactTree` in your code:

```js
import ReactTree from 'react-tree-es6';
```

then, add to `render()` function:

```js
render() {
return (<ReactTree core={CORE} onChanged={this.handleOnChanged} />);
}
```
77 changes: 77 additions & 0 deletions book/get-started/add-core-data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Add core data

[`core`](https://www.jstree.com/api/#/?q=core) is the jsTree object contains basic
data and configurations of the tree. This is an example of `core` object:

```js
{
data: [ // data can be an array or object.
'Simple root node',
{
text: 'Root node 2',
state: {
opened: true,
selected: true
},
children: [
{
text: 'Child 1'
},
'Child 2'
]
}
]
}
```

## Node Format

As you know, *a tree has one or many nodes, each node has one or many child nodes*:

```js
// Alternative format of the node (id & parent are required)
{
id: 'string' // required
parent: 'string' // required
text: 'string' // node text
icon: 'string' // string for custom
state: {
opened: boolean // is the node open
disabled: boolean // is the node disabled
selected: boolean // is the node selected
},
li_attr: { } // attributes for the generated LI node
a_attr: { } // attributes for the generated A node
}
```

You can define a `core` object and use with `core` property:

```js
const CORE = {
data: [
'Simple root node',
{
text: 'Root node 2',
state: {
opened: true,
selected: true
},
children: [
{
text: 'Child 1'
},
'Child 2'
]
}
]
};

class ExampleApp extends React.Component {
render() {
return (<ReactTree core={CORE} />);
}
}
```

**To make sure you can find what you need, go to [jsTree API](https://www.jstree.com/api) for more details.**
30 changes: 30 additions & 0 deletions book/get-started/add-onchanged-listener.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Add onChanged Listener

This event will be triggered when a node is clicked:

```js
class ExampleApp extends React.Component {
constructor(props) {
super(props);

this.state = { items: [] };

this.handleOnChanged = this.handleOnChanged.bind(this);
}

handleOnChanged(changedItems) {
this.setState({
items: changedItems.map(item => item.text).join(', ')
});
}

render() {
return (
<div>
<ReactTree core={CORE} onChanged={this.handleOnChanged} />
<div>Selected items: {this.state.items}</div>
</div>
);
}
}
```
50 changes: 50 additions & 0 deletions book/get-started/full-example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Full Example

```js
import React from 'react';
import ReactTree from 'react-tree-es6';

const CORE = {
data: [
'Simple root node',
{
text: 'Root node 2',
state: {
opened: true,
selected: true
},
children: [
{
text: 'Child 1'
},
'Child 2'
]
}
]
};

class ExampleApp extends React.Component {
constructor(props) {
super(props);

this.state = { items: [] };

this.handleOnChanged = this.handleOnChanged.bind(this);
}

handleOnChanged(changedItems) {
this.setState({
items: changedItems.map(item => item.text).join(', ')
});
}

render() {
return (
<div>
<ReactTree core={CORE} onChanged={this.handleOnChanged} />
<div>Selected items: {this.state.items}</div>
</div>
);
}
}
```
42 changes: 42 additions & 0 deletions book/get-started/themes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Themes

If user want to apply css for **ReactTree**, consider to include these files to your web app:

* node_modules/jstree/dist/themes/**default**/style.min.css
* node_modules/jstree/dist/themes/**default-dark**/style.min.css

with additional options in `core` object, for instance with **default-dark** theme:

```js
const CORE = {
data: [
'Simple root node',
{
text: 'Root node 2',
state: {
opened: true,
selected: true
},
children: [
{
text: 'Child 1'
},
'Child 2'
]
}
],
themes: {
name: 'default-dark'
}
};
```

If you are using React ES6 with [webpack](https://github.com/webpack/webpack),
you can add these themes easily by using [css-loader](https://github.com/webpack/css-loader):

```js
import 'node_modules/jstree/dist/themes/default/style.min.css';
import 'node_modules/jstree/dist/themes/default-dark/style.min.css';
```

*You only need to `import` these themes one time.*
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
"main": "./lib/react-tree.js",
"scripts": {
"start": "webpack-dev-server --port=3000",
"start-docs":"gitbook serve",
"test": "jest",
"test-coverage": "jest && codecov",
"build": "babel src --out-dir lib"
"build": "babel src --out-dir lib",
"build-docs":"gitbook build"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 34399e8

Please sign in to comment.