Skip to content

Commit 21b32dd

Browse files
committed
Expose preview component
1 parent c7cd6ea commit 21b32dd

File tree

5 files changed

+46
-12
lines changed

5 files changed

+46
-12
lines changed

packages/mdx/src/client/preview.tsx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,43 @@ import {
88
import { EditorStep } from "@code-hike/mini-editor"
99

1010
export type PresetConfig = SandboxInfo
11-
1211
export function Preview({
1312
className,
1413
files,
1514
presetConfig,
15+
show,
16+
children,
17+
...rest
1618
}: {
1719
className: string
20+
files: EditorStep["files"]
21+
presetConfig?: PresetConfig
22+
show?: string
23+
children?: React.ReactNode
24+
}) {
25+
return (
26+
<div
27+
className={
28+
"ch-preview" + (className ? " " + className : "")
29+
}
30+
{...rest}
31+
>
32+
{!presetConfig ? (
33+
<MiniBrowser loadUrl={show} children={children} />
34+
) : (
35+
<SandpackPreview
36+
files={files}
37+
presetConfig={presetConfig}
38+
/>
39+
)}
40+
</div>
41+
)
42+
}
43+
44+
function SandpackPreview({
45+
files,
46+
presetConfig,
47+
}: {
1848
files: EditorStep["files"]
1949
presetConfig: PresetConfig
2050
}) {
@@ -46,7 +76,7 @@ export function Preview({
4676
}, [files])
4777

4878
return (
49-
<MiniBrowser className={className}>
79+
<MiniBrowser>
5080
<iframe ref={iframeRef} />
5181
</MiniBrowser>
5282
)

packages/mdx/src/components.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
annotationsMap,
1212
Annotation,
1313
} from "./client/annotations"
14+
import { Preview } from "./client/preview"
1415

1516
export const CH = {
1617
Code,
@@ -19,6 +20,7 @@ export const CH = {
1920
SectionCode,
2021
Spotlight,
2122
Scrollycoding,
23+
Preview,
2224
annotations: annotationsMap,
2325
Annotation,
2426
Slideshow,

packages/mdx/src/index.scss

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
@import "./client/slideshow.scss";
66

77
.ch-codeblock,
8-
.ch-codegroup {
8+
.ch-codegroup,
9+
.ch-preview {
910
border-radius: 6px;
1011
overflow: hidden;
1112
box-shadow: 0 13px 27px -5px rgba(50, 50, 93, 0.25),
1213
0 8px 16px -8px rgba(0, 0, 0, 0.3),
1314
0 -6px 16px -6px rgba(0, 0, 0, 0.025);
14-
}
1515

16-
.ch-codeblock > *,
17-
.ch-codegroup > * {
18-
height: 100%;
16+
& > * {
17+
height: 100%;
18+
}
1919
}

packages/mini-frame/src/index.scss

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
.ch-frame {
2-
border-radius: 6px;
3-
overflow: hidden;
4-
box-shadow: 0 13px 27px -5px rgba(50, 50, 93, 0.25),
5-
0 8px 16px -8px rgba(0, 0, 0, 0.3),
6-
0 -6px 16px -6px rgba(0, 0, 0, 0.025);
2+
// border-radius: 6px;
3+
// overflow: hidden;
4+
// box-shadow: 0 13px 27px -5px rgba(50, 50, 93, 0.25),
5+
// 0 8px 16px -8px rgba(0, 0, 0, 0.3),
6+
// 0 -6px 16px -6px rgba(0, 0, 0, 0.025);
77
font-family: Ubuntu, Droid Sans, -apple-system,
88
BlinkMacSystemFont, Segoe WPC, Segoe UI, sans-serif;
99
height: 100%;

packages/playground/content/simple-code.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,5 @@ function lorem(ipsum, dolor = 1) {
8484
: []
8585
}
8686
```
87+
88+
<CH.Preview show="/" style={{ height: 200 }} />

0 commit comments

Comments
 (0)