-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Sandpack: upgrade dependencies and adds ReactDevtools #4161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
059d8c7
c5ebd61
2d4e27b
5202a8f
50498f5
c53ec60
b5adb42
3679b10
1301a9d
1425f2c
5666721
77b5860
29d034e
b7f3766
8fbcaac
5a522d1
15f8c71
877b8b2
c29fa17
5b40436
bfe9ad9
a91d10e
a965508
2a1cf07
32ba5ff
0686663
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
* Copyright (c) Facebook, Inc. and its affiliates. | ||
*/ | ||
|
||
import * as React from 'react'; | ||
import cn from 'classnames'; | ||
import { | ||
ClasserProvider, | ||
|
@@ -21,22 +20,19 @@ interface InlineHiglight { | |
endColumn: number; | ||
} | ||
|
||
const CodeBlock = React.forwardRef(function CodeBlock( | ||
{ | ||
children, | ||
className = 'language-js', | ||
metastring, | ||
noMargin, | ||
noMarkers, | ||
}: { | ||
children: string; | ||
className?: string; | ||
metastring: string; | ||
noMargin?: boolean; | ||
noMarkers?: boolean; | ||
}, | ||
ref?: React.Ref<HTMLDivElement> | ||
) { | ||
const CodeBlock = function CodeBlock({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only removed |
||
children, | ||
className = 'language-js', | ||
metastring, | ||
noMargin, | ||
noMarkers, | ||
}: { | ||
children: string; | ||
className?: string; | ||
metastring: string; | ||
noMargin?: boolean; | ||
noMarkers?: boolean; | ||
}) { | ||
const getDecoratedLineInfo = () => { | ||
if (!metastring) { | ||
return []; | ||
|
@@ -95,7 +91,6 @@ const CodeBlock = React.forwardRef(function CodeBlock( | |
'sp-cm': styles.codeViewer, | ||
}}> | ||
<SandpackCodeViewer | ||
ref={ref} | ||
showLineNumbers={false} | ||
decorators={decorators} | ||
/> | ||
|
@@ -104,7 +99,7 @@ const CodeBlock = React.forwardRef(function CodeBlock( | |
</SandpackProvider> | ||
</div> | ||
); | ||
}); | ||
}; | ||
|
||
export default CodeBlock; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import { | |
useActiveCode, | ||
SandpackCodeEditor, | ||
SandpackThemeProvider, | ||
SandpackReactDevTools, | ||
} from '@codesandbox/sandpack-react'; | ||
import scrollIntoView from 'scroll-into-view-if-needed'; | ||
|
||
|
@@ -77,6 +78,7 @@ export function CustomPreset({ | |
maxHeight: isExpanded ? '' : 406, | ||
}} | ||
/> | ||
|
||
{isExpandable && ( | ||
<button | ||
translate="yes" | ||
|
@@ -104,6 +106,8 @@ export function CustomPreset({ | |
</button> | ||
)} | ||
</div> | ||
|
||
<SandpackReactDevTools /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we'll want to make this conditional. (Show DevTools for some sandboxes, but not every one.) diff --git a/beta/src/components/MDX/Sandpack/CustomPreset.tsx b/beta/src/components/MDX/Sandpack/CustomPreset.tsx
index 7050dcb6..acf0cb77 100644
--- a/beta/src/components/MDX/Sandpack/CustomPreset.tsx
+++ b/beta/src/components/MDX/Sandpack/CustomPreset.tsx
@@ -22,9 +22,11 @@ import {CustomTheme} from './Themes';
export function CustomPreset({
isSingleFile,
onReset,
+ showDevTools,
}: {
isSingleFile: boolean;
onReset: () => void;
+ showDevTools: boolean;
}) {
const lineCountRef = React.useRef<{[key: string]: number}>({});
const containerRef = React.useRef<HTMLDivElement>(null);
@@ -107,7 +109,7 @@ export function CustomPreset({
)}
</div>
- <SandpackReactDevTools />
+ {showDevTools && <SandpackReactDevTools />}
</SandpackThemeProvider>
</div>
</>
diff --git a/beta/src/components/MDX/Sandpack/index.tsx b/beta/src/components/MDX/Sandpack/index.tsx
index 3cfa4ebd..374a6d51 100644
--- a/beta/src/components/MDX/Sandpack/index.tsx
+++ b/beta/src/components/MDX/Sandpack/index.tsx
@@ -15,6 +15,7 @@ type SandpackProps = {
children: React.ReactChildren;
autorun?: boolean;
setup?: SandpackSetup;
+ showDevTools?: boolean;
};
const sandboxStyle = `
@@ -64,7 +65,7 @@ ul {
`.trim();
function Sandpack(props: SandpackProps) {
- let {children, setup, autorun = true} = props;
+ let {children, setup, autorun = true, showDevTools = false} = props;
let [resetKey, setResetKey] = React.useState(0);
let codeSnippets = React.Children.toArray(children) as React.ReactElement[];
let isSingleFile = true;
@@ -144,6 +145,7 @@ function Sandpack(props: SandpackProps) {
onReset={() => {
setResetKey((k) => k + 1);
}}
+ showDevTools={showDevTools}
/>
</SandpackProvider>
</div> There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tried to just push this small change myself but I don't have permissions to push to your fork :D |
||
</SandpackThemeProvider> | ||
</div> | ||
</> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,29 +3,21 @@ | |
*/ | ||
|
||
import * as React from 'react'; | ||
import {useCodeSandboxLink} from '@codesandbox/sandpack-react'; | ||
import {UnstyledOpenInCodeSandboxButton} from '@codesandbox/sandpack-react'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a minor Sandpack break change that fixed a bug for long sandboxes |
||
import cn from 'classnames'; | ||
import {IconNewPage} from '../../Icon/IconNewPage'; | ||
|
||
export const OpenInCodeSandboxButton = ({className}: {className?: string}) => { | ||
const url = useCodeSandboxLink(); | ||
|
||
return ( | ||
<a | ||
<UnstyledOpenInCodeSandboxButton | ||
className={cn( | ||
'text-sm text-primary dark:text-primary-dark inline-flex items-center hover:text-link duration-100 ease-in transition mx-1', | ||
className | ||
)} | ||
href={url} | ||
rel="noreferrer noopener" | ||
target="_blank" | ||
title="Open in CodeSandbox"> | ||
<span className="hidden md:inline"> | ||
<IconNewPage className="inline mb-0.5 text-base" /> Fork | ||
</span> | ||
<span className="inline md:hidden"> | ||
<span className="inline"> | ||
<IconNewPage className="inline mb-0.5 text-base" /> Fork | ||
</span> | ||
</a> | ||
</UnstyledOpenInCodeSandboxButton> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
ref
as this hasn't been used anywhere