1
- import { Fragment , useState , useEffect } from 'react' ;
2
- import JsonView , { JsonViewProps } from '@uiw/react-json-view' ;
1
+ import { Fragment , useState , useEffect , useRef } from 'react' ;
2
+ import JsonView , { JsonViewProps , useHighlight , SemicolonProps } from '@uiw/react-json-view' ;
3
3
import { styled } from 'styled-components' ;
4
4
import { lightTheme } from '@uiw/react-json-view/light' ;
5
5
import { darkTheme } from '@uiw/react-json-view/dark' ;
@@ -16,7 +16,7 @@ function aPlusB(a: number, b: number) {
16
16
}
17
17
const example = {
18
18
avatar,
19
- string : 'Lorem ipsum dolor sit amet' ,
19
+ string : 'Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet ' ,
20
20
integer : 42 ,
21
21
float : 114.514 ,
22
22
// @ts -ignore
@@ -54,6 +54,15 @@ const Options = styled.div`
54
54
grid-template-columns: 50% 60%;
55
55
` ;
56
56
57
+ const ObjectKey : SemicolonProps [ 'render' ] = ( { value, keyName, parentName, ...props } ) => {
58
+ const $edit = useRef < HTMLSpanElement & HTMLModElement > ( null ) ;
59
+ useHighlight ( { value, highlightUpdates : true , highlightContainer : $edit } ) ;
60
+ if ( keyName === 'integer' && typeof value === 'number' && value > 40 ) {
61
+ return < del { ...props } ref = { $edit } /> ;
62
+ }
63
+ return < span { ...props } ref = { $edit } /> ;
64
+ } ;
65
+
57
66
export function Example ( ) {
58
67
const [ indentWidth , setIndentWidth ] = useState ( 15 ) ;
59
68
const [ theme , setTheme ] = useState < React . CSSProperties > ( lightTheme as React . CSSProperties ) ;
@@ -91,12 +100,7 @@ export function Example() {
91
100
style = { { ...theme , padding : 6 , borderRadius : 6 } }
92
101
collapsed = { collapsed }
93
102
components = { {
94
- objectKey : ( { value, keyName, parentName, ...props } ) => {
95
- if ( keyName === 'integer' && typeof value === 'number' && value > 40 ) {
96
- return < del { ...props } /> ;
97
- }
98
- return < span { ...props } /> ;
99
- } ,
103
+ objectKey : ObjectKey ,
100
104
} }
101
105
/>
102
106
< Options >
0 commit comments