Merge pull request #460 from quantified-uncertainty/partial-storybook
Add partial functionality to storybook and update partial bindings async
This commit is contained in:
commit
b9bde840b5
|
@ -164,15 +164,25 @@ export let SquigglePartial: React.FC<SquigglePartialProps> = ({
|
||||||
xyPointLength: outputXYPoints,
|
xyPointLength: outputXYPoints,
|
||||||
};
|
};
|
||||||
let [expression, setExpression] = React.useState(initialSquiggleString);
|
let [expression, setExpression] = React.useState(initialSquiggleString);
|
||||||
let squiggleResult = runPartial(
|
let [error, setError] = React.useState<string | null>(null);
|
||||||
expression,
|
|
||||||
bindings,
|
let runSquiggleAndUpdateBindings = () => {
|
||||||
samplingInputs,
|
let squiggleResult = runPartial(
|
||||||
jsImports
|
expression,
|
||||||
);
|
bindings,
|
||||||
if (squiggleResult.tag == "Ok") {
|
samplingInputs,
|
||||||
if (onChange) onChange(squiggleResult.value);
|
jsImports
|
||||||
}
|
);
|
||||||
|
if (squiggleResult.tag == "Ok") {
|
||||||
|
if (onChange) onChange(squiggleResult.value);
|
||||||
|
setError(null);
|
||||||
|
} else {
|
||||||
|
setError(errorValueToString(squiggleResult.value));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
React.useEffect(runSquiggleAndUpdateBindings, [expression]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Input>
|
<Input>
|
||||||
|
@ -184,13 +194,7 @@ export let SquigglePartial: React.FC<SquigglePartialProps> = ({
|
||||||
height={20}
|
height={20}
|
||||||
/>
|
/>
|
||||||
</Input>
|
</Input>
|
||||||
{squiggleResult.tag == "Error" ? (
|
{error !== null ? <ErrorBox heading="Error">{error}</ErrorBox> : <></>}
|
||||||
<ErrorBox heading="Error">
|
|
||||||
{errorValueToString(squiggleResult.value)}
|
|
||||||
</ErrorBox>
|
|
||||||
) : (
|
|
||||||
<></>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
51
packages/components/src/stories/SquigglePartial.stories.mdx
Normal file
51
packages/components/src/stories/SquigglePartial.stories.mdx
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
import { SquigglePartial, SquiggleEditor } from "../components/SquiggleEditor";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { Canvas, Meta, Story, Props } from "@storybook/addon-docs";
|
||||||
|
|
||||||
|
<Meta title="Squiggle/SquigglePartial" component={SquigglePartial} />
|
||||||
|
|
||||||
|
export const Template = (props) => <SquigglePartial {...props} />;
|
||||||
|
|
||||||
|
# Squiggle Partial
|
||||||
|
|
||||||
|
A Squiggle Partial is an editor that does not return a graph to the user, but
|
||||||
|
instead returns bindings that can be used by further Squiggle Editors.
|
||||||
|
|
||||||
|
<Canvas>
|
||||||
|
<Story
|
||||||
|
name="Standalone"
|
||||||
|
args={{
|
||||||
|
initialSquiggleString: "x = normal(5,2)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{Template.bind({})}
|
||||||
|
</Story>
|
||||||
|
</Canvas>
|
||||||
|
|
||||||
|
<Canvas>
|
||||||
|
<Story
|
||||||
|
name="With Editor"
|
||||||
|
args={{
|
||||||
|
initialPartialString: "x = normal(5,2)",
|
||||||
|
initialEditorString: "x",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{(props) => {
|
||||||
|
let [bindings, setBindings] = useState({});
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<SquigglePartial
|
||||||
|
{...props}
|
||||||
|
initialSquiggleString={props.initialPartialString}
|
||||||
|
onChange={setBindings}
|
||||||
|
/>
|
||||||
|
<SquiggleEditor
|
||||||
|
{...props}
|
||||||
|
initialSquiggleString={props.initialEditorString}
|
||||||
|
bindings={bindings}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
</Story>
|
||||||
|
</Canvas>
|
Loading…
Reference in New Issue
Block a user