From 228cc6105dc8d8531e1963a0c15cead17423ca8c Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 14 Oct 2025 23:15:16 +0800 Subject: [PATCH] chore: update StatCard component for improved icon and count rendering in StatisticsView --- .../components/StatisticsView/StatCard.tsx | 64 ++++++++++++------- .../StatisticsView/StatisticsView.tsx | 16 ++--- 2 files changed, 46 insertions(+), 34 deletions(-) diff --git a/web/src/components/StatisticsView/StatCard.tsx b/web/src/components/StatisticsView/StatCard.tsx index e33a58160..48673a579 100644 --- a/web/src/components/StatisticsView/StatCard.tsx +++ b/web/src/components/StatisticsView/StatCard.tsx @@ -1,37 +1,55 @@ +import { cloneElement, isValidElement } from "react"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; import { cn } from "@/lib/utils"; import type { StatCardProps } from "@/types/statistics"; export const StatCard = ({ icon, label, count, onClick, tooltip, className }: StatCardProps) => { - const content = ( -
{ + if (typeof count === "number" || typeof count === "string") { + return {count}; + } + if (isValidElement(count)) { + return cloneElement(count, { + className: cn("text-foreground/80", count.props.className), + }); + } + return {count}; + })(); + + const button = ( +
+ {iconNode} + {label} + {countNode} + ); - if (tooltip) { - return ( - - - {content} - -

{tooltip}

-
-
-
- ); + if (!tooltip) { + return button; } - return content; + return ( + + + {button} + +

{tooltip}

+
+
+
+ ); }; diff --git a/web/src/components/StatisticsView/StatisticsView.tsx b/web/src/components/StatisticsView/StatisticsView.tsx index feed59ba5..387a97a7c 100644 --- a/web/src/components/StatisticsView/StatisticsView.tsx +++ b/web/src/components/StatisticsView/StatisticsView.tsx @@ -46,10 +46,10 @@ const StatisticsView = observer(() => { /> -
+
{isRootPath && hasPinnedMemos && ( } + icon={} label={t("common.pinned")} count={userStore.state.currentUserStats!.pinnedMemos.length} onClick={() => handleFilterClick("pinned")} @@ -57,20 +57,14 @@ const StatisticsView = observer(() => { )} } + icon={} label={t("memo.links")} count={memoTypeStats.linkCount} onClick={() => handleFilterClick("property.hasLink")} /> 0 ? ( - - ) : ( - - ) - } + icon={memoTypeStats.undoCount > 0 ? : } label={t("memo.to-do")} count={ memoTypeStats.undoCount > 0 ? ( @@ -88,7 +82,7 @@ const StatisticsView = observer(() => { /> } + icon={} label={t("memo.code")} count={memoTypeStats.codeCount} onClick={() => handleFilterClick("property.hasCode")}