From afbc1e1455c23e8dc1eccc694306ac1bead7a5f6 Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Thu, 7 Jul 2022 20:54:40 +0400 Subject: [PATCH] collapsible tree --- .../src/components/SquiggleItem.tsx | 157 +++++++++--------- 1 file changed, 74 insertions(+), 83 deletions(-) diff --git a/packages/components/src/components/SquiggleItem.tsx b/packages/components/src/components/SquiggleItem.tsx index e5eef1a4..e68da76a 100644 --- a/packages/components/src/components/SquiggleItem.tsx +++ b/packages/components/src/components/SquiggleItem.tsx @@ -43,7 +43,7 @@ interface VariableBoxProps { showTypes: boolean; } -export const VariableBox: React.FC = ({ +const VariableBox: React.FC = ({ name, heading = "Error", children, @@ -51,13 +51,11 @@ export const VariableBox: React.FC = ({ }) => { const [isCollapsed, setIsCollapsed] = useState(false); return ( - + {name || showTypes ? ( setIsCollapsed(!isCollapsed)} > @@ -69,12 +67,35 @@ export const VariableBox: React.FC = ({ ) : null} {isCollapsed ? null : ( - {children} + + {children} + )} ); }; +const VariableList: React.FC<{ + name?: string; + heading: string; + showTypes: boolean; + children: React.ReactNode; +}> = ({ name, heading, showTypes, children }) => ( + + + {children} + + +); + export interface SquiggleItemProps { /** The output of squiggle's run */ expression: squiggleExpression; @@ -217,90 +238,60 @@ export const SquiggleItem: React.FC = ({ } case "module": { return ( - -
- - {Object.entries(expression.value) - .filter(([key, r]) => key !== "Math") - .map(([key, r]) => ( - - ))} - -
-
+ + {Object.entries(expression.value) + .filter(([key, r]) => key !== "Math") + .map(([key, r]) => ( + + ))} + ); } case "record": return ( - -
- - {Object.entries(expression.value).map(([key, r]) => ( - - ))} - -
-
+ + {Object.entries(expression.value).map(([key, r]) => ( + + ))} + ); case "array": return ( - -
- - {expression.value.map((r, i) => ( - - ))} - -
-
+ + {expression.value.map((r, i) => ( + + ))} + ); default: { return (