@@ -11,6 +11,7 @@ interface JsonViewProps {
11
11
initialExpandDepth ?: number ;
12
12
className ?: string ;
13
13
withCopyButton ?: boolean ;
14
+ isError ?: boolean ;
14
15
}
15
16
16
17
function tryParseJson ( str : string ) : { success : boolean ; data : JsonValue } {
@@ -35,6 +36,7 @@ const JsonView = memo(
35
36
initialExpandDepth = 3 ,
36
37
className,
37
38
withCopyButton = true ,
39
+ isError = false
38
40
} : JsonViewProps ) => {
39
41
const { toast } = useToast ( ) ;
40
42
const [ copied , setCopied ] = useState ( false ) ;
@@ -100,6 +102,7 @@ const JsonView = memo(
100
102
name = { name }
101
103
depth = { 0 }
102
104
initialExpandDepth = { initialExpandDepth }
105
+ isError = { isError }
103
106
/>
104
107
</ div >
105
108
</ div >
@@ -114,10 +117,11 @@ interface JsonNodeProps {
114
117
name ?: string ;
115
118
depth : number ;
116
119
initialExpandDepth : number ;
120
+ isError ?: boolean ;
117
121
}
118
122
119
123
const JsonNode = memo (
120
- ( { data, name, depth = 0 , initialExpandDepth } : JsonNodeProps ) => {
124
+ ( { data, name, depth = 0 , initialExpandDepth, isError = false } : JsonNodeProps ) => {
121
125
const [ isExpanded , setIsExpanded ] = useState ( depth < initialExpandDepth ) ;
122
126
123
127
const getDataType = ( value : JsonValue ) : string => {
@@ -133,7 +137,8 @@ const JsonNode = memo(
133
137
boolean : "text-amber-600" ,
134
138
null : "text-purple-600" ,
135
139
undefined : "text-gray-600" ,
136
- string : "text-green-600 break-all whitespace-pre-wrap" ,
140
+ string : "text-green-600 group-hover:text-green-500" ,
141
+ error : "text-red-600 group-hover:text-red-500" ,
137
142
default : "text-gray-700" ,
138
143
} ;
139
144
@@ -236,7 +241,7 @@ const JsonNode = memo(
236
241
{ name } :
237
242
</ span >
238
243
) }
239
- < pre className = { typeStyleMap . string } > "{ value } "</ pre >
244
+ < pre className = { clsx ( typeStyleMap . string , "break-all whitespace-pre-wrap" ) } > "{ value } "</ pre >
240
245
</ div >
241
246
) ;
242
247
}
@@ -250,8 +255,8 @@ const JsonNode = memo(
250
255
) }
251
256
< pre
252
257
className = { clsx (
253
- typeStyleMap . string ,
254
- "cursor-pointer group-hover:text-green-500 " ,
258
+ isError ? typeStyleMap . error : typeStyleMap . string ,
259
+ "cursor-pointer break-all whitespace-pre-wrap " ,
255
260
) }
256
261
onClick = { ( ) => setIsExpanded ( ! isExpanded ) }
257
262
title = { isExpanded ? "Click to collapse" : "Click to expand" }
0 commit comments