Skip to content

Commit 65ab7f4

Browse files
committed
feat(sandpack): fileExplorer/codeEditor/preview props
1 parent 5752ba0 commit 65ab7f4

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

docs/getting-started/authoring.mdx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,41 @@ It is also possible to pass some individual [file format](https://sandpack.codes
413413

414414
</details>
415415

416+
#### `Sandpack[fileExplorer]`
417+
418+
```tsx
419+
<Sandpack
420+
template="react-ts"
421+
folder="authoring-sandpack-cloud"
422+
fileExplorer
423+
/>
424+
```
425+
426+
<details>
427+
<summary>Result</summary>
428+
429+
<Sandpack
430+
template="react-ts"
431+
folder="authoring-sandpack-cloud"
432+
fileExplorer
433+
/>
434+
435+
</details>
436+
437+
> [!TIP]
438+
> Conveniently, enabling `fileExplorer` will by default `[codeEditor={showTabs: false}]`.
439+
> You can override it with [`[codeEditor]` options](#sandpack[codeeditor])
440+
441+
You can also pass [any `fileExplorer={options: ComponentProps<SandpackFileExplorer>}`](https://sandpack.codesandbox.io/docs/advanced-usage/components#file-explorer:~:text=Preview-,Options,-If%20you%27re%20looking).
442+
443+
#### `Sandpack[codeEditor]`
444+
445+
You can pass [any `codeEditor={options: ComponentProps<SandpackCodeEditor>}`](https://sandpack.codesandbox.io/docs/advanced-usage/components#code-editor:~:text=Preview-,Options,-Extensions).
446+
447+
#### `Sandpack[preview]`
448+
449+
You can pass [any `preview={options: ComponentProps<SandpackPreview>}`](https://sandpack.codesandbox.io/docs/advanced-usage/components#preview:~:text=Preview-,Options,-Additional%20buttons).
450+
416451
### `Codesandbox`
417452

418453
```md

src/components/mdx/Sandpack/Sandpack.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import cn from '@/lib/cn'
22
import { crawl } from '@/utils/docs'
33
import {
44
SandpackCodeEditor,
5+
SandpackFileExplorer,
56
SandpackLayout,
67
SandpackPreview,
78
SandpackProvider,
@@ -12,6 +13,7 @@ import fs from 'node:fs'
1213
import path from 'node:path'
1314

1415
// https://tailwindcss.com/docs/configuration#referencing-in-java-script
16+
import { ComponentProps } from 'react'
1517
import resolveConfig from 'tailwindcss/resolveConfig'
1618
import tailwindConfig from '../../../../tailwind.config'
1719
const fullConfig = resolveConfig(tailwindConfig)
@@ -59,10 +61,16 @@ async function getSandpackFiles(
5961
export const Sandpack = async ({
6062
className,
6163
folder,
64+
fileExplorer,
65+
codeEditor,
66+
preview,
6267
...props
6368
}: SandpackProviderProps & {
64-
className: string
69+
className?: string
6570
folder?: string
71+
codeEditor?: ComponentProps<typeof SandpackCodeEditor>
72+
preview?: ComponentProps<typeof SandpackPreview>
73+
fileExplorer?: boolean | ComponentProps<typeof SandpackFileExplorer>
6674
}) => {
6775
// console.log('folder', folder)
6876

@@ -92,7 +100,7 @@ export const Sandpack = async ({
92100
},
93101
font: {
94102
mono: fullConfig.theme.fontFamily.mono.join(', '),
95-
size: fullConfig.theme.fontSize.xs[0],
103+
// size: fullConfig.theme.fontSize.xs[0],
96104
},
97105
}}
98106
files={_files}
@@ -102,8 +110,13 @@ export const Sandpack = async ({
102110
style={{ '--sp-border-radius': fullConfig.theme.borderRadius.lg }}
103111
>
104112
<SandpackLayout>
105-
<SandpackCodeEditor />
106-
<SandpackPreview />
113+
{fileExplorer && (
114+
<SandpackFileExplorer
115+
{...(typeof fileExplorer !== 'boolean' ? fileExplorer : undefined)}
116+
/>
117+
)}
118+
<SandpackCodeEditor showTabs={fileExplorer ? false : undefined} {...codeEditor} />
119+
<SandpackPreview {...preview} />
107120
</SandpackLayout>
108121
</SandpackProvider>
109122
</div>

0 commit comments

Comments
 (0)