Skip to content

Commit 7ae1061

Browse files
authored
feat: apply theme to preview (#200)
1 parent 7dd1a9b commit 7ae1061

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/output/Preview.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const props = defineProps<{ show: boolean; ssr: boolean }>()
2020
2121
const store = inject('store') as Store
2222
const clearConsole = inject('clear-console') as Ref<boolean>
23+
const theme = inject('theme') as Ref<'dark' | 'light'>
2324
2425
const previewOptions = inject('preview-options') as Props['previewOptions']
2526
@@ -85,6 +86,7 @@ function createSandbox() {
8586
importMap.imports.vue = store.state.vueRuntimeURL
8687
}
8788
const sandboxSrc = srcdoc
89+
.replace(/<html>/, `<html class="${theme.value}">`)
8890
.replace(/<!--IMPORT_MAP-->/, JSON.stringify(importMap))
8991
.replace(
9092
/<!-- PREVIEW-OPTIONS-HEAD-HTML -->/,
@@ -277,7 +279,12 @@ defineExpose({ reload })
277279
</script>
278280

279281
<template>
280-
<div class="iframe-container" v-show="show" ref="container"></div>
282+
<div
283+
class="iframe-container"
284+
:class="theme"
285+
v-show="show"
286+
ref="container"
287+
></div>
281288
<Message :err="runtimeError" />
282289
<Message v-if="!runtimeError" :warn="runtimeWarning" />
283290
</template>
@@ -290,4 +297,7 @@ defineExpose({ reload })
290297
border: none;
291298
background-color: #fff;
292299
}
300+
.iframe-container.dark :deep(iframe) {
301+
background-color: #1e1e1e;
302+
}
293303
</style>

0 commit comments

Comments
 (0)