/* * Copyright (c) Facebook, Inc. and its affiliates. */ import * as React from 'react'; import {SandpackProvider} from '@codesandbox/sandpack-react'; import {SandpackLogLevel} from '@codesandbox/sandpack-client'; import {CustomPreset} from './CustomPreset'; import {createFileMap} from './createFileMap'; import type {SandpackSetup} from '@codesandbox/sandpack-react'; type SandpackProps = { children: React.ReactNode; autorun?: boolean; setup?: SandpackSetup; showDevTools?: boolean; }; const sandboxStyle = ` * { box-sizing: border-box; } body { font-family: sans-serif; margin: 20px; padding: 0; } h1 { margin-top: 0; font-size: 22px; } h2 { margin-top: 0; font-size: 20px; } h3 { margin-top: 0; font-size: 18px; } h4 { margin-top: 0; font-size: 16px; } h5 { margin-top: 0; font-size: 14px; } h6 { margin-top: 0; font-size: 12px; } ul { padding-left: 20px; } `.trim(); function SandpackRoot(props: SandpackProps) { let {children, setup, autorun = true, showDevTools = false} = props; const [devToolsLoaded, setDevToolsLoaded] = React.useState(false); let codeSnippets = React.Children.toArray(children) as React.ReactElement[]; let isSingleFile = true; const files = createFileMap(codeSnippets); files['/styles.css'] = { code: [sandboxStyle, files['/styles.css']?.code ?? ''].join('\n\n'), hidden: true, }; return (
setDevToolsLoaded(true)} devToolsLoaded={devToolsLoaded} />
); } SandpackRoot.displayName = 'Sandpack'; export default SandpackRoot;