+
= ({
case "record":
return (
- {Object.entries(expression.value).map(([key, r]) => (
-
-
-
{key}:
+
+ {Object.entries(expression.value).map(([key, r]) => (
+
-
-
-
-
- ))}
+ ))}
+
);
case "arraystring":
@@ -285,7 +283,7 @@ export interface SquiggleChartProps {
showControls?: boolean;
}
-let defaultChartSettings = { start: 0, stop: 10, count: 20 };
+const defaultChartSettings = { start: 0, stop: 10, count: 20 };
export const SquiggleChart: React.FC
= ({
squiggleString = "",
@@ -299,31 +297,29 @@ export const SquiggleChart: React.FC = ({
showTypes = false,
showControls = false,
chartSettings = defaultChartSettings,
-}: SquiggleChartProps) => {
+}) => {
let expressionResult = run(squiggleString, bindings, environment, jsImports);
- let e = environment ? environment : defaultEnvironment;
- let internal: JSX.Element;
- if (expressionResult.tag === "Ok") {
- let expression = expressionResult.value;
- onChange(expression);
- internal = (
-
- );
- } else {
- internal = (
+ if (expressionResult.tag !== "Ok") {
+ return (
{errorValueToString(expressionResult.value)}
);
}
- return internal;
+
+ let e = environment ?? defaultEnvironment;
+ let expression = expressionResult.value;
+ onChange(expression);
+ return (
+
+ );
};
diff --git a/packages/components/src/components/SquiggleEditor.tsx b/packages/components/src/components/SquiggleEditor.tsx
index bd90c6b1..e35de4f5 100644
--- a/packages/components/src/components/SquiggleEditor.tsx
+++ b/packages/components/src/components/SquiggleEditor.tsx
@@ -57,8 +57,8 @@ export let SquiggleEditor: React.FC = ({
showControls = false,
showSummary = false,
}: SquiggleEditorProps) => {
- let [expression, setExpression] = React.useState(initialSquiggleString);
- let chartSettings = {
+ const [expression, setExpression] = React.useState(initialSquiggleString);
+ const chartSettings = {
start: diagramStart,
stop: diagramStop,
count: diagramCount,
@@ -150,17 +150,17 @@ export let SquigglePartial: React.FC = ({
environment,
jsImports = defaultImports,
}: SquigglePartialProps) => {
- let [expression, setExpression] = React.useState(initialSquiggleString);
- let [error, setError] = React.useState(null);
+ const [expression, setExpression] = React.useState(initialSquiggleString);
+ const [error, setError] = React.useState(null);
- let runSquiggleAndUpdateBindings = () => {
- let squiggleResult = runPartial(
+ const runSquiggleAndUpdateBindings = () => {
+ const squiggleResult = runPartial(
expression,
bindings,
environment,
jsImports
);
- if (squiggleResult.tag == "Ok") {
+ if (squiggleResult.tag === "Ok") {
if (onChange) onChange(squiggleResult.value);
setError(null);
} else {
@@ -181,11 +181,7 @@ export let SquigglePartial: React.FC = ({
height={20}
/>
- {error !== null ? (
- {error}
- ) : (
- <>>
- )}
+ {error !== null ? {error} : null}
);
};
diff --git a/packages/components/src/components/SquigglePlayground.tsx b/packages/components/src/components/SquigglePlayground.tsx
index cff11825..e0214af6 100644
--- a/packages/components/src/components/SquigglePlayground.tsx
+++ b/packages/components/src/components/SquigglePlayground.tsx
@@ -1,19 +1,21 @@
-import _ from "lodash";
-import React, { FC, ReactElement, useState } from "react";
+import React, { FC, Fragment, useState } from "react";
import ReactDOM from "react-dom";
-import { SquiggleChart } from "./SquiggleChart";
-import CodeEditor from "./CodeEditor";
-import JsonEditor from "./JsonEditor";
-import { useForm, useWatch } from "react-hook-form";
+import { Path, useForm, UseFormRegister, useWatch } from "react-hook-form";
import * as yup from "yup";
import { yupResolver } from "@hookform/resolvers/yup";
-import { defaultBindings, environment } from "@quri/squiggle-lang";
import { Tab } from "@headlessui/react";
-import { CodeIcon } from "@heroicons/react/solid";
-import { CogIcon } from "@heroicons/react/solid";
-import { ChartSquareBarIcon } from "@heroicons/react/solid";
-import { CurrencyDollarIcon } from "@heroicons/react/solid";
-import { Fragment } from "react";
+import {
+ ChartSquareBarIcon,
+ CodeIcon,
+ CogIcon,
+ CurrencyDollarIcon,
+} from "@heroicons/react/solid";
+
+import { defaultBindings, environment } from "@quri/squiggle-lang";
+
+import { SquiggleChart } from "./SquiggleChart";
+import { CodeEditor } from "./CodeEditor";
+import { JsonEditor } from "./JsonEditor";
import { ErrorAlert, SuccessAlert } from "./Alert";
interface PlaygroundProps {
@@ -85,49 +87,20 @@ const schema = yup
})
.required();
-type InputProps = {
- label: string;
- children: ReactElement;
-};
-
-const InputItem: React.FC
= ({ label, children }) => (
-
-);
-
-let numberStyle =
- "max-w-lg block w-full shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:max-w-xs sm:text-sm border-gray-300 rounded-md";
-
function classNames(...classes: string[]) {
return classes.filter(Boolean).join(" ");
}
type StyledTabProps = {
name: string;
- iconName: string;
+ icon: (props: React.ComponentProps<"svg">) => JSX.Element;
};
-const StyledTab: React.FC = ({ name, iconName }) => {
- let iconStyle = (isSelected: boolean) =>
- classNames(
- "-ml-0.5 mr-2 h-4 w-4 ",
- isSelected ? "text-slate-500" : "text-gray-400 group-hover:text-gray-900"
- );
-
- let icon = (selected: boolean) =>
- ({
- code: ,
- cog: ,
- squareBar: ,
- dollar: ,
- }[iconName]);
-
+const StyledTab: React.FC = ({ name, icon: Icon }) => {
return (
{({ selected }) => (
-