({ path }: { path: string })
| 6 | import {usePreferences} from '~/components/PreferencesProvider' |
| 7 | |
| 8 | export 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 | |
| 40 | function schemaPathFromPath(path: JSONHeroPath | string): JSONHeroPath { |
| 41 | const heroPath = typeof path === "string" ? new JSONHeroPath(path) : path; |
nothing calls this directly
no test coverage detected