squiggle/packages/website/docs/Internal/ImportIntoMdx.mdx

40 lines
1008 B
Plaintext
Raw Normal View History

2022-07-27 21:31:40 +00:00
---
title: How to import squiggle files into `.mdx` documents
sidebar_position: 5
---
2022-07-28 15:26:22 +00:00
import { SquiggleEditorWithImportedBindings } from "../../src/components/SquiggleEditor";
2022-07-27 21:31:40 +00:00
_Proof of concept_
## Consider the following squiggle file
In our docusaurus repo, we have a static asset called `demo.squiggle`. It looks like this
```js
x = 1 to 2
y = {a: x, b: 1e1}
f(t) = normal(t, 1.1)
z = y.b * y.a
```
We can call `f(z)` upon the assignments in `demo.squiggle` like so:
```jsx
2022-07-28 15:26:22 +00:00
import { SquiggleEditorWithImportedBindings } from "../../src/components/SquiggleEditor";
2022-07-27 21:31:40 +00:00
<SquiggleEditorWithImportedBindings
2022-07-27 21:31:40 +00:00
defaultCode={"f(z)"}
bindingsImportFile={"/estimates/demo.squiggle"}
2022-07-27 21:31:40 +00:00
/>;
```
Notice, you need to wrap the export of `@quri/squiggle-components` in custom code for dynamicism, please view `packages/website/src/components/` in github for details.
2022-07-27 21:31:40 +00:00
Which would then look exactly like
2022-07-28 14:33:31 +00:00
<SquiggleEditorWithImportedBindings
2022-07-27 21:31:40 +00:00
defaultCode={"f(z)"}
bindingsImportUrl={"/estimates/demo.squiggle"}
2022-07-27 21:31:40 +00:00
/>