diff --git a/packages/dev/s2-docs/src/CodePlatter.tsx b/packages/dev/s2-docs/src/CodePlatter.tsx index ac9d5abf6d6..ff9a2b900a7 100644 --- a/packages/dev/s2-docs/src/CodePlatter.tsx +++ b/packages/dev/s2-docs/src/CodePlatter.tsx @@ -72,6 +72,7 @@ export function ShareUrlProvider(props: ProviderProps) { export function CodePlatter({children, type, showCoachMark}: CodePlatterProps) { let codeRef = useRef(null); let [showShadcn, setShowShadcn] = useState(false); + let [showCodeSandbox, setShowCodeSandbox] = useState(false); let getText = () => codeRef.current!.querySelector('pre')!.textContent!; let {library} = useContext(CodePlatterContext); if (!type) { @@ -126,7 +127,7 @@ export function CodePlatter({children, type, showCoachMark}: CodePlatterProps) { Copy link } - {files && + {files && { let filesToDownload = getCodeSandboxFiles(getExampleFiles(codeRef, files, urls, entry), deps, type, entry); @@ -157,16 +158,16 @@ export function CodePlatter({children, type, showCoachMark}: CodePlatterProps) { Install with shadcn } - {files && + {files && { - createCodeSandbox(getExampleFiles(codeRef, files, urls, entry), deps, type, entry); + setShowCodeSandbox(true); }}> Open in CodeSandbox } - {files && type !== 's2' && + {files && type !== 's2' && { createStackBlitz(getExampleFiles(codeRef, files, urls, entry), deps, type, entry); @@ -191,6 +192,11 @@ export function CodePlatter({children, type, showCoachMark}: CodePlatterProps) {
{children}
+ setShowCodeSandbox(false)}> + {showCodeSandbox && + + } + setShowShadcn(false)}> {showShadcn && @@ -313,6 +319,32 @@ function ShadcnDialog({registryUrl}) { ); } +function CodeSandboxDialog({getExampleFiles, codeRef, files, urls, entry, deps, type}) { + return ( + + {({close}) => (<> + Create a CodeSandbox + +

This will create an editable sandbox with this example in a new tab.

+

Troubleshooting: If the sandbox fails to open or isn't created, try logging in to CodeSandbox first. If you're already logged in, try signing out and back in.

+
+ + + + + + )} +
+ ); +} + const pulseAnimation = keyframes(` 0% { outline-width: 0px;