-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson-viewer.tsx
More file actions
77 lines (72 loc) · 2.24 KB
/
Copy pathjson-viewer.tsx
File metadata and controls
77 lines (72 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"use client"
import type React from "react"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
import { JsonTree } from "@/components/json-tree"
import { Card } from "@/components/ui/card"
interface JsonViewerProps {
parsedJson: any
viewMode: "tree" | "raw"
setViewMode: (mode: "tree" | "raw") => void
searchQuery: string
setSearchQuery: (query: string) => void
handleCopyToClipboard: () => void
error: string | null
outputTreeRef: React.RefObject<HTMLDivElement | null>
outputRawRef: React.RefObject<HTMLPreElement | null>
}
export function JsonViewer({
parsedJson,
viewMode,
setViewMode,
searchQuery,
setSearchQuery,
handleCopyToClipboard,
error,
outputTreeRef,
outputRawRef,
}: JsonViewerProps) {
return (
<div className="flex flex-col h-[90vh] border p-4">
{/* Content area with proper scrolling */}
<div className="flex-1 bg-card rounded-md overflow-auto">
<Tabs
value={viewMode}
onValueChange={(value) => setViewMode(value as "tree" | "raw")}
className="h-full"
>
<TabsContent value="tree" className="h-full m-0">
<div
ref={outputTreeRef}
className="h-full p-4"
>
{parsedJson ? (
<div>
<JsonTree data={parsedJson} searchQuery={searchQuery} />
</div>
) : (
<div className="flex items-center justify-center h-full text-muted-foreground">
{error || "Enter JSON to view"}
</div>
)}
</div>
</TabsContent>
<TabsContent value="raw" className="h-full m-0">
<div className="h-full p-4">
{parsedJson ? (
<div>
<pre ref={outputRawRef} className="text-sm font-mono">
{JSON.stringify(parsedJson, null, 2)}
</pre>
</div>
) : (
<div className="flex items-center justify-center h-full text-muted-foreground">
{error || "Enter JSON to view"}
</div>
)}
</div>
</TabsContent>
</Tabs>
</div>
</div>
)
}