-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
318 lines (304 loc) ยท 8.08 KB
/
Copy pathindex.tsx
File metadata and controls
318 lines (304 loc) ยท 8.08 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*
* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
* TERMINAL UI PRIMITIVES โ Bloomberg classic GUI ์ฌํ
* ๋ ํผ๋ฐ์ค: docs/design/bloomberg-reference-3.png
* ๋ชจ๋ ํ๋ฉด์ raw <div> ๋์ ์ด ํ๋ฆฌ๋ฏธํฐ๋ธ๋ฅผ ์กฐ๋ฆฝํ๋ค. (docs/DESIGN.md)
* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
*/
import Link from "next/link";
import type { ReactNode } from "react";
import { cn } from "@/lib/utils/cn";
type Tone = "default" | "accent" | "up" | "down" | "info" | "warn" | "mag";
const TEXT_TONE: Record<Tone, string> = {
default: "text-term-white",
accent: "text-term-accent",
up: "text-term-up",
down: "text-term-down",
info: "text-term-info",
warn: "text-term-warn",
mag: "text-term-mag",
};
const SOLID_TONE: Record<Tone, string> = {
default: "bg-term-chrome text-term-white",
accent: "bg-term-accent text-black",
up: "bg-term-up text-black",
down: "bg-term-down text-black",
info: "bg-term-info text-black",
warn: "bg-term-warn text-black",
mag: "bg-term-mag text-black",
};
/**
* ๋ฐ์ดํฐ ํจ๋. ๋ค์ด๋น ํ์ดํ๋ฐ(์ฃผํฉ ๊ธ์) + Win95 ๋ฒ ๋ฒจ + ๊ฒ์ ๋ณธ๋ฌธ.
* ๋ ํผ๋ฐ์ค์ ๋ชจ๋ ์ฐฝ์ด ์ด ํํ๋ค.
*/
export function Panel({
title,
code,
right,
className,
bodyClassName,
children,
}: {
title?: ReactNode;
/** ํ์ดํ๋ฐ ์ฐ์ธก ์ฝ๋/์๋ณ์ (์: "RT" "1)") */
code?: ReactNode;
/** ํ์ดํ๋ฐ ์ฐ์ธก ์ปค์คํ
๋
ธ๋ (code ๋์ ) */
right?: ReactNode;
className?: string;
bodyClassName?: string;
children: ReactNode;
}) {
return (
<section
className={cn(
"bevel flex min-w-0 flex-col border border-term-border bg-term-panel",
className,
)}
>
{(title || code || right) && (
<header className="flex items-center gap-2 bg-term-navy px-1.5 py-0.5">
{title && (
<h2 className="truncate text-[11px] font-bold text-term-accent">
{title}
</h2>
)}
<div className="ml-auto text-[10px] text-term-info">
{right ?? code}
</div>
</header>
)}
<div className={cn("flex-1 p-1", bodyClassName)}>{children}</div>
</section>
);
}
/** ๋ผ๋ฒจ(์ข) โ ๊ฐ(์ฐ). ์ด๊ณ ๋ฐ๋ ํ ์ค. */
export function DataRow({
label,
value,
tone = "default",
className,
}: {
label: ReactNode;
value: ReactNode;
tone?: Tone;
className?: string;
}) {
return (
<div
className={cn(
"flex items-baseline justify-between gap-2 py-px text-[11px] leading-tight",
className,
)}
>
<span className="truncate text-term-muted">{label}</span>
<span className={cn("shrink-0 tabular-nums", TEXT_TONE[tone])}>
{value}
</span>
</div>
);
}
/** ์ปฌ๋ผ ํค๋ ํ (์ฃผํฉ). ํ ์๋จ. */
export function ColHead({ cols }: { cols: string[] }) {
return (
<div className="flex justify-between gap-2 border-b border-term-accent-dim pb-px text-[10px] font-bold uppercase text-term-accent">
{cols.map((c, i) => (
<span key={i} className={i === 0 ? "" : "text-right"}>
{c}
</span>
))}
</div>
);
}
/** ์ฆ๊ฐ ๊ฐ โ green/red, +/- ๋ถํธ. */
export function Delta({
value,
suffix = "",
withSign = true,
className,
}: {
value: number;
suffix?: string;
withSign?: boolean;
className?: string;
}) {
const up = value >= 0;
const sign = withSign ? (up ? "+" : "-") : up ? "" : "-";
return (
<span
className={cn(
"tabular-nums",
up ? "text-term-up" : "text-term-down",
className,
)}
>
{sign}
{Math.abs(value).toFixed(2)}
{suffix}
</span>
);
}
/** ์์ ๋ฒ ๋ฒจ ํ๊ทธ/์นฉ. ์ํยท์์ฅ ๋ผ๋ฒจ. */
export function Tag({
children,
tone = "accent",
className,
}: {
children: ReactNode;
tone?: Tone;
className?: string;
}) {
return (
<span
className={cn(
"bevel inline-block px-1 text-[10px] font-bold uppercase leading-tight",
SOLID_TONE[tone],
className,
)}
>
{children}
</span>
);
}
/** ํํธ๋งต ์
โ ๊ฐ ๊ฐ๋์ ๋ฐ๋ผ ์ ๋ธ๋ก. */
export function Cell({
children,
tone = "default",
className,
}: {
children: ReactNode;
tone?: Tone;
className?: string;
}) {
const bg: Record<Tone, string> = {
default: "bg-term-elevated text-term-white",
accent: "bg-term-accent/25 text-term-accent",
up: "bg-term-up/25 text-term-up",
down: "bg-term-down/25 text-term-down",
info: "bg-term-info/25 text-term-info",
warn: "bg-term-warn/25 text-term-warn",
mag: "bg-term-mag/25 text-term-mag",
};
return (
<span
className={cn(
"flex items-center justify-center px-1 py-0.5 text-center text-[10px] tabular-nums",
bg[tone],
className,
)}
>
{children}
</span>
);
}
/** ASCII ์คํํฌ๋ผ์ธ โ ๋ธ๋ก ๋ฌธ์ ๋ฏธ๋์ฐจํธ. */
const SPARK = "โโโโโ
โโโ";
export function Sparkline({
data,
tone,
className,
}: {
data: number[];
tone?: Tone;
className?: string;
}) {
const min = Math.min(...data);
const max = Math.max(...data);
const span = max - min || 1;
const chars = data
.map((v) => SPARK[Math.round(((v - min) / span) * (SPARK.length - 1))])
.join("");
const auto = data[data.length - 1] >= data[0] ? "up" : "down";
return (
<span className={cn("tracking-tighter", TEXT_TONE[tone ?? (auto as Tone)], className)}>
{chars}
</span>
);
}
/** ๋น์จ ๋ฐ โ 0~100% ์ฑ์. */
export function Bar({
pct,
tone = "up",
className,
}: {
pct: number;
tone?: Tone;
className?: string;
}) {
const bg: Record<Tone, string> = {
default: "bg-term-white",
accent: "bg-term-accent",
up: "bg-term-up",
down: "bg-term-down",
info: "bg-term-info",
warn: "bg-term-warn",
mag: "bg-term-mag",
};
return (
<span className={cn("bevel-in flex h-2 w-full bg-term-elevated", className)}>
<span
className={cn("h-full", bg[tone])}
style={{ width: `${Math.max(0, Math.min(100, pct))}%` }}
/>
</span>
);
}
/** ์คํฌ๋กค ํฐ์ปค ํ
์ดํ. */
export function TickerTape({
items,
}: {
items: { sym: string; px: string; chg: number }[];
}) {
const doubled = [...items, ...items];
return (
<div className="overflow-hidden border-y border-term-border bg-term-bg py-0.5">
<div className="ticker-track">
{doubled.map((it, i) => (
<span key={i} className="mx-3 inline-flex items-baseline gap-1.5 text-[11px]">
<span className="font-bold text-term-accent">{it.sym}</span>
<span className="tabular-nums text-term-white">{it.px}</span>
<span
className={cn(
"tabular-nums",
it.chg >= 0 ? "text-term-up" : "text-term-down",
)}
>
{it.chg >= 0 ? "โฒ" : "โผ"}
{Math.abs(it.chg).toFixed(2)}%
</span>
</span>
))}
</div>
</div>
);
}
/** ํ๋จ ๋ฒํธ ๋ด์ค ํผ๋ โ ์ฃผํฉ ๋ฒํธ + ํค๋๋ผ์ธ. */
export function NewsFeed({
items,
}: {
items: { n: number; h: string; t: string }[];
}) {
return (
<div className="bg-term-bg">
{items.map((it) => (
<div
key={it.n}
className="flex items-baseline gap-2 border-b border-term-grid px-1 py-px text-[11px] leading-tight last:border-0"
>
<span className="shrink-0 font-bold tabular-nums text-term-accent">
{it.n}
</span>
<span className="min-w-0 flex-1 truncate text-term-white">{it.h}</span>
<span className="shrink-0 tabular-nums text-term-faint">{it.t}</span>
</div>
))}
</div>
);
}
/** ํ๋กฌํํธ ๋ผ๋ฒจ. */
export function Prompt({ children }: { children: ReactNode }) {
return (
<span className="text-term-accent">
<span className="text-term-faint">{">"}</span> {children}
</span>
);
}