Skip to content

Commit 130d33e

Browse files
committed
Update README.md
1 parent d221acd commit 130d33e

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44

55
A [React](https://github.com/facebook/react) component for editing or viewing JSON/object data
66

7+
**[Explore the Demo](https://carlosnz.github.io/json-edit-react/)**
8+
9+
![NPM Version](https://img.shields.io/npm/v/json-edit-react)
10+
![GitHub License](https://img.shields.io/github/license/carlosnz/json-edit-react)
11+
![NPM Downloads](https://img.shields.io/npm/dm/json-edit-react)
12+
713
> [!IMPORTANT]
814
> **Version 1.14.0** has a change which recommends you provide a `setData` prop and not use `onUpdate` for updating your data externally. See [Managing state](#managing-state).
915
10-
Features include:
16+
### Features include:
1117

1218
- edit individual values, or whole objects as JSON text
1319
- fine-grained control over which elements can be edited, deleted, or added to
@@ -19,8 +25,6 @@ Features include:
1925
- [localisable](#localisation) UI
2026
- **NEW!** [Drag-n-drop](#drag-n-drop) editing! (*experimental*)
2127

22-
**[Explore the Demo](https://carlosnz.github.io/json-edit-react/)**
23-
2428
<img width="392" alt="screenshot" src="image/screenshot.png">
2529

2630
- [Installation](#installation)
@@ -213,7 +217,7 @@ Normally, the component will display simple error messages whenever an error con
213217
}
214218
}
215219
```
216-
(An example of a custom Error UI can be seen in the [Demo](#https://carlosnz.github.io/json-edit-react/) with the "Custom Nodes" data set -- when you enter invalid JSON input a "Toast" notification is displayed instead of the normal component error message.)
220+
(An example of a custom Error UI can be seen in the [Demo](#https://carlosnz.github.io/json-edit-react/?data=customNodes) with the "Custom Nodes" data set -- when you enter invalid JSON input a "Toast" notification is displayed instead of the normal component error message.)
217221

218222
### Copy function
219223

@@ -308,7 +312,7 @@ restrictTypeSelection = { ({ path, value }) => {
308312

309313
### JSON Schema validation
310314

311-
As well as dynamically controlling *access* to the various edit tools as described above, it's possible to do full [JSON Schema](https://json-schema.org/) validation by creating an [Update Function](#update-functions) that passes the data to a 3rd-party schema validation library (e.g. [Ajv](https://ajv.js.org/)). This will then reject any invalid input, and display an error in the UI (or via a custom [onError](#onerror-function) function). You can see an example of this in the [Demo](https://carlosnz.github.io/json-edit-react/) with the "JSON Schema Validation" data set (and the "Custom Nodes" data set).
315+
As well as dynamically controlling *access* to the various edit tools as described above, it's possible to do full [JSON Schema](https://json-schema.org/) validation by creating an [Update Function](#update-functions) that passes the data to a 3rd-party schema validation library (e.g. [Ajv](https://ajv.js.org/)). This will then reject any invalid input, and display an error in the UI (or via a custom [onError](#onerror-function) function). You can see an example of this in the [Demo](https://carlosnz.github.io/json-edit-react/?data=jsonSchemaValidation) with the "JSON Schema Validation" data set (and the "Custom Nodes" data set).
312316

313317
An example `onUpdate` validation function (using Ajv) could be something like this:
314318

@@ -372,7 +376,7 @@ You can specify what should be matched by setting `searchFilter` to either `"key
372376
373377
There are two helper functions (`matchNode()` and `matchNodeKey()`) exported with the package that might make creating your search function easier (these are the functions used internally for the `"key"` and `"value"` matches described above). You can see what they do [here](https://github.com/CarlosNZ/json-edit-react/blob/574f2c1ba3e724c93ce8ab9cdba2fe8ebbbbf806/src/filterHelpers.ts#L64-L95).
374378
375-
An example custom search function can be seen in the [Demo](#https://carlosnz.github.io/json-edit-react/) with the "Client list" data set -- the search function matches by name and username, and makes the entire "Client" object visible when one of those matches, so it can be used to find a particular person and edit their specific details:
379+
An example custom search function can be seen in the [Demo](#https://carlosnz.github.io/json-edit-react/?data=jsonPlaceholder) with the "Client list" data set -- the search function matches by name and username, and makes the entire "Client" object visible when one of those matches, so it can be used to find a particular person and edit their specific details:
376380
377381
```js
378382
({ path, fullData }, searchText) => {
@@ -542,7 +546,7 @@ Localise your implementation by passing in a `translations` object to replace th
542546
543547
## Custom Nodes
544548
545-
You can replace certain nodes in the data tree with your own custom components. An example might be for an image display, or a custom date editor, or just to add some visual bling. See the "Custom Nodes" data set in the [interactive demo](https://carlosnz.github.io/json-edit-react/) to see it in action. (There is also a custom Date picker that appears when editing ISO strings in the other data sets.)
549+
You can replace certain nodes in the data tree with your own custom components. An example might be for an image display, or a custom date editor, or just to add some visual bling. See the "Custom Nodes" data set in the [interactive demo](https://carlosnz.github.io/json-edit-react/?data=customNodes) to see it in action. (There is also a custom Date picker that appears when editing ISO strings in the other data sets.)
546550
547551
Custom nodes are provided in the `customNodeDefinitions` prop, as an array of objects of following structure:
548552
@@ -594,7 +598,7 @@ return (
594598
595599
### Custom Collection nodes
596600
597-
In most cases it will be preferable (and simpler) to create custom nodes to match *value* nodes (i.e. not `array` or `object` *collection* nodes), which is what all the [Demo](https://carlosnz.github.io/json-edit-react/) examples show. However, if you *do* wish to target a whole collection node, there are a couple of other things to know:
601+
In most cases it will be preferable (and simpler) to create custom nodes to match *value* nodes (i.e. not `array` or `object` *collection* nodes), which is what all the [Demo](https://carlosnz.github.io/json-edit-react/?data=customNodes) examples show. However, if you *do* wish to target a whole collection node, there are a couple of other things to know:
598602
- The normal descendants of this node can still be displayed using the [React `children`](https://react.dev/learn/passing-props-to-a-component#passing-jsx-as-children) property, it just becomes your component's responsibility to handle it.
599603
- You can specify two different components in the definition:
600604
- the regular `element` prop, which will be displayed *inside* the collection brackets (i.e. it appears as the *contents* of the collection)
@@ -605,7 +609,7 @@ In most cases it will be preferable (and simpler) to create custom nodes to matc
605609
606610
## Custom Text
607611
608-
It's possible to change the various text strings displayed by the component. You can [localise it](#localisation), but you can also specify functions to override the displayed text based on certain conditions. For example, say we want the property count text (e.g. `6 items` by default) to give a summary of a certain type of node, which can look nice when collapsed. For example (taken from the [Demo](https://carlosnz.github.io/json-edit-react/)):
612+
It's possible to change the various text strings displayed by the component. You can [localise it](#localisation), but you can also specify functions to override the displayed text based on certain conditions. For example, say we want the property count text (e.g. `6 items` by default) to give a summary of a certain type of node, which can look nice when collapsed. For example (taken from the [Demo](https://carlosnz.github.io/json-edit-react/?data=customNodes)):
609613
610614
<img width="391" alt="Custom text example" src="image/custom_text.png">
611615

0 commit comments

Comments
 (0)