/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import useCountUp from '../../../hooks/common/useCountUp';
/**
* 企业中心统一统计卡(KPI 卡,方案 A+ 底盘层)。
* 实底、紧凑、tabular-nums 等宽数字;图标品牌色浅底(不再渐变实底);
* 数值可选 count-up 滚动(签名层动效,respect prefers-reduced-motion)。
*
* @param {React.ComponentType} icon lucide 图标组件
* @param {React.ReactNode} label 标题(兼容旧用法的 title)
* @param {React.ReactNode} title label 的别名
* @param {React.ReactNode} value 主数值(直接展示)
* @param {number} [countTo] 数值 count-up 目标;提供时优先于 value 渲染
* @param {(n:number)=>React.ReactNode} [formatter] countTo 的格式化函数(默认 toLocaleString)
* @param {number} [decimals] countTo 保留小数位,默认 0
* @param {React.ReactNode} [hint] 副说明(兼容旧用法的 subtitle)
* @param {React.ReactNode} [subtitle] hint 的别名
* @param {React.ReactNode} [extra] 底部扩展槽(进度条等)
* @param {string} [tone] 'brand' | 'amber' | 'rose' | 'sky' | 'violet'
* @param {boolean} [danger] 危险态(红色强调),等价于 tone='rose'
* @param {boolean} [loading] 骨架加载态
* @param {boolean} [compact] 紧凑横向布局(用于密集 KPI 行)
* @param {string} [className] 追加类名
*/
// tone -> 图标浅底色/数值强调色。底盘层原则:色彩只用于图标与语义强调,不再渐变铺装饰。
const TONES = {
brand: {
icon: 'bg-brand/10 text-brand',
value: 'text-[var(--text-primary)]',
},
amber: {
icon: 'bg-amber-500/10 text-amber-600 dark:text-amber-400',
value: 'text-[var(--text-primary)]',
},
rose: {
icon: 'bg-rose-500/10 text-rose-600 dark:text-rose-400',
value: 'text-rose-600 dark:text-rose-400',
},
sky: {
icon: 'bg-sky-500/10 text-sky-600 dark:text-sky-400',
value: 'text-[var(--text-primary)]',
},
violet: {
icon: 'bg-violet-500/10 text-violet-600 dark:text-violet-400',
value: 'text-[var(--text-primary)]',
},
};
const OrgStatCard = ({
icon: Icon,
label,
title,
value,
countTo,
formatter,
decimals = 0,
hint,
subtitle,
extra,
tone = 'brand',
danger = false,
loading = false,
compact = false,
className = '',
}) => {
const resolvedTone = danger ? 'rose' : tone;
const palette = TONES[resolvedTone] || TONES.brand;
const heading = label ?? title;
const sub = hint ?? subtitle;
const hasCountUp = typeof countTo === 'number';
const animated = useCountUp(hasCountUp ? countTo : 0, { decimals });
const displayValue = hasCountUp
? formatter
? formatter(animated)
: animated.toLocaleString()
: value;
return (
{Icon && (
)}
{compact && (
{heading}
{loading ? (
) : (
{displayValue}
)}
)}
{!compact && (
{heading}
)}
{!compact &&
(loading ? (
) : (
<>
{displayValue}
{sub && (
{sub}
)}
{extra &&
{extra}
}
>
))}
);
};
export default OrgStatCard;