Can customize shown depth
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-08-26 08:47:02 +02:00
parent d3b1028fe4
commit 635fb667e1
4 changed files with 157 additions and 72 deletions

View File

@ -13,6 +13,7 @@ import { MemberPhoto } from "./MemberPhoto";
export function BasicFamilyTree(p: {
tree: FamilyTreeNode;
depth: number;
}): React.ReactElement {
return (
<TreeView
@ -20,12 +21,15 @@ export function BasicFamilyTree(p: {
defaultExpandIcon={<ChevronRightIcon />}
sx={{ flexGrow: 1 }}
>
<FamilyTreeItem n={p.tree} />
<FamilyTreeItem n={p.tree} depth={p.depth} />
</TreeView>
);
}
function FamilyTreeItem(p: { n: FamilyTreeNode }): React.ReactElement {
function FamilyTreeItem(p: {
depth: number;
n: FamilyTreeNode;
}): React.ReactElement {
let children = p.n.down ?? [];
if (p.n.couples) {
@ -55,9 +59,10 @@ function FamilyTreeItem(p: { n: FamilyTreeNode }): React.ReactElement {
</div>
}
>
{children.map((c) => (
<FamilyTreeItem key={c.member.id} n={c} />
))}
{p.depth >= 2 &&
children.map((c) => (
<FamilyTreeItem depth={p.depth - 1} key={c.member.id} n={c} />
))}
</TreeItem>
);
}