6
6
SandboxInfo ,
7
7
} from "@codesandbox/sandpack-client"
8
8
import { EditorStep } from "@code-hike/mini-editor"
9
+ import { EditorTheme } from "@code-hike/utils"
9
10
10
11
export type PresetConfig = SandboxInfo
11
12
export function Preview ( {
@@ -14,13 +15,15 @@ export function Preview({
14
15
presetConfig,
15
16
show,
16
17
children,
18
+ codeConfig,
17
19
...rest
18
20
} : {
19
21
className : string
20
22
files : EditorStep [ "files" ]
21
23
presetConfig ?: PresetConfig
22
24
show ?: string
23
25
children ?: React . ReactNode
26
+ codeConfig : { theme : EditorTheme }
24
27
} ) {
25
28
return (
26
29
< div
@@ -30,11 +33,16 @@ export function Preview({
30
33
{ ...rest }
31
34
>
32
35
{ ! presetConfig ? (
33
- < MiniBrowser loadUrl = { show } children = { children } />
36
+ < MiniBrowser
37
+ loadUrl = { show }
38
+ children = { children }
39
+ theme = { codeConfig . theme }
40
+ />
34
41
) : (
35
42
< SandpackPreview
36
43
files = { files }
37
44
presetConfig = { presetConfig }
45
+ codeConfig = { codeConfig }
38
46
/>
39
47
) }
40
48
</ div >
@@ -44,9 +52,11 @@ export function Preview({
44
52
function SandpackPreview ( {
45
53
files,
46
54
presetConfig,
55
+ codeConfig,
47
56
} : {
48
57
files : EditorStep [ "files" ]
49
58
presetConfig : PresetConfig
59
+ codeConfig : { theme : EditorTheme }
50
60
} ) {
51
61
const iframeRef = React . useRef < HTMLIFrameElement > ( null ! )
52
62
const clientRef = React . useRef < SandpackClient > ( null ! )
@@ -76,7 +86,8 @@ function SandpackPreview({
76
86
} , [ files ] )
77
87
78
88
return (
79
- < MiniBrowser >
89
+ // TODO only render iframe here, leave MiniBrowser for the parent component
90
+ < MiniBrowser theme = { codeConfig . theme } >
80
91
< iframe ref = { iframeRef } />
81
92
</ MiniBrowser >
82
93
)
0 commit comments