Skip to content

Commit

Permalink
Try #112:
Browse files Browse the repository at this point in the history
  • Loading branch information
hackworth-ltd-bors[bot] authored Nov 24, 2021
2 parents 6f55d25 + 6cc26e1 commit 7a6f3b9
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 0 deletions.
106 changes: 106 additions & 0 deletions packages/primer-components/src/TreeOutline/TreeOutline.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { ComponentStory, ComponentMeta } from "@storybook/react";

import { Tree } from "@hackworthltd/primer-types";
import { TreeOutline } from "./TreeOutline";

export default {
title: "Application/Component Library/TreeOutline",
component: TreeOutline,
argTypes: {
tree: { control: "object", name: "Tree to display" },
},
} as ComponentMeta<typeof TreeOutline>;

/* We have this indirection so storybook renders the whole json description of
* a tree as one control. (As having three separate controls for 'label', 'id'
* and 'subtrees' is not particularly useful.)
*/
interface TreeArgs {
tree: Tree;
}

const Template: ComponentStory<(args: TreeArgs) => JSX.Element> = (args) => (
<TreeOutline {...args.tree} />
);

export const Tree1 = Template.bind({});
Tree1.args = { tree: { nodeId: 0, childTrees: [], label: "EmptyHole" } };

export const Tree2 = Template.bind({});
Tree2.args = {
tree: {
nodeId: 0,
childTrees: [{ nodeId: 1, childTrees: [], label: "Var x" }],
label: "Lam x",
},
};

export const Tree3 = Template.bind({});
Tree3.args = {
tree: {
nodeId: 0,
childTrees: [{ nodeId: 1, childTrees: [], label: "Var y" }],
label: "Lam y",
},
};

export const Tree4 = Template.bind({});
Tree4.args = {
tree: {
nodeId: 0,
childTrees: [
{
nodeId: 1,
childTrees: [
{
nodeId: 2,
childTrees: [
{
nodeId: 3,
childTrees: [{ nodeId: 4, childTrees: [], label: "Var x" }],
label: "Lam x",
},
],
label: "LAM a",
},
{
nodeId: 5,
childTrees: [
{
nodeId: 6,
childTrees: [
{ nodeId: 7, childTrees: [], label: "TVar a" },
{ nodeId: 8, childTrees: [], label: "TVar a" },
],
label: "TFun",
},
],
label: "TForall",
},
],
label: "Ann",
},
{ nodeId: 9, childTrees: [], label: "Con Unit" },
],
label: "App",
},
};

export const Tree5 = Template.bind({});
Tree5.args = {
tree: {
nodeId: 0,
childTrees: [
{
nodeId: 1,
childTrees: [
{ nodeId: 2, childTrees: [], label: "Var x" },
{ nodeId: 3, childTrees: [], label: "EmptyHole" },
{ nodeId: 6, childTrees: [], label: "EmptyHole" },
],
label: "Case",
},
],
label: "Lam x",
},
};
23 changes: 23 additions & 0 deletions packages/primer-components/src/TreeOutline/TreeOutline.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import "@/index.css";

import { Tree } from "@hackworthltd/primer-types";

export const TreeOutline = (tree: Tree): JSX.Element => (
<ul className="ml-2 list-disc list-outside">
<li>{tree.label}</li>
<ChildTrees trees={tree.childTrees} />
</ul>
);

function ChildTrees({ trees }: { trees: Tree[] }): JSX.Element {
if (trees.length > 0) {
return (
<ul className="ml-2 list-disc list-outside">
{trees.map((t) => (
<TreeOutline {...t} key={t.nodeId} />
))}
</ul>
);
}
return <></>;
}
3 changes: 3 additions & 0 deletions packages/primer-components/src/TreeOutline/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { TreeOutline } from "./TreeOutline";

export default TreeOutline;
1 change: 1 addition & 0 deletions packages/primer-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export { default as SearchBar } from "@/SearchBar";
export { default as SessionList } from "@/SessionList";
export { default as SessionPreview } from "@/SessionPreview";
export { default as SessionsNavBar } from "@/SessionsNavBar";
export { default as TreeOutline } from "@/TreeOutline";
export { default as UIButton } from "@/UIButton";
25 changes: 25 additions & 0 deletions packages/primer-types/src/Tree.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
*
* @export
* @interface Tree
*/
export interface Tree {
/**
*
* @type {Array<Tree>}
* @memberof Tree
*/
childTrees: Array<Tree>;
/**
*
* @type {number}
* @memberof Tree
*/
nodeId: number;
/**
*
* @type {string}
* @memberof Tree
*/
label: string;
}
1 change: 1 addition & 0 deletions packages/primer-types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./Account";
export * from "./Session";
export * from "./Tree";

0 comments on commit 7a6f3b9

Please sign in to comment.