Skip to content

Commit

Permalink
feat: set theme on code preview
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunmoAhn committed Nov 1, 2024
1 parent 1bd735c commit c275120
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
6 changes: 1 addition & 5 deletions src/components/playground/PlaygroundOutput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,7 @@ export const PlaygroundOutput = ({
</Button>
</TabListWrapper>
<TabContent value="result" forceMount height={outputHeight}>
<SandpackPreview
style={{ height: '100%' }}
showOpenInCodeSandbox={false}
showRefreshButton={false}
/>
<SandpackPreview style={{ height: '100%' }} showRefreshButton={false} />
</TabContent>
<TabContent value="console" forceMount height={outputHeight}>
<SandpackConsole style={{ height: '100%' }} standalone resetOnPreviewRestart />
Expand Down
24 changes: 21 additions & 3 deletions src/components/playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,36 @@ export interface PlaygroundProps {
outputHeight?: number;
}

const strictOff = {
const strictOff = (theme: 'dark' | 'light') => ({
'/index.js': {
hidden: true,
code: `import React from "react";
import { createRoot } from "react-dom/client";
import "./styles.css";
import "./theme.css";
import App from "./App";
const root = createRoot(document.getElementById("root"));
root.render(<App />);
`,
},
};
'/theme.css': {
hidden: true,
code:
theme === 'dark'
? `
html {
color: #e3e3e3;
background-color: #1c1e21;
}
`
: `
html {
color: #1c1e21;
background-color: transparent;
}
`,
},
});

export const Playground = ({
files,
Expand All @@ -51,7 +69,7 @@ export const Playground = ({

return (
<SandpackProvider
files={{ ...files, ...(!strict && strictOff) }}
files={{ ...files, ...(!strict && strictOff(colorMode)) }}
theme={colorMode}
template="react"
options={{ autorun: true, autoReload: true }}
Expand Down

0 comments on commit c275120

Please sign in to comment.