);
diff --git a/beta/src/components/MDX/Sandpack/CustomPreset.tsx b/beta/src/components/MDX/Sandpack/CustomPreset.tsx
index 7dd6fa55298..47eb57def82 100644
--- a/beta/src/components/MDX/Sandpack/CustomPreset.tsx
+++ b/beta/src/components/MDX/Sandpack/CustomPreset.tsx
@@ -7,19 +7,16 @@ import {
useSandpack,
useActiveCode,
SandpackCodeEditor,
- SandpackThemeProvider,
- SandpackReactDevTools,
+ // SandpackReactDevTools,
+ SandpackLayout,
} from '@codesandbox/sandpack-react';
import cn from 'classnames';
import {IconChevron} from 'components/Icon/IconChevron';
import {NavigationBar} from './NavigationBar';
import {Preview} from './Preview';
-import {CustomTheme} from './Themes';
-import {useSandpackLint} from './useSandpackLint';
-// Workaround for https://github.com/reactjs/reactjs.org/issues/4686#issuecomment-1137402613.
-const emptyArray: Array = [];
+import {useSandpackLint} from './useSandpackLint';
export function CustomPreset({
showDevTools,
@@ -39,11 +36,11 @@ export function CustomPreset({
const {code} = useActiveCode();
const [isExpanded, setIsExpanded] = React.useState(false);
- const {activePath} = sandpack;
- if (!lineCountRef.current[activePath]) {
- lineCountRef.current[activePath] = code.split('\n').length;
+ const {activeFile} = sandpack;
+ if (!lineCountRef.current[activeFile]) {
+ lineCountRef.current[activeFile] = code.split('\n').length;
}
- const lineCount = lineCountRef.current[activePath];
+ const lineCount = lineCountRef.current[activeFile];
const isExpandable = lineCount > 16 || isExpanded;
return (
@@ -52,64 +49,61 @@ export function CustomPreset({
className="shadow-lg dark:shadow-lg-dark rounded-lg"
ref={containerRef}>
-
-
-
-
- {isExpandable && (
-
-
- {showDevTools && (
-
+ }
+ }}>
+
+
+ {isExpanded ? 'Show less' : 'Show more'}
+
+
)}
-
+
+
+ {/* {showDevTools && (
+ // @ts-ignore TODO(@danilowoz): support devtools
+
+ )} */}
>
);
diff --git a/beta/src/components/MDX/Sandpack/NavigationBar.tsx b/beta/src/components/MDX/Sandpack/NavigationBar.tsx
index 9adf0fca385..27164404afb 100644
--- a/beta/src/components/MDX/Sandpack/NavigationBar.tsx
+++ b/beta/src/components/MDX/Sandpack/NavigationBar.tsx
@@ -40,10 +40,10 @@ export function NavigationBar({providedFiles}: {providedFiles: Array}) {
// By default, show the dropdown because all tabs may not fit.
// We don't know whether they'll fit or not until after hydration:
const [showDropdown, setShowDropdown] = React.useState(true);
- const {openPaths, clients, setActiveFile, activePath} = sandpack;
+ const {activeFile, setActiveFile, visibleFiles, clients} = sandpack;
const clientId = Object.keys(clients)[0];
const {refresh} = useSandpackNavigation(clientId);
- const isMultiFile = openPaths.length > 1;
+ const isMultiFile = visibleFiles.length > 1;
const hasJustToggledDropdown = React.useRef(false);
// Keep track of whether we can show all tabs or just the dropdown.
@@ -88,9 +88,9 @@ export function NavigationBar({providedFiles}: {providedFiles: Array}) {
};
return (
-
+
-
+
}) {
)}>
-
+
{({open}) => (
// If tabs don't fit, display the dropdown instead.
// The dropdown is absolutely positioned inside the
// space that's taken by the (invisible) tab list.
-
+ )}
))}
diff --git a/beta/src/components/MDX/Sandpack/Preview.tsx b/beta/src/components/MDX/Sandpack/Preview.tsx
index cf1a595bcb5..8df69e8e6d8 100644
--- a/beta/src/components/MDX/Sandpack/Preview.tsx
+++ b/beta/src/components/MDX/Sandpack/Preview.tsx
@@ -4,12 +4,19 @@
/* eslint-disable react-hooks/exhaustive-deps */
import * as React from 'react';
-import {useSandpack, LoadingOverlay} from '@codesandbox/sandpack-react';
+import {
+ useSandpack,
+ LoadingOverlay,
+ SandpackStack,
+} from '@codesandbox/sandpack-react';
import cn from 'classnames';
import {Error} from './Error';
import {SandpackConsole} from './Console';
import type {LintDiagnostic} from './useSandpackLint';
+/**
+ * TODO: can we use React.useId?
+ */
const generateRandomId = (): string =>
Math.floor(Math.random() * 10000).toString();
@@ -149,8 +156,8 @@ export function Preview({
// The best way to test it is to actually go through some challenges.
return (
-
{!error && }
-
+
);
}
diff --git a/beta/src/components/MDX/Sandpack/SandpackRoot.tsx b/beta/src/components/MDX/Sandpack/SandpackRoot.tsx
index aec0b576ec5..ef396405e86 100644
--- a/beta/src/components/MDX/Sandpack/SandpackRoot.tsx
+++ b/beta/src/components/MDX/Sandpack/SandpackRoot.tsx
@@ -7,7 +7,7 @@ import {SandpackProvider} from '@codesandbox/sandpack-react';
import {SandpackLogLevel} from '@codesandbox/sandpack-client';
import {CustomPreset} from './CustomPreset';
import {createFileMap} from './createFileMap';
-
+import {CustomTheme} from './Themes';
import type {SandpackSetup} from '@codesandbox/sandpack-react';
type SandpackProps = {
@@ -75,15 +75,19 @@ function SandpackRoot(props: SandpackProps) {
};
return (
-