- Sparkline 컴포넌트를 PriceHero 내부에서 web/components/Sparkline.tsx 로 분리·재사용 - /api/markets/indices: macro_daily 의 kospi/kosdaq N일 시계열 + 최신값/전일대비 - 홈 IndicesPanel: 두 인덱스 카드(현재값/등락/우측 sparkline) - /api/symbols/search?with_sparkline=true: 결과 한 번에 최근 30 종가 batch 조회 - SearchBox 결과 행에 mini sparkline + 현재가/등락률 인라인 표시 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
64 lines
2.0 KiB
TypeScript
64 lines
2.0 KiB
TypeScript
"use client";
|
|
|
|
// 종목 페이지 상단 가격 헤더.
|
|
// 표시: 종목명 / (코드·시장) / 현재가 / 전일대비 + 우측에 sparkline.
|
|
// 한국 거래소 관행대로 상승=빨강, 하락=파랑.
|
|
|
|
import { Sparkline } from "./Sparkline";
|
|
|
|
type Props = {
|
|
name: string;
|
|
code: string;
|
|
market: string;
|
|
current: number | null;
|
|
prev: number | null;
|
|
asOf?: string | null;
|
|
// 헤더 우측 sparkline 용 종가 시계열 (오래된 → 최신 순). 비어 있으면 미표시.
|
|
series?: number[];
|
|
};
|
|
|
|
export function PriceHero({ name, code, market, current, prev, asOf, series }: Props) {
|
|
const change = current != null && prev != null ? current - prev : null;
|
|
const pct = change != null && prev ? (change / prev) * 100 : null;
|
|
const tone =
|
|
change == null || change === 0
|
|
? "text-zinc-400"
|
|
: change > 0
|
|
? "text-rose-400"
|
|
: "text-sky-400";
|
|
const arrow = change == null || change === 0 ? "—" : change > 0 ? "▲" : "▼";
|
|
|
|
return (
|
|
<div className="mb-5 flex items-end justify-between gap-4">
|
|
<div>
|
|
<div className="text-xs text-zinc-500">
|
|
{code} · {market}
|
|
</div>
|
|
<h1 className="mt-0.5 text-2xl font-bold tracking-tight text-zinc-50">
|
|
{name}
|
|
</h1>
|
|
<div className="mt-3 flex items-baseline gap-3">
|
|
<span className="text-4xl font-semibold tabular-nums text-zinc-50">
|
|
{current != null ? current.toLocaleString() : "-"}
|
|
</span>
|
|
{change != null && pct != null && (
|
|
<span className={`text-base font-medium tabular-nums ${tone}`}>
|
|
{arrow} {Math.abs(change).toLocaleString()}{" "}
|
|
({pct >= 0 ? "+" : ""}
|
|
{pct.toFixed(2)}%)
|
|
</span>
|
|
)}
|
|
</div>
|
|
{asOf && <div className="mt-1 text-xs text-zinc-500">기준 {asOf}</div>}
|
|
</div>
|
|
|
|
{series && series.length >= 2 && (
|
|
<Sparkline
|
|
values={series}
|
|
stroke={change != null && change < 0 ? "#3b82f6" : "#ef4444"}
|
|
/>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|