Skip to content

Commit 1f6905f

Browse files
(doc) add docz documentation
1 parent da6eb17 commit 1f6905f

File tree

7 files changed

+13662
-9
lines changed

7 files changed

+13662
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
/node_modules
66
/umd
77
npm-debug.log*
8+
.docz

doczrc.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { css } from 'docz-plugin-css';
2+
import { svgr } from 'docz-plugin-svgr';
3+
4+
export default {
5+
themeConfig: {
6+
mode: 'dark'
7+
},
8+
plugins: [
9+
svgr(),
10+
css()
11+
]
12+
};

nwb.config.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
2-
type: 'react-component',
3-
npm: {
4-
esModules: true,
5-
umd: false
6-
}
7-
}
2+
type: 'react-component',
3+
npm: {
4+
esModules: true,
5+
umd: false
6+
}
7+
};

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,23 @@
1616
"start": "nwb serve-react-demo",
1717
"test": "nwb test-react",
1818
"test:coverage": "nwb test-react --coverage",
19-
"test:watch": "nwb test-react --server"
19+
"test:watch": "nwb test-react --server",
20+
"docz:dev": "docz dev",
21+
"docz:build": "docz build"
2022
},
2123
"dependencies": {
2224
"easy-json-schema": "0.0.2-beta",
2325
"jsoneditor": "^5.16.0",
24-
"jsonpath": "^1.0.0"
26+
"jsonpath": "^1.0.0",
27+
"prop-types": "^15.6.2"
2528
},
2629
"peerDependencies": {
2730
"react": "16.x"
2831
},
2932
"devDependencies": {
33+
"docz": "^0.11.0",
34+
"docz-plugin-css": "^0.11.0",
35+
"docz-plugin-svgr": "^0.11.0",
3036
"enzyme": "^3.3.0",
3137
"enzyme-adapter-react-16": "^1.1.1",
3238
"eslint": "^5.3.0",

src/index.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, {Component} from 'react';
22
import Editor from './components/Editor';
3+
import PropTypes from 'prop-types';
34

45
/**
56
* props :
@@ -9,7 +10,7 @@ import Editor from './components/Editor';
910
* - json? -- json to edit
1011
* - editorPosition? -- {x,y} overrides the position of the editor
1112
*/
12-
export default class extends Component {
13+
class ReactJsonPath extends Component {
1314

1415
constructor(props) {
1516
super(props);
@@ -114,3 +115,22 @@ export default class extends Component {
114115
</React.Fragment>;
115116
}
116117
}
118+
119+
ReactJsonPath.propTypes = {
120+
/** Properties to set on input tag */
121+
inputProps: PropTypes.object,
122+
/** Input value */
123+
value: PropTypes.string,
124+
/** Function called when input value change */
125+
onChange: PropTypes.func,
126+
/** Json to edit */
127+
json: PropTypes.object,
128+
/** {x,y} overrides the position of the editor */
129+
editorPosition: PropTypes.exact({
130+
x: PropTypes.number,
131+
y: PropTypes.number
132+
}),
133+
};
134+
135+
136+
export default ReactJsonPath;

src/index.mdx

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
name: react-json-editor
3+
route: /
4+
---
5+
6+
import { Playground, PropsTable } from 'docz'
7+
import JsonPathEditor from './';
8+
9+
# React JSON Path editor
10+
11+
[![Travis][build-badge]][build] &nbsp;&nbsp;
12+
[![npm package][npm-badge]][npm] &nbsp;&nbsp;
13+
[![Coveralls][coveralls-badge]][coveralls]
14+
15+
A react component that enables simple jsonpath editing by providing autocompletion and preview evaluation in a JSON editor
16+
17+
<PropsTable of={JsonPathEditor} />
18+
19+
## Basic usage
20+
21+
The editor won't be displayed rigth under the field due to the offset of the playground
22+
23+
<Playground>
24+
<JsonPathEditor/>
25+
</Playground>
26+
27+
## With editor position
28+
29+
With editor position fixing the display issue when the component is encapsulated
30+
31+
<Playground>
32+
<JsonPathEditor editorPosition={{ x: 31, y: 55 }}/>
33+
</Playground>
34+
35+
## With a default value
36+
37+
<Playground>
38+
<JsonPathEditor value='$.' editorPosition={{ x: 31, y: 55 }}/>
39+
</Playground>
40+
41+
## With a prop
42+
43+
<Playground>
44+
<JsonPathEditor inputProps={{style: {background: 'black', color: 'white'}}} editorPosition={{ x: 31, y: 55 }}/>
45+
</Playground>
46+
47+
48+
## With a callback on change
49+
50+
<Playground>
51+
<JsonPathEditor onChange={(newValue) => { console.log(newValue) }} editorPosition={{ x: 31, y: 55 }}/>
52+
</Playground>
53+
54+
## With a json
55+
56+
<Playground>
57+
<JsonPathEditor json={{
58+
"data": [{
59+
"type": "articles",
60+
"id": "1",
61+
"attributes": {
62+
"title": "JSON API paints my bikeshed!",
63+
"body": "The shortest article. Ever.",
64+
"created": "2015-05-22T14:56:29.000Z",
65+
"updated": "2015-05-22T14:56:28.000Z"
66+
},
67+
"relationships": {
68+
"author": {
69+
"data": {"id": "42", "type": "people"}
70+
}
71+
}
72+
}],
73+
"included": [
74+
{
75+
"type": "people",
76+
"id": "42",
77+
"attributes": {
78+
"name": "John",
79+
"age": 80,
80+
"gender": "male"
81+
}
82+
}
83+
]
84+
}} editorPosition={{ x: 31, y: 55 }}/>
85+
</Playground>
86+
87+
[build-badge]: https://img.shields.io/travis/JeanBaptisteWATENBERG/react-jsonpath-editor/master.png?style=flat-square
88+
[build]: https://travis-ci.org/JeanBaptisteWATENBERG/react-jsonpath-editor
89+
90+
[npm-badge]: https://img.shields.io/npm/v/react-jsonpath-editor.png?style=flat-square
91+
[npm]: https://www.npmjs.com/package/react-jsonpath-editor
92+
93+
[coveralls-badge]: https://img.shields.io/coveralls/JeanBaptisteWATENBERG/react-jsonpath-editor/master.png?style=flat-square
94+
[coveralls]: https://coveralls.io/github/JeanBaptisteWATENBERG/react-jsonpath-editor

0 commit comments

Comments
 (0)