|
1 | 1 | "use client" |
2 | 2 |
|
3 | | -import { Card, Flex, Text } from "@code0-tech/pictor" |
4 | | -import { IconNote, IconVariable } from "@tabler/icons-react" |
| 3 | +import { NodeDisplay, type NodeItem } from "@/components/nodes/NodeDisplay" |
5 | 4 | import { useInView, useReducedMotion } from "motion/react" |
6 | 5 | import { useEffect, useRef } from "react" |
7 | | -import { StableBadge } from "../ui/StableBadge" |
8 | | - |
9 | | -type NodeSegmentType = "text" | "literal" | "reference" | "node" |
10 | | -type NodeAccent = "brand" | "yellow" | "aqua" | "blue" | "pink" |
11 | | - |
12 | | -const ICON_COLOR_MAP: Record<NodeAccent, string> = { |
13 | | - brand: "var(--bg-brand)", |
14 | | - yellow: "var(--bg-yellow)", |
15 | | - aqua: "var(--bg-aqua)", |
16 | | - blue: "var(--bg-blue)", |
17 | | - pink: "var(--bg-pink)", |
18 | | -} |
19 | | - |
20 | | -export interface NodeSegment { |
21 | | - type: NodeSegmentType |
22 | | - value: string |
23 | | -} |
24 | | - |
25 | | -export interface NodeItem { |
26 | | - color: NodeAccent |
27 | | - segments: NodeSegment[] |
28 | | - outline: boolean |
29 | | -} |
30 | | - |
31 | | -function displayMessage(segments: NodeSegment[]) { |
32 | | - return segments.map((segment, index) => { |
33 | | - switch (segment.type) { |
34 | | - case "literal": |
35 | | - return ( |
36 | | - <StableBadge key={`${segment.type}-${segment.value}-${index}`} style={{ verticalAlign: "middle" }} color={"secondary"}> |
37 | | - <Text size={"sm"} style={{ color: "white" }}> |
38 | | - {segment.value} |
39 | | - </Text> |
40 | | - </StableBadge> |
41 | | - ) |
42 | | - case "reference": |
43 | | - return ( |
44 | | - <StableBadge key={`${segment.type}-${segment.value}-${index}`} style={{ verticalAlign: "middle" }} color={"warning"} border className="py-0"> |
45 | | - <IconVariable size={12} /> |
46 | | - <Text size={"sm"} style={{ color: "inherit" }}> |
47 | | - {segment.value} |
48 | | - </Text> |
49 | | - </StableBadge> |
50 | | - ) |
51 | | - case "node": |
52 | | - return ( |
53 | | - <StableBadge key={`${segment.type}-${segment.value}-${index}`} style={{ verticalAlign: "middle", textWrap: "nowrap" }} border> |
54 | | - <IconNote size={12} className="text-white" /> |
55 | | - <Text size={"sm"} style={{ color: "white" }}> |
56 | | - {segment.value} |
57 | | - </Text> |
58 | | - </StableBadge> |
59 | | - ) |
60 | | - case "text": |
61 | | - return ( |
62 | | - <Text key={`${segment.type}-${index}`} size="sm" style={{ color: "inherit" }}> |
63 | | - {segment.value} |
64 | | - </Text> |
65 | | - ) |
66 | | - } |
67 | | - }) |
68 | | -} |
69 | 6 |
|
70 | 7 | function NodeRow({ nodes, direction, active }: { nodes: NodeItem[]; direction: "left" | "right"; active: boolean }) { |
71 | 8 | const animationRef = useRef<HTMLDivElement>(null) |
@@ -105,26 +42,12 @@ function NodeRow({ nodes, direction, active }: { nodes: NodeItem[]; direction: " |
105 | 42 | > |
106 | 43 | <div ref={listRef} className="flex items-start gap-4"> |
107 | 44 | {nodes.map((node, index) => ( |
108 | | - <Card key={`${direction}-${node.color}-${index}`} paddingSize="xs" py="0.35" borderColor="info" color="primary" outline={node.outline}> |
109 | | - <Flex align="center" style={{ gap: "0.7rem" }}> |
110 | | - <IconNote color={ICON_COLOR_MAP[node.color]} size={16} className="shrink-0" /> |
111 | | - <Flex align="center" wrap="wrap" className="text-secondary!" style={{ gap: "0.35rem" }}> |
112 | | - {displayMessage(node.segments)} |
113 | | - </Flex> |
114 | | - </Flex> |
115 | | - </Card> |
| 45 | + <NodeDisplay key={`${direction}-${node.color}-${index}`} node={node} /> |
116 | 46 | ))} |
117 | 47 | </div> |
118 | 48 | <div className="flex items-start gap-4" aria-hidden="true"> |
119 | 49 | {nodes.map((node, index) => ( |
120 | | - <Card key={`${direction}-clone-${node.color}-${index}`} paddingSize="xs" py="0.35" borderColor="info" color="primary" outline={node.outline}> |
121 | | - <Flex align="center" style={{ gap: "0.7rem" }}> |
122 | | - <IconNote color={ICON_COLOR_MAP[node.color]} size={16} className="shrink-0" /> |
123 | | - <Flex align="center" wrap="wrap" className="text-secondary!" style={{ gap: "0.35rem" }}> |
124 | | - {displayMessage(node.segments)} |
125 | | - </Flex> |
126 | | - </Flex> |
127 | | - </Card> |
| 50 | + <NodeDisplay key={`${direction}-clone-${node.color}-${index}`} node={node} /> |
128 | 51 | ))} |
129 | 52 | </div> |
130 | 53 | </div> |
|
0 commit comments