2026-02-10 11:16:39 +09:00
|
|
|
// import { Badge } from "@/components/ui/badge";
|
|
|
|
|
import { Separator } from "@/components/ui/separator";
|
2026-02-24 15:43:56 +09:00
|
|
|
import type { DashboardStockItem } from "@/features/trade/types/trade.types";
|
2026-02-10 11:16:39 +09:00
|
|
|
import { cn } from "@/lib/utils";
|
|
|
|
|
|
|
|
|
|
interface StockHeaderProps {
|
|
|
|
|
stock: DashboardStockItem;
|
|
|
|
|
price: string;
|
|
|
|
|
change: string;
|
|
|
|
|
changeRate: string;
|
|
|
|
|
high?: string;
|
|
|
|
|
low?: string;
|
|
|
|
|
volume?: string;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-24 15:43:56 +09:00
|
|
|
/**
|
|
|
|
|
* @description 선택된 종목의 현재가/등락/시세 요약 헤더를 렌더링합니다.
|
|
|
|
|
* @see features/trade/components/layout/TradeDashboardContent.tsx - StockHeader 사용 (header prop으로 전달)
|
|
|
|
|
*/
|
2026-02-10 11:16:39 +09:00
|
|
|
export function StockHeader({
|
|
|
|
|
stock,
|
|
|
|
|
price,
|
|
|
|
|
change,
|
|
|
|
|
changeRate,
|
|
|
|
|
high,
|
|
|
|
|
low,
|
|
|
|
|
volume,
|
|
|
|
|
}: StockHeaderProps) {
|
2026-02-24 15:43:56 +09:00
|
|
|
const changeRateNum = parseFloat(changeRate);
|
|
|
|
|
const isRise = changeRateNum > 0;
|
|
|
|
|
const isFall = changeRateNum < 0;
|
2026-02-10 11:16:39 +09:00
|
|
|
const colorClass = isRise
|
|
|
|
|
? "text-red-500"
|
|
|
|
|
: isFall
|
2026-02-11 14:06:06 +09:00
|
|
|
? "text-blue-600 dark:text-blue-400"
|
2026-02-10 11:16:39 +09:00
|
|
|
: "text-foreground";
|
|
|
|
|
|
2026-02-24 15:43:56 +09:00
|
|
|
const bgGlowClass = isRise
|
|
|
|
|
? "from-red-500/10 to-transparent dark:from-red-500/15"
|
|
|
|
|
: isFall
|
|
|
|
|
? "from-blue-500/10 to-transparent dark:from-blue-500/15"
|
|
|
|
|
: "from-brand-500/10 to-transparent";
|
|
|
|
|
|
|
|
|
|
// 전일종가 계산 (현재가 - 변동액)
|
|
|
|
|
const prevClose =
|
|
|
|
|
stock.prevClose > 0 ? stock.prevClose.toLocaleString("ko-KR") : "--";
|
|
|
|
|
const open = stock.open > 0 ? stock.open.toLocaleString("ko-KR") : "--";
|
|
|
|
|
|
2026-02-10 11:16:39 +09:00
|
|
|
return (
|
2026-02-24 15:43:56 +09:00
|
|
|
<div className="bg-white px-3 py-2 dark:bg-brand-900/22 sm:px-4">
|
2026-02-10 11:16:39 +09:00
|
|
|
{/* ========== STOCK SUMMARY ========== */}
|
|
|
|
|
<div className="flex items-start justify-between gap-3">
|
2026-02-24 15:43:56 +09:00
|
|
|
{/* 종목명 + 코드 */}
|
|
|
|
|
<div className="min-w-0 flex-1">
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<h1 className="truncate text-base font-bold leading-tight text-foreground dark:text-brand-50 sm:text-lg">
|
|
|
|
|
{stock.name}
|
|
|
|
|
</h1>
|
|
|
|
|
<span className="shrink-0 rounded border border-brand-200/60 bg-brand-50/50 px-1.5 py-0.5 text-[10px] font-medium text-brand-600 dark:border-brand-700/45 dark:bg-brand-900/30 dark:text-brand-200">
|
|
|
|
|
{stock.market}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
2026-02-13 16:41:10 +09:00
|
|
|
<span className="mt-0.5 block text-[11px] text-muted-foreground dark:text-brand-100/70 sm:text-xs">
|
2026-02-24 15:43:56 +09:00
|
|
|
{stock.symbol}
|
2026-02-10 11:16:39 +09:00
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-02-24 15:43:56 +09:00
|
|
|
{/* 현재가 + 등락 */}
|
|
|
|
|
<div
|
|
|
|
|
className={cn(
|
|
|
|
|
"shrink-0 rounded-lg bg-linear-to-l px-3 py-1.5 text-right",
|
|
|
|
|
bgGlowClass,
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<span
|
|
|
|
|
className={cn(
|
|
|
|
|
"block text-xl font-bold tracking-tight tabular-nums sm:text-2xl",
|
|
|
|
|
colorClass,
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{price}
|
2026-02-10 11:16:39 +09:00
|
|
|
</span>
|
2026-02-24 15:43:56 +09:00
|
|
|
<div className="flex items-center justify-end gap-1.5">
|
|
|
|
|
<span
|
|
|
|
|
className={cn(
|
|
|
|
|
"text-[11px] font-medium tabular-nums sm:text-xs",
|
|
|
|
|
colorClass,
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{isRise ? "▲" : isFall ? "▼" : ""}
|
|
|
|
|
{changeRate}%
|
|
|
|
|
</span>
|
|
|
|
|
<span
|
|
|
|
|
className={cn("text-[11px] tabular-nums sm:text-xs", colorClass)}
|
|
|
|
|
>
|
|
|
|
|
{isRise && "+"}
|
|
|
|
|
{change}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
2026-02-10 11:16:39 +09:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-02-24 15:43:56 +09:00
|
|
|
{/* ========== MOBILE STATS ========== */}
|
|
|
|
|
<div className="mt-2 grid grid-cols-3 gap-1.5 text-xs md:hidden">
|
|
|
|
|
<StatCard label="고가" value={high || "--"} tone="ask" />
|
|
|
|
|
<StatCard label="저가" value={low || "--"} tone="bid" />
|
|
|
|
|
<StatCard label="거래량" value={volume || "--"} />
|
2026-02-10 11:16:39 +09:00
|
|
|
</div>
|
|
|
|
|
|
2026-02-13 16:41:10 +09:00
|
|
|
<Separator className="mt-1.5 md:hidden" />
|
2026-02-10 11:16:39 +09:00
|
|
|
|
|
|
|
|
{/* ========== DESKTOP STATS ========== */}
|
2026-02-24 15:43:56 +09:00
|
|
|
<div className="hidden items-center justify-end gap-4 pt-1.5 md:flex">
|
|
|
|
|
<DesktopStat label="전일종가" value={prevClose} />
|
|
|
|
|
<DesktopStat label="시가" value={open} />
|
|
|
|
|
<DesktopStat label="고가" value={high || "--"} tone="ask" />
|
|
|
|
|
<DesktopStat label="저가" value={low || "--"} tone="bid" />
|
|
|
|
|
<DesktopStat label="거래량" value={volume ? `${volume}주` : "--"} />
|
2026-02-10 11:16:39 +09:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-02-24 15:43:56 +09:00
|
|
|
|
|
|
|
|
/** 모바일 통계 카드 */
|
|
|
|
|
function StatCard({
|
|
|
|
|
label,
|
|
|
|
|
value,
|
|
|
|
|
tone,
|
|
|
|
|
}: {
|
|
|
|
|
label: string;
|
|
|
|
|
value: string;
|
|
|
|
|
tone?: "ask" | "bid";
|
|
|
|
|
}) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="rounded-md bg-muted/40 px-2 py-1.5 dark:border dark:border-brand-800/45 dark:bg-brand-900/25">
|
|
|
|
|
<p className="text-[11px] text-muted-foreground dark:text-brand-100/70">
|
|
|
|
|
{label}
|
|
|
|
|
</p>
|
|
|
|
|
<p
|
|
|
|
|
className={cn(
|
|
|
|
|
"font-semibold",
|
|
|
|
|
tone === "ask" && "text-red-500",
|
|
|
|
|
tone === "bid" && "text-blue-600 dark:text-blue-400",
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{value}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 데스크톱 통계 항목 */
|
|
|
|
|
function DesktopStat({
|
|
|
|
|
label,
|
|
|
|
|
value,
|
|
|
|
|
tone,
|
|
|
|
|
}: {
|
|
|
|
|
label: string;
|
|
|
|
|
value: string;
|
|
|
|
|
tone?: "ask" | "bid";
|
|
|
|
|
}) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col items-end">
|
|
|
|
|
<span className="text-[11px] text-muted-foreground dark:text-brand-100/70">
|
|
|
|
|
{label}
|
|
|
|
|
</span>
|
|
|
|
|
<span
|
|
|
|
|
className={cn(
|
|
|
|
|
"text-sm font-semibold tabular-nums",
|
|
|
|
|
tone === "ask" && "text-red-500",
|
|
|
|
|
tone === "bid" && "text-blue-600 dark:text-blue-400",
|
|
|
|
|
!tone && "text-foreground dark:text-brand-50",
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{value}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|