MCPcopy Create free account
hub / github.com/triggerdotdev/jsonhero-web / JsonSchemaViewer

Function JsonSchemaViewer

app/components/JsonSchemaViewer.tsx:8–38  ·  view source on GitHub ↗
({ path }: { path: string })

Source from the content-addressed store, hash-verified

6import {usePreferences} from '~/components/PreferencesProvider'
7
8export function JsonSchemaViewer({ path }: { path: string }) {
9 const schema = useJsonSchema();
10 const schemaPath = schemaPathFromPath(path);
11 const schemaJson = schemaPath.first(schema);
12 const [hovering, setHovering] = useState(false);
13 const [preferences] = usePreferences();
14
15 const code = useMemo(() => {
16 return JSON.stringify(schemaJson, null, preferences?.indent || 2);
17 }, [schemaJson, preferences]);
18
19 return (
20 <div
21 className="relative w-full h-full"
22 onMouseEnter={() => setHovering(true)}
23 onMouseLeave={() => setHovering(false)}
24 >
25 <CodeViewer code={code} lang="json" />
26 <div
27 className={`absolute top-1 right-0 flex justify-end w-full transition ${
28 hovering ? "opacity-100" : "opacity-0"
29 }`}
30 >
31 <CopyTextButton
32 value={code}
33 className="bg-slate-200 hover:bg-slate-300 h-fit mr-1 px-2 py-0.5 rounded-sm transition hover:cursor-pointer dark:text-white dark:bg-slate-700 dark:hover:bg-slate-600"
34 ></CopyTextButton>
35 </div>
36 </div>
37 );
38}
39
40function schemaPathFromPath(path: JSONHeroPath | string): JSONHeroPath {
41 const heroPath = typeof path === "string" ? new JSONHeroPath(path) : path;

Callers

nothing calls this directly

Calls 3

useJsonSchemaFunction · 0.90
usePreferencesFunction · 0.90
schemaPathFromPathFunction · 0.85

Tested by

no test coverage detected