diff --git a/packages/components/src/components/SquiggleItem.tsx b/packages/components/src/components/SquiggleItem.tsx index 48a8a0fb..e5eef1a4 100644 --- a/packages/components/src/components/SquiggleItem.tsx +++ b/packages/components/src/components/SquiggleItem.tsx @@ -1,4 +1,4 @@ -import * as React from "react"; +import React, { useState } from "react"; import { squiggleExpression, environment, @@ -10,6 +10,8 @@ import { DistributionPlottingSettings, } from "./DistributionChart"; import { FunctionChart, FunctionChartSettings } from "./FunctionChart"; +import clsx from "clsx"; +import { LayoutGroup, motion } from "framer-motion"; function getRange(x: declaration) { const first = x.args[0]; @@ -35,33 +37,48 @@ function getChartSettings(x: declaration): FunctionChartSettings { } interface VariableBoxProps { + name?: string; heading: string; children: React.ReactNode; showTypes: boolean; } export const VariableBox: React.FC = ({ + name, heading = "Error", children, showTypes = false, }) => { - if (showTypes) { - return ( -
-
-
{heading}
-
-
{children}
-
- ); - } else { - return
{children}
; - } + const [isCollapsed, setIsCollapsed] = useState(false); + return ( + + {name || showTypes ? ( + setIsCollapsed(!isCollapsed)} + > + {name ? {name}: : null} + {showTypes ? {heading} : null} + {isCollapsed ? ( + ... + ) : null} + + ) : null} + {isCollapsed ? null : ( + {children} + )} + + ); }; export interface SquiggleItemProps { - /** The input string for squiggle */ + /** The output of squiggle's run */ expression: squiggleExpression; + name?: string; width?: number; height: number; distributionPlotSettings: DistributionPlottingSettings; @@ -74,6 +91,7 @@ export interface SquiggleItemProps { } export const SquiggleItem: React.FC = ({ + name, expression, width, height, @@ -85,7 +103,7 @@ export const SquiggleItem: React.FC = ({ switch (expression.tag) { case "number": return ( - +
@@ -95,6 +113,7 @@ export const SquiggleItem: React.FC = ({ const distType = expression.value.type(); return ( @@ -112,9 +131,9 @@ export const SquiggleItem: React.FC = ({ } case "string": return ( - + " - + {expression.value} " @@ -122,94 +141,45 @@ export const SquiggleItem: React.FC = ({ ); case "boolean": return ( - + {expression.value.toString()} ); case "symbol": return ( - + Undefined Symbol: {expression.value} ); case "call": return ( - + {expression.value} ); - case "array": - return ( - - {expression.value.map((r, i) => ( -
-
-
{i}
-
-
- -
-
- ))} -
- ); - case "record": - return ( - -
- {Object.entries(expression.value).map(([key, r]) => ( -
-
-
{key}:
-
-
- -
-
- ))} -
-
- ); case "arraystring": return ( - + {expression.value.map((r) => `"${r}"`).join(", ")} ); case "date": return ( - + {expression.value.toDateString()} ); case "timeDuration": { return ( - + ); } case "lambda": return ( - +
{`function(${expression.value.parameters.join( "," )})`}
@@ -227,7 +197,11 @@ export const SquiggleItem: React.FC = ({ ); case "lambdaDeclaration": { return ( - + = ({ } case "module": { return ( - -
- {Object.entries(expression.value) - .filter(([key, r]) => key !== "Math") - .map(([key, r]) => ( -
-
-
{key}:
-
-
- -
-
- ))} + +
+ + {Object.entries(expression.value) + .filter(([key, r]) => key !== "Math") + .map(([key, r]) => ( + + ))} +
); } + case "record": + return ( + +
+ + {Object.entries(expression.value).map(([key, r]) => ( + + ))} + +
+
+ ); + case "array": + return ( + +
+ + {expression.value.map((r, i) => ( + + ))} + +
+
+ ); default: { return (