StatTile.tsx
1.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
import type { ReactNode } from 'react';
export interface StatTileProps {
label: ReactNode;
value: ReactNode;
/** 数值单位,如「起」 */
unit?: ReactNode;
/** 辅助说明行(对比值、口径说明) */
hint?: ReactNode;
/** 数值强调色。不传则用默认文本色 */
tone?: 'default' | 'primary' | 'cyan' | 'gold' | 'danger';
className?: string;
}
const TONE_VAR: Record<NonNullable<StatTileProps['tone']>, string> = {
default: 'var(--hm-text-1)',
primary: 'var(--hm-primary)',
cyan: 'var(--hm-accent-cyan)',
gold: 'var(--hm-accent-gold-deep)',
danger: 'var(--hm-error)',
};
/** 指标块:大数字 + 口径说明。左栏概览区的最小信息单元 */
export function StatTile({ label, value, unit, hint, tone = 'default', className }: StatTileProps) {
return (
<div className={['hm-stat', className].filter(Boolean).join(' ')}>
<div className="hm-stat__label">{label}</div>
<div className="hm-stat__value" style={{ color: TONE_VAR[tone] }}>
{value}
{unit && <span className="hm-stat__unit">{unit}</span>}
</div>
{hint && <div className="hm-stat__hint">{hint}</div>}
</div>
);
}
export function StatGrid({ children, columns = 2 }: { children: ReactNode; columns?: number }) {
return (
<div className="hm-stat-grid" style={{ gridTemplateColumns: `repeat(${columns}, minmax(0,1fr))` }}>
{children}
</div>
);
}