MSP-3486 add theme in JSONSchemaView in JsonSchemaViewer
This commit is contained in:
1 parent
0df7073ac0
commit
fc93c0bb02
1 file changed
+8
-3
@@ -1,7 +1,9 @@
|
||||
import RefParser from '@apidevtools/json-schema-ref-parser'
|
||||
import JSONSchemaView from 'json-schema-view-js'
|
||||
import cloneDeep from 'lodash.clonedeep'
|
||||
import React, { useEffect, useRef } from 'react'
|
||||
import { FC, useContext, useEffect, useRef } from 'react'
|
||||
|
||||
import { Context } from '@stores/index.tsx'
|
||||
|
||||
import 'json-schema-view-js/dist/style.min.css'
|
||||
|
||||
@@ -9,7 +11,8 @@ interface JsonSchemaViewerProps {
|
||||
schema: object
|
||||
}
|
||||
|
||||
const JsonSchemaViewer: React.FC<JsonSchemaViewerProps> = ({ schema }) => {
|
||||
const JsonSchemaViewer: FC<JsonSchemaViewerProps> = ({ schema }) => {
|
||||
const { changeTheme } = useContext(Context)
|
||||
const myRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -28,7 +31,9 @@ const JsonSchemaViewer: React.FC<JsonSchemaViewerProps> = ({ schema }) => {
|
||||
if (err) {
|
||||
console.log(err)
|
||||
} else {
|
||||
const view = new JSONSchemaView(dereferencedSchema, 3)
|
||||
const view = new JSONSchemaView(dereferencedSchema, 3, {
|
||||
theme: changeTheme ? 'dark' : ''
|
||||
})
|
||||
if (myRef.current) {
|
||||
myRef.current.appendChild(view.render())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user