import type { TooltipContentProps, TooltipPayloadEntry } from 'recharts'; import { formatCurrency, formatCompactCurrency } from '@/lib/format'; import { getChartColors } from '../utils/chart-colors'; import { isOHLCVData } from '../utils/chart-data-transformers'; type ChartTooltipProps = TooltipContentProps & { formatters?: { price?: (value: number) => string; date?: (value: string) => string; volume?: (value: number) => string; }; }; export function ChartTooltip(props: ChartTooltipProps) { const { active, payload, label, formatters } = props; if (!active || !payload || payload.length === 0) return null; const colors = getChartColors(); const formatDate = formatters?.date || ((date: string) => new Date(date).toLocaleDateString()); const formatPrice = formatters?.price || formatCurrency; const formatVolume = formatters?.volume || formatCompactCurrency; const data = payload[0].payload; return (
{formatDate(label as string)}
{isOHLCVData(data) ? (
) : (
{payload.map((entry: TooltipPayloadEntry, index: number) => ( ))}
)}
); } type TooltipRowProps = { label: string; value: string; color: string; }; function TooltipRow({ label, value, color }: TooltipRowProps) { return (
{label}: {value}
); }