-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCrumbLine.tsx
More file actions
110 lines (105 loc) · 2.4 KB
/
CrumbLine.tsx
File metadata and controls
110 lines (105 loc) · 2.4 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import type React from "react";
import { theme } from "./theme";
type CrumbLineProps = {
ns: string;
nsColor: string;
msg: string;
dt: string;
data?: string;
depth?: number;
type?: "crumb" | "scope:enter" | "scope:exit" | "scope:error" | "time" | "snapshot" | "session:start";
tags?: string[];
sid?: string;
};
export const CrumbLine: React.FC<CrumbLineProps> = ({
ns,
nsColor,
msg,
dt,
data,
depth = 0,
type = "crumb",
tags,
}) => {
const pad = " ".repeat(depth);
const dtStyle = { color: theme.comment };
let msgDisplay: React.ReactNode;
switch (type) {
case "scope:enter":
msgDisplay = (
<>
{pad}
<span style={{ fontWeight: "bold" }}>[{msg}]</span>{" "}
<span style={dtStyle}>→</span> enter
</>
);
break;
case "scope:exit":
msgDisplay = (
<>
{pad}
<span style={{ fontWeight: "bold" }}>[{msg}]</span>{" "}
<span style={dtStyle}>←</span> exit
</>
);
break;
case "scope:error":
msgDisplay = (
<>
{pad}
<span style={{ fontWeight: "bold" }}>[{msg}]</span>{" "}
<span style={{ color: theme.error }}>!!</span>{" "}
<span style={{ color: theme.error }}>error</span>
</>
);
break;
case "time":
msgDisplay = (
<>
{pad}
<span style={dtStyle}>time:</span> {msg}
</>
);
break;
case "snapshot":
msgDisplay = (
<>
{pad}
<span style={dtStyle}>snapshot:</span> {msg}
</>
);
break;
case "session:start":
msgDisplay = (
<>
{pad}
<span style={{ fontWeight: "bold" }}>session start:</span> {msg}
</>
);
break;
default:
msgDisplay = (
<>
{pad}
{msg}
</>
);
}
return (
<div style={{ whiteSpace: "pre", fontSize: 16, lineHeight: 1.5 }}>
<span style={{ color: nsColor, display: "inline-block", width: 140 }}>
{ns}
</span>
{" "}
<span style={{ color: theme.fgBright }}>{msgDisplay}</span>
{" "}
<span style={dtStyle}>{dt}</span>
{tags && tags.length > 0 && (
<span style={dtStyle}> [{tags.join(", ")}]</span>
)}
{data && (
<span style={{ color: theme.comment }}> {data}</span>
)}
</div>
);
};