-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChildren.tsx
More file actions
34 lines (32 loc) · 959 Bytes
/
Children.tsx
File metadata and controls
34 lines (32 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { type FC } from "react";
import { type ComponentChangeHandler } from "@/types/state/event";
import { type ComponentNode, isComponentState } from "@/types/state/component";
import { Component } from "./Component";
export interface ChildrenProps {
nodes?: ComponentNode[];
onChange: ComponentChangeHandler;
}
export const Children: FC<ChildrenProps> = ({
nodes,
onChange,
}: ChildrenProps) => {
if (!nodes || nodes.length === 0) {
return null;
}
return (
<>
{nodes.map((node, index) => {
if (isComponentState(node)) {
const key = node.id || index;
return <Component key={key} {...node} onChange={onChange} />;
} else if (typeof node === "string") {
return node;
} else if (!node) {
// This is ok, just as with React, don't render
} else {
console.warn("chartlets: invalid child node encountered:", node);
}
})}
</>
);
};