Skip to content

Commit

Permalink
(doc) add docz documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanBaptisteWATENBERG committed Sep 6, 2018
1 parent da6eb17 commit 1f6905f
Show file tree
Hide file tree
Showing 7 changed files with 13,662 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/node_modules
/umd
npm-debug.log*
.docz
12 changes: 12 additions & 0 deletions doczrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { css } from 'docz-plugin-css';
import { svgr } from 'docz-plugin-svgr';

export default {
themeConfig: {
mode: 'dark'
},
plugins: [
svgr(),
css()
]
};
12 changes: 6 additions & 6 deletions nwb.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
type: 'react-component',
npm: {
esModules: true,
umd: false
}
}
type: 'react-component',
npm: {
esModules: true,
umd: false
}
};
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@
"start": "nwb serve-react-demo",
"test": "nwb test-react",
"test:coverage": "nwb test-react --coverage",
"test:watch": "nwb test-react --server"
"test:watch": "nwb test-react --server",
"docz:dev": "docz dev",
"docz:build": "docz build"
},
"dependencies": {
"easy-json-schema": "0.0.2-beta",
"jsoneditor": "^5.16.0",
"jsonpath": "^1.0.0"
"jsonpath": "^1.0.0",
"prop-types": "^15.6.2"
},
"peerDependencies": {
"react": "16.x"
},
"devDependencies": {
"docz": "^0.11.0",
"docz-plugin-css": "^0.11.0",
"docz-plugin-svgr": "^0.11.0",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"eslint": "^5.3.0",
Expand Down
22 changes: 21 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, {Component} from 'react';
import Editor from './components/Editor';
import PropTypes from 'prop-types';

/**
* props :
Expand All @@ -9,7 +10,7 @@ import Editor from './components/Editor';
* - json? -- json to edit
* - editorPosition? -- {x,y} overrides the position of the editor
*/
export default class extends Component {
class ReactJsonPath extends Component {

constructor(props) {
super(props);
Expand Down Expand Up @@ -114,3 +115,22 @@ export default class extends Component {
</React.Fragment>;
}
}

ReactJsonPath.propTypes = {
/** Properties to set on input tag */
inputProps: PropTypes.object,
/** Input value */
value: PropTypes.string,
/** Function called when input value change */
onChange: PropTypes.func,
/** Json to edit */
json: PropTypes.object,
/** {x,y} overrides the position of the editor */
editorPosition: PropTypes.exact({
x: PropTypes.number,
y: PropTypes.number
}),
};


export default ReactJsonPath;
94 changes: 94 additions & 0 deletions src/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
name: react-json-editor
route: /
---

import { Playground, PropsTable } from 'docz'
import JsonPathEditor from './';

# React JSON Path editor

[![Travis][build-badge]][build] &nbsp;&nbsp;
[![npm package][npm-badge]][npm] &nbsp;&nbsp;
[![Coveralls][coveralls-badge]][coveralls]

A react component that enables simple jsonpath editing by providing autocompletion and preview evaluation in a JSON editor

<PropsTable of={JsonPathEditor} />

## Basic usage

The editor won't be displayed rigth under the field due to the offset of the playground

<Playground>
<JsonPathEditor/>
</Playground>

## With editor position

With editor position fixing the display issue when the component is encapsulated

<Playground>
<JsonPathEditor editorPosition={{ x: 31, y: 55 }}/>
</Playground>

## With a default value

<Playground>
<JsonPathEditor value='$.' editorPosition={{ x: 31, y: 55 }}/>
</Playground>

## With a prop

<Playground>
<JsonPathEditor inputProps={{style: {background: 'black', color: 'white'}}} editorPosition={{ x: 31, y: 55 }}/>
</Playground>


## With a callback on change

<Playground>
<JsonPathEditor onChange={(newValue) => { console.log(newValue) }} editorPosition={{ x: 31, y: 55 }}/>
</Playground>

## With a json

<Playground>
<JsonPathEditor json={{
"data": [{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!",
"body": "The shortest article. Ever.",
"created": "2015-05-22T14:56:29.000Z",
"updated": "2015-05-22T14:56:28.000Z"
},
"relationships": {
"author": {
"data": {"id": "42", "type": "people"}
}
}
}],
"included": [
{
"type": "people",
"id": "42",
"attributes": {
"name": "John",
"age": 80,
"gender": "male"
}
}
]
}} editorPosition={{ x: 31, y: 55 }}/>
</Playground>

[build-badge]: https://img.shields.io/travis/JeanBaptisteWATENBERG/react-jsonpath-editor/master.png?style=flat-square
[build]: https://travis-ci.org/JeanBaptisteWATENBERG/react-jsonpath-editor

[npm-badge]: https://img.shields.io/npm/v/react-jsonpath-editor.png?style=flat-square
[npm]: https://www.npmjs.com/package/react-jsonpath-editor

[coveralls-badge]: https://img.shields.io/coveralls/JeanBaptisteWATENBERG/react-jsonpath-editor/master.png?style=flat-square
[coveralls]: https://coveralls.io/github/JeanBaptisteWATENBERG/react-jsonpath-editor
Loading

0 comments on commit 1f6905f

Please sign in to comment.