11import { useEffect , useState } from "react"
22import { Box } from "@mui/material"
3- import { API } from "@stoplight/elements"
4- import "@stoplight/elements/styles.min.css"
53import LoadingWrapper from "./LoadingWrapper"
64
75const Stoplight = ( { url } : { url : string } ) => {
@@ -27,7 +25,21 @@ const Stoplight = ({ url }: { url: string }) => {
2725 )
2826}
2927
30- const ResponsiveStoplight = ( { document } : { document : string } ) => {
28+ const ResponsiveStoplight = ( { document : apiDescriptionDocument } : { document : string } ) => {
29+ useEffect ( ( ) => {
30+ const script = document . createElement ( "script" )
31+ script . src = "https://unpkg.com/@stoplight/elements/web-components.min.js"
32+ script . async = true
33+ document . body . appendChild ( script )
34+ const link = document . createElement ( "link" )
35+ link . rel = "stylesheet"
36+ link . href = "https://unpkg.com/@stoplight/elements/styles.min.css"
37+ document . head . appendChild ( link )
38+ return ( ) => {
39+ document . body . removeChild ( script )
40+ document . head . removeChild ( link )
41+ }
42+ } , [ ] )
3143 return (
3244 < >
3345 < Box sx = { {
@@ -36,8 +48,9 @@ const ResponsiveStoplight = ({ document }: { document: string }) => {
3648 height : "100%" ,
3749 padding : 2
3850 } } >
39- < API
40- apiDescriptionDocument = { document }
51+ < Box
52+ component = "elements-api"
53+ apiDescriptionDocument = { apiDescriptionDocument }
4154 router = "hash"
4255 layout = "stacked"
4356 />
@@ -47,8 +60,9 @@ const ResponsiveStoplight = ({ document }: { document: string }) => {
4760 width : "100%" ,
4861 height : "100%" ,
4962 } } >
50- < API
51- apiDescriptionDocument = { document }
63+ < Box
64+ component = "elements-api"
65+ apiDescriptionDocument = { apiDescriptionDocument }
5266 router = "hash"
5367 layout = "sidebar"
5468 />
0 commit comments