-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2fc0abc
commit d9426cb
Showing
8 changed files
with
799 additions
and
7 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,11 @@ | ||
/* | ||
* A component that points out something to the reader, such as a call to | ||
* try out an idea oneself. | ||
* props: { title?: string; children: any } | ||
*/ | ||
export const Callout = (props) => ( | ||
<div className="callout"> | ||
<h5>{props.title || "Try this!"}</h5> | ||
{props.children} | ||
</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 |
---|---|---|
@@ -1,19 +1,22 @@ | ||
const wrapJsInMarkup = (jsCode) => `<!DOCTYPE html> | ||
const wrapJsInMarkup = (jsCode, options) => `<!DOCTYPE html> | ||
<meta charset="utf8" /> | ||
<body></body> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.8.0/p5.min.js"></script> | ||
<script id="code" type="module">${jsCode}</script> | ||
${options.cssCode ? (`<style type='text/css'>${options.cssCode}</style>`) : ""} | ||
<body>${options.bodyCode || ""}</body> | ||
<script id="code" type="text/javascript">${jsCode}</script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.1/p5.min.js"></script> | ||
`; | ||
|
||
/* | ||
* Component that uses an iframe to run p5 code. | ||
* props: { code: string } | ||
* props: { code: string; height?: number | string; width?: number | string } | ||
*/ | ||
export const CodeFrame = (props) => ( | ||
<iframe | ||
srcDoc={wrapJsInMarkup(props.code)} | ||
srcDoc={wrapJsInMarkup(props.code, props)} | ||
sandbox="allow-scripts allow-popups allow-modals allow-forms" | ||
aria-label="Code Preview" | ||
title="Code Preview" | ||
height={props.height} | ||
width={props.width} | ||
/> | ||
); |
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,5 @@ | ||
import CodeEmbedCodeMirror from "../CodeEmbed"; | ||
|
||
export const EditableSketch = (props) => ( | ||
<CodeEmbedCodeMirror initialValue={props.code.trim()} previewable editable /> | ||
); |
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,21 @@ | ||
import { CodeFrame } from "../CodeEmbed/frame"; | ||
|
||
/* | ||
* A component that displays a full-width sketch without showing its code. | ||
* props: { | ||
* code: string; | ||
* cssCode?: string; | ||
* bodyCode?: string; | ||
* width?: number | string; | ||
* height?: number | string; | ||
* } | ||
*/ | ||
export const SketchEmbed = (props) => ( | ||
<CodeFrame | ||
code={props.code} | ||
cssCode={props.cssCode} | ||
bodyCode={props.bodyCode} | ||
height={props.height || 400} | ||
width="100%" | ||
/> | ||
); |
Oops, something went wrong.