Skip to content

Commit

Permalink
feat(sandpack): codeViewer
Browse files Browse the repository at this point in the history
  • Loading branch information
abernier committed Nov 5, 2024
1 parent 65ab7f4 commit ad556d0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
25 changes: 25 additions & 0 deletions docs/getting-started/authoring.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,31 @@ You can also pass [any `fileExplorer={options: ComponentProps<SandpackFileExplor

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

#### `Sandpack[codeViewer]`

It will render the [`SandpackCodeViewer`](https://sandpack.codesandbox.io/docs/advanced-usage/components#code-viewer) instead of the default [`SandpackCodeEditor`](https://sandpack.codesandbox.io/docs/advanced-usage/components#code-editor).

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

<details>
<summary>Result</summary>

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

</details>

You can also pass [any `codeViewer={options: ComponentProps<SandpackCodeViewer>}`](https://sandpack.codesandbox.io/docs/advanced-usage/components#code-viewer:~:text=Preview-,Options,-CodeMirror%20decorations).

#### `Sandpack[preview]`

You can pass [any `preview={options: ComponentProps<SandpackPreview>}`](https://sandpack.codesandbox.io/docs/advanced-usage/components#preview:~:text=Preview-,Options,-Additional%20buttons).
Expand Down
10 changes: 9 additions & 1 deletion 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,
SandpackCodeViewer,
SandpackFileExplorer,
SandpackLayout,
SandpackPreview,
Expand Down Expand Up @@ -63,12 +64,14 @@ export const Sandpack = async ({
folder,
fileExplorer,
codeEditor,
codeViewer,
preview,
...props
}: SandpackProviderProps & {
className?: string
folder?: string
codeEditor?: ComponentProps<typeof SandpackCodeEditor>
codeViewer?: boolean | ComponentProps<typeof SandpackCodeViewer>
preview?: ComponentProps<typeof SandpackPreview>
fileExplorer?: boolean | ComponentProps<typeof SandpackFileExplorer>
}) => {
Expand Down Expand Up @@ -115,7 +118,12 @@ export const Sandpack = async ({
{...(typeof fileExplorer !== 'boolean' ? fileExplorer : undefined)}
/>
)}
<SandpackCodeEditor showTabs={fileExplorer ? false : undefined} {...codeEditor} />
{codeViewer ? (
<SandpackCodeViewer {...(typeof codeViewer !== 'boolean' ? codeViewer : undefined)} />
) : (
<SandpackCodeEditor showTabs={fileExplorer ? false : undefined} {...codeEditor} />
)}

<SandpackPreview {...preview} />
</SandpackLayout>
</SandpackProvider>
Expand Down

0 comments on commit ad556d0

Please sign in to comment.