Skip to content

Commit

Permalink
feat(sandpack): fileExplorer/codeEditor/preview props
Browse files Browse the repository at this point in the history
  • Loading branch information
abernier committed Nov 5, 2024
1 parent 5752ba0 commit 65ab7f4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
35 changes: 35 additions & 0 deletions docs/getting-started/authoring.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,41 @@ It is also possible to pass some individual [file format](https://sandpack.codes

</details>

#### `Sandpack[fileExplorer]`

```tsx
<Sandpack
template="react-ts"
folder="authoring-sandpack-cloud"
fileExplorer
/>
```

<details>
<summary>Result</summary>

<Sandpack
template="react-ts"
folder="authoring-sandpack-cloud"
fileExplorer
/>

</details>

> [!TIP]
> Conveniently, enabling `fileExplorer` will by default `[codeEditor={showTabs: false}]`.
> You can override it with [`[codeEditor]` options](#sandpack[codeeditor])
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).

#### `Sandpack[codeEditor]`

You can pass [any `codeEditor={options: ComponentProps<SandpackCodeEditor>}`](https://sandpack.codesandbox.io/docs/advanced-usage/components#code-editor:~:text=Preview-,Options,-Extensions).

#### `Sandpack[preview]`

You can pass [any `preview={options: ComponentProps<SandpackPreview>}`](https://sandpack.codesandbox.io/docs/advanced-usage/components#preview:~:text=Preview-,Options,-Additional%20buttons).

### `Codesandbox`

```md
Expand Down
21 changes: 17 additions & 4 deletions src/components/mdx/Sandpack/Sandpack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import cn from '@/lib/cn'
import { crawl } from '@/utils/docs'
import {
SandpackCodeEditor,
SandpackFileExplorer,
SandpackLayout,
SandpackPreview,
SandpackProvider,
Expand All @@ -12,6 +13,7 @@ import fs from 'node:fs'
import path from 'node:path'

// https://tailwindcss.com/docs/configuration#referencing-in-java-script
import { ComponentProps } from 'react'
import resolveConfig from 'tailwindcss/resolveConfig'
import tailwindConfig from '../../../../tailwind.config'
const fullConfig = resolveConfig(tailwindConfig)
Expand Down Expand Up @@ -59,10 +61,16 @@ async function getSandpackFiles(
export const Sandpack = async ({
className,
folder,
fileExplorer,
codeEditor,
preview,
...props
}: SandpackProviderProps & {
className: string
className?: string
folder?: string
codeEditor?: ComponentProps<typeof SandpackCodeEditor>
preview?: ComponentProps<typeof SandpackPreview>
fileExplorer?: boolean | ComponentProps<typeof SandpackFileExplorer>
}) => {
// console.log('folder', folder)

Expand Down Expand Up @@ -92,7 +100,7 @@ export const Sandpack = async ({
},
font: {
mono: fullConfig.theme.fontFamily.mono.join(', '),
size: fullConfig.theme.fontSize.xs[0],
// size: fullConfig.theme.fontSize.xs[0],
},
}}
files={_files}
Expand All @@ -102,8 +110,13 @@ export const Sandpack = async ({
style={{ '--sp-border-radius': fullConfig.theme.borderRadius.lg }}
>
<SandpackLayout>
<SandpackCodeEditor />
<SandpackPreview />
{fileExplorer && (
<SandpackFileExplorer
{...(typeof fileExplorer !== 'boolean' ? fileExplorer : undefined)}
/>
)}
<SandpackCodeEditor showTabs={fileExplorer ? false : undefined} {...codeEditor} />
<SandpackPreview {...preview} />
</SandpackLayout>
</SandpackProvider>
</div>
Expand Down

0 comments on commit 65ab7f4

Please sign in to comment.