@@ -112,6 +112,7 @@ const customTheme = {
112
112
' --w-rjv-background-color' : ' #1e1e1e' ,
113
113
' --w-rjv-line-color' : ' #323232' ,
114
114
' --w-rjv-arrow-color' : ' var(--w-rjv-color)' ,
115
+ ' --w-rjv-edit-color' : ' var(--w-rjv-color)' ,
115
116
' --w-rjv-info-color' : ' #656565' ,
116
117
' --w-rjv-update-color' : ' #ebcb8b' ,
117
118
' --w-rjv-copied-color' : ' #9cdcfe' ,
@@ -144,9 +145,9 @@ export default function Demo() {
144
145
Online custom style example, please check in the [ documentation website] ( https://uiwjs.github.io/react-json-view/ )
145
146
146
147
``` tsx mdx:preview:&title=Online Editing Theme
147
- import React , { useState , useEffect , useRef } from ' react' ;
148
+ import React , { useState , useEffect } from ' react' ;
148
149
import Colorful from ' @uiw/react-color-colorful' ;
149
- import JsonView from ' @uiw/react-json-view' ;
150
+ import JsonView from ' @uiw/react-json-view/editor ' ;
150
151
151
152
const object = {
152
153
avatar: ' https://i.imgur.com/MK3eW3As.jpg' ,
@@ -176,6 +177,7 @@ const customTheme = {
176
177
' --w-rjv-background-color' : ' #1e1e1e' ,
177
178
' --w-rjv-line-color' : ' #323232' ,
178
179
' --w-rjv-arrow-color' : ' #9cdcfe' ,
180
+ ' --w-rjv-edit-color' : ' #9cdcfe' ,
179
181
' --w-rjv-info-color' : ' #656565' ,
180
182
' --w-rjv-update-color' : ' #ebcb8b' ,
181
183
' --w-rjv-copied-color' : ' #0184a6' ,
@@ -199,6 +201,7 @@ const customTheme = {
199
201
export default function Demo() {
200
202
const [cssvar, setCssvar] = useState (' --w-rjv-background-color' );
201
203
const [hex, setHex] = useState (" #1e1e1e" );
204
+ const [editable, setEditable] = useState (false );
202
205
const [theme, setTheme] = useState (customTheme );
203
206
const onChange = ({ hexa }) => {
204
207
setHex (hexa );
@@ -217,13 +220,17 @@ export default function Demo() {
217
220
return () => clearInterval (id )
218
221
}, []);
219
222
223
+ const changeEditable = (evn ) => setEditable (evn .target .checked );
220
224
return (
221
225
<React.Fragment >
222
- <div style = { { display: ' flex' , gap: ' 1rem' }} >
223
- <JsonView value = { src } keyName = " root" style = { { flex: 1 , ... theme }} />
226
+ <label >
227
+ <input type = " checkbox" checked = { editable } onChange = { changeEditable } /> Editable
228
+ </label >
229
+ <div style = { { display: ' flex' , gap: ' 1rem' , alignItems: ' flex-start' }} >
230
+ <JsonView editable = { editable } value = { src } keyName = " root" style = { { flex: 1 , overflow: ' auto' , ... theme }} />
224
231
<div >
225
232
<Colorful color = { hex } onChange = { onChange } />
226
- <div style = { { display: ' flex' , gap: ' 0.4rem' , flexWrap : ' wrap ' }} >
233
+ <div style = { { display: ' flex' , gap: ' 0.4rem' , flexDirection : ' column ' }} >
227
234
{ Object .keys (customTheme ).map ((varname , idx ) => {
228
235
const click = () => {
229
236
setCssvar (varname );
@@ -577,6 +584,8 @@ export default function Demo() {
577
584
578
585
## Props
579
586
587
+ ### JsonView Props
588
+
580
589
``` ts
581
590
import React from ' react' ;
582
591
import { MetaProps , SemicolonProps , EllipsisProps , ValueViewProps } from ' @uiw/react-json-view' ;
@@ -624,6 +633,26 @@ declare const JsonView: React.ForwardRefExoticComponent<Omit<JsonViewProps<objec
624
633
export default JsonView ;
625
634
```
626
635
636
+ ### JsonView Editor Props
637
+
638
+ ``` ts
639
+ import { JsonViewProps } from ' @uiw/react-json-view' ;
640
+ export interface JsonViewEditorProps <T extends object > extends JsonViewProps <T > {
641
+ /** Callback when value edit functionality */
642
+ onEdit? : (option : {
643
+ value: unknown ;
644
+ oldValue: unknown ;
645
+ keyName? : string | number ;
646
+ parentName? : string | number ;
647
+ type? : ' value' | ' key' ;
648
+ }) => void ;
649
+ /** Whether enable edit feature. @default true */
650
+ editable? : boolean ;
651
+ }
652
+ declare const JsonViewEditor: import (" react" ).ForwardRefExoticComponent <Omit <JsonViewEditorProps <object >, " ref" > & import (" react" ).RefAttributes <HTMLDivElement >>;
653
+ export default JsonViewEditor ;
654
+ ```
655
+
627
656
## Size and dependencies
628
657
629
658
Here is the size benchmark (using [ bundlephobia.com] ( https://bundlephobia.com ) ) against similar React libraries (found by [ ` npmjs.com/search ` ] ( https://www.npmjs.com/search?q=react%20json&ranking=popularity ) ):
0 commit comments