You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -918,8 +919,9 @@ Your `translations` object doesn't have to be exhaustive — only define the key
918
919
919
920
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.)
920
921
921
-
> [!NOTE]
922
-
> Coming soon: a **Custom Component** library
922
+
> [!TIP]
923
+
> There are a selection of useful Custom components ready for you to use in my [Custom Component Library](https://github.com/CarlosNZ/json-edit-react/blob/main/custom-component-library/README.md).
924
+
> Please contribute your own if you think they'd be useful to others.
923
925
924
926
Custom nodes are provided in the `customNodeDefinitions` prop, as an array of objects of following structure:
925
927
@@ -942,6 +944,10 @@ Custom nodes are provided in the `customNodeDefinitions` prop, as an array of ob
wrapperElement // React component (optional) to wrap *outside* the normal collection wrapper
944
946
wrapperProps // object (optional) -- props for the above wrapper component
947
+
948
+
// For JSON conversion -- only needed if editing as JSON text
949
+
stringifyReplacer // function for stringifying to JSON (if non-JSON data type)
950
+
parseReviver?: // function for parsing as JSON (if non-JSON data type)
945
951
}
946
952
```
947
953
@@ -973,6 +979,17 @@ return (
973
979
)
974
980
```
975
981
982
+
### Handling JSON
983
+
984
+
If you implement a Custom Node that uses a non-JSON data type (e.g. `BigInt`, `Date`), then if you edit your data as full JSON text, these values will be stripped out by the default `JSON.stringify` and `JSON.parse` methods. In this case, you can provide [**replacer**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#replacer) and [**reviver**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#the_reviver_parameter) methods to serialize and de-serialize your data as you see fit. For example the [`BigInt` component](https://github.com/CarlosNZ/json-edit-react/blob/main/custom-component-library/components/BigInt/definition.ts) in the [custom component library](https://github.com/CarlosNZ/json-edit-react/blob/main/custom-component-library/components/DateObject/definition.ts) serializes the value into JSON text like so:
985
+
986
+
```
987
+
{
988
+
"__type": "BigInt",
989
+
"value": 1234567890123456789012345678901234567890
990
+
}
991
+
```
992
+
976
993
### Custom Collection nodes
977
994
978
995
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:
@@ -1199,6 +1216,9 @@ This component is heavily inspired by [react-json-view](https://github.com/mac-s
1199
1216
1200
1217
## Changelog
1201
1218
1219
+
- **1.25.7**:
1220
+
- Handle non-standard data types (e.g. `undefined`, `BigInt`) when stringifying/parsing JSON
1221
+
- More custom components (See [library ReadMe](https://github.com/CarlosNZ/json-edit-react/blob/main/custom-component-library/README.md))
1202
1222
- **1.25.6**:
1203
1223
- Expose a few more components and props to custom components
1204
1224
- Start building Custom Component library (separate to main package)
Copy file name to clipboardExpand all lines: custom-component-library/README.md
+18-5
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,25 @@
1
1
A collection of [Custom Components](https://github.com/CarlosNZ/json-edit-react#custom-nodes) for **json-edit-react**.
2
2
3
-
A work in progress.
3
+
Eventually, I'd like to publish these in a separate package so you can easily import them. But for now just copy the code out of this repo.
4
4
5
5
Contains a [Vite](https://vite.dev/) web-app for previewing and developing components.
6
6
7
7
The individual components are in the `/components` folder, along with demo data (in `data.ts`).
8
8
9
+
> [!NOTE]
10
+
> If you create a custom component that you think would be useful to others, please [create a PR](https://github.com/CarlosNZ/json-edit-react/pulls) for it.
11
+
9
12
## Components
10
13
11
-
These are the ones I'm planning for now:
14
+
These are the ones currently available:
12
15
13
16
-[x] Hyperlink/URL
14
17
-[x] Undefined
15
18
-[x] Date Object
16
-
-[ ] Date Picker (with ISO string)
17
-
-[ ]`NaN`
18
-
-[ ] BigInt
19
+
-[x] Date/Time Picker (with ISO string)
20
+
-[x] Boolean Toggle
21
+
-[x]`NaN`
22
+
-[x] BigInt
19
23
20
24
## Development
21
25
@@ -33,3 +37,12 @@ Launch app:
33
37
yarn dev
34
38
```
35
39
40
+
## Guidelines for development:
41
+
42
+
Custom components should consider the following:
43
+
44
+
- Must respect editing restrictions
45
+
- If including CSS classes, please prefix with `jer-`
46
+
- Handle keyboard input if possible
47
+
- Provide customisation options, particularly styles
0 commit comments