Skip to content

Commit ad556d0

Browse files
committed
feat(sandpack): codeViewer
1 parent 65ab7f4 commit ad556d0

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

docs/getting-started/authoring.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,31 @@ You can also pass [any `fileExplorer={options: ComponentProps<SandpackFileExplor
444444

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

447+
#### `Sandpack[codeViewer]`
448+
449+
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).
450+
451+
```tsx
452+
<Sandpack
453+
template="react-ts"
454+
folder="authoring-sandpack-cloud"
455+
codeViewer
456+
/>
457+
```
458+
459+
<details>
460+
<summary>Result</summary>
461+
462+
<Sandpack
463+
template="react-ts"
464+
folder="authoring-sandpack-cloud"
465+
codeViewer
466+
/>
467+
468+
</details>
469+
470+
You can also pass [any `codeViewer={options: ComponentProps<SandpackCodeViewer>}`](https://sandpack.codesandbox.io/docs/advanced-usage/components#code-viewer:~:text=Preview-,Options,-CodeMirror%20decorations).
471+
447472
#### `Sandpack[preview]`
448473

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

src/components/mdx/Sandpack/Sandpack.tsx

Lines changed: 9 additions & 1 deletion
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+
SandpackCodeViewer,
56
SandpackFileExplorer,
67
SandpackLayout,
78
SandpackPreview,
@@ -63,12 +64,14 @@ export const Sandpack = async ({
6364
folder,
6465
fileExplorer,
6566
codeEditor,
67+
codeViewer,
6668
preview,
6769
...props
6870
}: SandpackProviderProps & {
6971
className?: string
7072
folder?: string
7173
codeEditor?: ComponentProps<typeof SandpackCodeEditor>
74+
codeViewer?: boolean | ComponentProps<typeof SandpackCodeViewer>
7275
preview?: ComponentProps<typeof SandpackPreview>
7376
fileExplorer?: boolean | ComponentProps<typeof SandpackFileExplorer>
7477
}) => {
@@ -115,7 +118,12 @@ export const Sandpack = async ({
115118
{...(typeof fileExplorer !== 'boolean' ? fileExplorer : undefined)}
116119
/>
117120
)}
118-
<SandpackCodeEditor showTabs={fileExplorer ? false : undefined} {...codeEditor} />
121+
{codeViewer ? (
122+
<SandpackCodeViewer {...(typeof codeViewer !== 'boolean' ? codeViewer : undefined)} />
123+
) : (
124+
<SandpackCodeEditor showTabs={fileExplorer ? false : undefined} {...codeEditor} />
125+
)}
126+
119127
<SandpackPreview {...preview} />
120128
</SandpackLayout>
121129
</SandpackProvider>

0 commit comments

Comments
 (0)