Skip to content

Commit 7bab486

Browse files
committed
doc: Update document example.
1 parent 9c7fb5c commit 7bab486

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

core/README.md

+17-2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ const customTheme = {
113113
'--w-rjv-line-color': '#323232',
114114
'--w-rjv-arrow-color': 'var(--w-rjv-color)',
115115
'--w-rjv-info-color': '#656565',
116+
'--w-rjv-update-color': '#ebcb8b',
116117
'--w-rjv-copied-color': '#9cdcfe',
117118
'--w-rjv-copied-success-color': '#28a745',
118119

@@ -142,7 +143,7 @@ export default function Demo() {
142143
Online custom style example, please check in the [documentation website](https://uiwjs.github.io/react-json-view/)
143144

144145
```tsx mdx:preview:&title=Online Editing Theme
145-
import React, { useState, useRef } from 'react';
146+
import React, { useState, useEffect, useRef } from 'react';
146147
import Colorful from '@uiw/react-color-colorful';
147148
import JsonView from '@uiw/react-json-view';
148149

@@ -174,6 +175,7 @@ const customTheme = {
174175
'--w-rjv-line-color': '#323232',
175176
'--w-rjv-arrow-color': '#9cdcfe',
176177
'--w-rjv-info-color': '#656565',
178+
'--w-rjv-update-color': '#ebcb8b',
177179
'--w-rjv-copied-color': '#0184a6',
178180
'--w-rjv-copied-success-color': '#28a745',
179181

@@ -199,10 +201,23 @@ export default function Demo() {
199201
setHex(hexa);
200202
setTheme({ ...theme, [cssvar]: hexa });
201203
};
204+
205+
const [src, setSrc] = useState({ ...object })
206+
useEffect(() => {
207+
const loop = () => {
208+
setSrc(src => ({
209+
...src,
210+
timer: src.timer + 1
211+
}))
212+
}
213+
const id = setInterval(loop, 1000)
214+
return () => clearInterval(id)
215+
}, []);
216+
202217
return (
203218
<React.Fragment>
204219
<div style={{ display: 'flex', gap: '1rem' }}>
205-
<JsonView value={object} keyName="root" style={{ flex: 1, ...theme }} />
220+
<JsonView value={src} keyName="root" style={{ flex: 1, ...theme }} />
206221
<div>
207222
<Colorful color={hex} onChange={onChange} />
208223
<div style={{ display: 'flex', gap: '0.4rem', flexWrap: 'wrap' }}>

www/src/Example.tsx

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Fragment, useState } from 'react';
1+
import { Fragment, useState, useEffect } from 'react';
22
import { styled } from 'styled-components';
33
import JsonView, { JsonViewProps } from '@uiw/react-json-view';
44
import { lightTheme } from '@uiw/react-json-view/light';
@@ -31,6 +31,7 @@ const example = {
3131
nestedArray: [
3232
[1, 2],
3333
[3, 4],
34+
{ a: 1}
3435
],
3536
object3: {},
3637
object2: {
@@ -62,16 +63,32 @@ export function Example() {
6263
const [theme, setTheme] = useState<React.CSSProperties>(lightTheme as React.CSSProperties);
6364
const [displayDataTypes, setDisplayDataTypes] = useState(true);
6465
const [displayObjectSize, setDisplayObjectSize] = useState(true);
66+
const [highlightUpdates, setHighlightUpdates] = useState(true);
6567
const [clipboard, setClipboard] = useState(true);
6668
const [quotes, setQuotes] = useState<JsonViewProps<object>['quotes']>("\"");
6769
const [collapsed, setCollapsed] = useState<JsonViewProps<object>['collapsed']>(true);
70+
71+
72+
const [src, setSrc] = useState({ ...example })
73+
useEffect(() => {
74+
const loop = () => {
75+
setSrc(src => ({
76+
...src,
77+
timer: src.timer + 1
78+
}))
79+
}
80+
const id = setInterval(loop, 1000)
81+
return () => clearInterval(id)
82+
}, []);
83+
6884
return (
6985
<Fragment>
7086
<JsonView
71-
value={example}
87+
value={src}
7288
indentWidth={indentWidth}
7389
displayObjectSize={displayObjectSize}
7490
displayDataTypes={displayDataTypes}
91+
highlightUpdates={highlightUpdates}
7592
quotes={quotes}
7693
enableClipboard={clipboard}
7794
style={{ ...theme, padding: 6, borderRadius: 6 }}
@@ -133,6 +150,14 @@ export function Example() {
133150
onChange={(evn) => setDisplayObjectSize(evn.target.checked)}
134151
/>
135152
</Label>
153+
<Label>
154+
<span>Highlight Updates:</span>
155+
<input
156+
type="checkbox"
157+
checked={highlightUpdates}
158+
onChange={(evn) => setHighlightUpdates(evn.target.checked)}
159+
/>
160+
</Label>
136161
</Options>
137162
</Fragment>
138163
);

0 commit comments

Comments
 (0)