StatsCards.jsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. Copyright (C) 2025 QuantumNous
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. For commercial licensing, please contact support@quantumnous.com
  14. */
  15. import React from 'react';
  16. import { Card, Avatar, Skeleton } from '@douyinfe/semi-ui';
  17. import { VChart } from '@visactor/react-vchart';
  18. const StatsCards = ({
  19. groupedStatsData,
  20. loading,
  21. getTrendSpec,
  22. CARD_PROPS,
  23. CHART_CONFIG
  24. }) => {
  25. return (
  26. <div className="mb-4">
  27. <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
  28. {groupedStatsData.map((group, idx) => (
  29. <Card
  30. key={idx}
  31. {...CARD_PROPS}
  32. className={`${group.color} border-0 !rounded-2xl w-full`}
  33. title={group.title}
  34. >
  35. <div className="space-y-4">
  36. {group.items.map((item, itemIdx) => (
  37. <div
  38. key={itemIdx}
  39. className="flex items-center justify-between cursor-pointer"
  40. onClick={item.onClick}
  41. >
  42. <div className="flex items-center">
  43. <Avatar
  44. className="mr-3"
  45. size="small"
  46. color={item.avatarColor}
  47. >
  48. {item.icon}
  49. </Avatar>
  50. <div>
  51. <div className="text-xs text-gray-500">{item.title}</div>
  52. <div className="text-lg font-semibold">
  53. <Skeleton
  54. loading={loading}
  55. active
  56. placeholder={
  57. <Skeleton.Paragraph
  58. active
  59. rows={1}
  60. style={{ width: '65px', height: '24px', marginTop: '4px' }}
  61. />
  62. }
  63. >
  64. {item.value}
  65. </Skeleton>
  66. </div>
  67. </div>
  68. </div>
  69. {(loading || (item.trendData && item.trendData.length > 0)) && (
  70. <div className="w-24 h-10">
  71. <VChart
  72. spec={getTrendSpec(item.trendData, item.trendColor)}
  73. option={CHART_CONFIG}
  74. />
  75. </div>
  76. )}
  77. </div>
  78. ))}
  79. </div>
  80. </Card>
  81. ))}
  82. </div>
  83. </div>
  84. );
  85. };
  86. export default StatsCards;