-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathSandpackClient.tsx
More file actions
63 lines (60 loc) · 1.73 KB
/
SandpackClient.tsx
File metadata and controls
63 lines (60 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use client'
import cn from '@/lib/cn'
import {
SandpackCodeEditor,
SandpackFileExplorer,
SandpackLayout,
SandpackPreview,
SandpackProvider,
type SandpackProviderProps,
} from '@codesandbox/sandpack-react'
import { ComponentProps } from 'react'
import { SandpackCodeViewer } from './SandpackCodeViewer'
export function SandpackClient({
className,
fileExplorer,
codeEditor,
codeViewer,
preview,
...props
}: SandpackProviderProps & {
className?: string
codeEditor?: ComponentProps<typeof SandpackCodeEditor>
codeViewer?: boolean | ComponentProps<typeof SandpackCodeViewer>
preview?: ComponentProps<typeof SandpackPreview>
fileExplorer?: boolean | ComponentProps<typeof SandpackFileExplorer>
}) {
return (
<div className={cn(className, 'sandpack')}>
<SandpackProvider
{...props}
theme={{
colors: {
surface1: 'var(--mcu-surface-container-low)',
surface2: 'var(--mcu-surface-container)',
surface3: 'var(--mcu-surface-container-high)',
},
font: {
mono: 'var(--font-mono)',
},
}}
// @ts-ignore
style={{ '--sp-border-radius': '0.5rem' }}
>
<SandpackLayout>
{fileExplorer && (
<SandpackFileExplorer
{...(typeof fileExplorer !== 'boolean' ? fileExplorer : undefined)}
/>
)}
{codeViewer ? (
<SandpackCodeViewer {...(typeof codeViewer !== 'boolean' ? codeViewer : undefined)} />
) : (
<SandpackCodeEditor showTabs={fileExplorer ? false : undefined} {...codeEditor} />
)}
<SandpackPreview {...preview} />
</SandpackLayout>
</SandpackProvider>
</div>
)
}