-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(console): Add SandpackConsole component (#546)
- Loading branch information
Showing
45 changed files
with
1,435 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
sandpack-react/src/components/CodeEditor/CodeMirror.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useClasser } from "@code-hike/classer"; | ||
import React from "react"; | ||
|
||
import { CleanIcon } from "../../icons"; | ||
import { css } from "../../styles"; | ||
import { | ||
buttonClassName, | ||
iconStandaloneClassName, | ||
actionButtonClassName, | ||
} from "../../styles/shared"; | ||
import { classNames } from "../../utils/classNames"; | ||
|
||
export const Button: React.FC<{ onClick: () => void }> = ({ onClick }) => { | ||
const c = useClasser("sp"); | ||
|
||
return ( | ||
<button | ||
className={classNames( | ||
c("button", "icon-standalone"), | ||
buttonClassName, | ||
iconStandaloneClassName, | ||
actionButtonClassName, | ||
css({ | ||
position: "absolute", | ||
bottom: "$space$2", | ||
right: "$space$2", | ||
}) | ||
)} | ||
onClick={onClick} | ||
> | ||
<CleanIcon /> | ||
</button> | ||
); | ||
}; |
132 changes: 132 additions & 0 deletions
132
sandpack-react/src/components/Console/Console.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import React from "react"; | ||
|
||
import { SandpackCodeEditor, SandpackPreview } from ".."; | ||
import { SandpackProvider, SandpackLayout, Sandpack } from "../.."; | ||
|
||
import { SandpackConsole } from "./SandpackConsole"; | ||
|
||
export default { | ||
title: "components/Console", | ||
}; | ||
|
||
/* eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-explicit-any */ | ||
const files = (full: boolean): any => ({ | ||
"/App.js": `export default function App() { | ||
return ( | ||
<> | ||
<p>Primitives</p> | ||
<button onClick={() => console.log("Lorem ipsum")}>string</button> | ||
<button onClick={() => console.log(123)}>number</button> | ||
<button onClick={() => console.log(true)}>boolean</button> | ||
<button onClick={() => console.log(undefined)}>undefined</button> | ||
<button onClick={() => console.log(null)}>null</button> | ||
${ | ||
full | ||
? `<p>Others</p> | ||
<button onClick={() => console.log(new Date())}>Date</button> | ||
<button onClick={() => console.log(NaN)}>NaN</button> | ||
<button onClick={() => console.log(new RegExp("//"))}>Regex</button> | ||
<button onClick={() => console.log(new Error("Foo"))}>Error</button> | ||
<button onClick={() => console.log(document.querySelector("button"))}>Log a node</button> | ||
<button onClick={() => console.log(document.querySelectorAll("button"))}>Log nodes</button> | ||
<button onClick={() => console.log(document.querySelector("body"))}>Log body</button> | ||
<button onClick={() => console.log(()=>{}, function foo(){})}>Log function</button> | ||
<button onClick={() => console.log(window)}>Log window</button> | ||
<button onClick={() => console.log({ foo: [] })}>Log object</button> | ||
<button onClick={() => console.log({foo: [], baz: () => {}})}>Log object II</button> | ||
<button onClick={() => console.log(["foo", 123, [], ["foo2"], () => {}])}>Multiples types</button> | ||
<button onClick={() => { | ||
console.log("foo", "baz") | ||
console.error("foo", "baz") | ||
}}> | ||
Multiples logs | ||
</button> | ||
<button onClick={() => console.error({ foo: [] })}>Log error</button> | ||
<button onClick={() => console.warn({ foo: [] })}>Log warning</button> | ||
<button onClick={() => console.info({ foo: [] })}>Log info</button> | ||
<button onClick={() => console.clear()}>Console.clear</button>` | ||
: "" | ||
} | ||
</> | ||
); | ||
} | ||
`, | ||
}); | ||
|
||
export const Main: React.FC = () => { | ||
const [showHeader, setShowHeader] = React.useState(true); | ||
const [showSyntaxErrors, setShowSyntaxErrors] = React.useState(true); | ||
|
||
return ( | ||
<SandpackProvider files={files(true)} template="react"> | ||
<SandpackLayout> | ||
<SandpackCodeEditor /> | ||
<SandpackPreview /> | ||
</SandpackLayout> | ||
|
||
<SandpackLayout style={{ marginTop: 12 }}> | ||
<SandpackConsole | ||
showHeader={showHeader} | ||
showSyntaxError={showSyntaxErrors} | ||
/> | ||
</SandpackLayout> | ||
|
||
<br /> | ||
|
||
<label> | ||
<input | ||
checked={showHeader} | ||
onChange={({ target }): void => setShowHeader(target.checked)} | ||
type="checkbox" | ||
/> | ||
Show header | ||
</label> | ||
|
||
<label> | ||
<input | ||
checked={showSyntaxErrors} | ||
onChange={({ target }): void => setShowSyntaxErrors(target.checked)} | ||
type="checkbox" | ||
/> | ||
Show syntax errors | ||
</label> | ||
</SandpackProvider> | ||
); | ||
}; | ||
|
||
export const Preset: React.FC = () => { | ||
return ( | ||
<div style={{ width: "auto" }}> | ||
<Sandpack template="react" /> | ||
|
||
<br /> | ||
|
||
<Sandpack | ||
files={files(false)} | ||
options={{ showConsoleButton: true, showConsole: true }} | ||
template="react" | ||
/> | ||
|
||
<br /> | ||
|
||
<Sandpack | ||
files={files(false)} | ||
options={{ showConsoleButton: false, showConsole: true }} | ||
template="react" | ||
/> | ||
|
||
<br /> | ||
|
||
<Sandpack | ||
files={files(false)} | ||
options={{ showConsoleButton: true, showConsole: false }} | ||
template="react" | ||
/> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from "react"; | ||
|
||
import { ConsoleIcon } from "../../icons"; | ||
import { css } from "../../styles"; | ||
import { classNames } from "../../utils/classNames"; | ||
|
||
export const Header: React.FC = () => { | ||
return ( | ||
<div | ||
className={classNames( | ||
css({ | ||
borderBottom: "1px solid $colors$surface2", | ||
padding: "$space$3 $space$2", | ||
}) | ||
)} | ||
> | ||
<p | ||
className={classNames( | ||
css({ | ||
lineHeight: 1, | ||
margin: 0, | ||
color: "$colors$base", | ||
fontSize: "$font$size", | ||
|
||
display: "flex", | ||
alignItems: "center", | ||
|
||
gap: "$space$2", | ||
}) | ||
)} | ||
> | ||
<ConsoleIcon /> | ||
Console | ||
</p> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.