File tree Expand file tree Collapse file tree 2 files changed +65
-3
lines changed Expand file tree Collapse file tree 2 files changed +65
-3
lines changed Original file line number Diff line number Diff line change @@ -322,6 +322,62 @@ export default function Demo() {
322
322
}
323
323
```
324
324
325
+ ** Support for the URL(opens in a new tab) API.**
326
+
327
+ ``` tsx mdx:preview
328
+ import React from ' react' ;
329
+ import JsonView from ' @uiw/react-json-view' ;
330
+
331
+ export default function Demo() {
332
+ return (
333
+ <JsonView
334
+ value = { {
335
+ url: new URL (' https://example.com?t=12' ),
336
+ urlStr: " https://example.com" ,
337
+ github: " https://example.com" ,
338
+ }}
339
+ style = { {
340
+ ' --w-rjv-background-color' : ' #ffffff' ,
341
+ }}
342
+ />
343
+ )
344
+ }
345
+ ```
346
+
347
+ ``` tsx mdx:preview
348
+ import React from ' react' ;
349
+ import JsonView from ' @uiw/react-json-view' ;
350
+
351
+ function value({ type , children , value , ... props }) {
352
+ if (value instanceof URL ) {
353
+ return (
354
+ <span { ... props } >
355
+ <a href = { value .href } target = " _blank" rel = " noopener noreferrer" >
356
+ { children }
357
+ </a >
358
+ Open URL
359
+ </span >
360
+ );
361
+ }
362
+ }
363
+
364
+ export default function Demo() {
365
+ return (
366
+ <JsonView
367
+ value = { {
368
+ url: new URL (' https://example.com?t=12' ),
369
+ urlStr: " https://example.com" ,
370
+ github: " https://example.com" ,
371
+ }}
372
+ components = { { value }}
373
+ style = { {
374
+ ' --w-rjv-background-color' : ' #ffffff' ,
375
+ }}
376
+ />
377
+ )
378
+ }
379
+ ```
380
+
325
381
## Highlight Updates
326
382
327
383
``` tsx mdx:preview
Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ export interface ValueViewProps<T>
63
63
indentWidth : number ;
64
64
renderKey ?: JSX . Element ;
65
65
renderBraces ?: MetaProps [ 'render' ] ;
66
- renderValue ?: ( props : React . HTMLAttributes < HTMLSpanElement > & { type : TypeProps [ 'type' ] } ) => JSX . Element ;
66
+ renderValue ?: ( props : React . HTMLAttributes < HTMLSpanElement > & { type : TypeProps [ 'type' ] ; value ?: T ; } ) => JSX . Element ;
67
67
}
68
68
69
69
export function ValueView < T = object > ( props : ValueViewProps < T > ) {
@@ -101,6 +101,11 @@ export function ValueView<T = object>(props: ValueViewProps<T>) {
101
101
type = 'bigint' ;
102
102
content = `${ value } n` ;
103
103
}
104
+ const isURL = value instanceof URL ;
105
+ if ( isURL ) {
106
+ type = 'string' ;
107
+ content = `"${ value . href } "` ;
108
+ }
104
109
if ( typeof value === 'string' ) {
105
110
content = `"${ value } "` ;
106
111
}
@@ -126,12 +131,13 @@ export function ValueView<T = object>(props: ValueViewProps<T>) {
126
131
className : 'w-rjv-value' ,
127
132
style : { color, ...style } ,
128
133
type,
134
+ value,
129
135
content,
130
- children : ( value as string ) ,
136
+ children : content ,
131
137
} ) ;
132
138
const valueView = reView ? reView : (
133
139
< Label color = { color } style = { style } className = "w-rjv-value" >
134
- { content }
140
+ { isURL ? < a href = { value . href } target = "_blank" rel = "noopener noreferrer" > { content } </ a > : content }
135
141
</ Label >
136
142
) ;
137
143
return (
You can’t perform that action at this time.
0 commit comments