diff --git a/packages/widgets/src/dns-hole/summary/component.tsx b/packages/widgets/src/dns-hole/summary/component.tsx index 239d02295..32504a70d 100644 --- a/packages/widgets/src/dns-hole/summary/component.tsx +++ b/packages/widgets/src/dns-hole/summary/component.tsx @@ -63,7 +63,7 @@ export default function DnsHoleSummaryWidget({ options, integrationIds }: Widget const data = useMemo(() => summaries.flatMap(({ summary }) => summary), [summaries]); return ( - + {data.length > 0 ? ( stats.map((item) => ( @@ -89,43 +89,43 @@ export default function DnsHoleSummaryWidget({ options, integrationIds }: Widget const stats = [ { icon: IconBarrierBlock, - value: (data) => + value: (data, size) => formatNumber( data.reduce((count, { adsBlockedToday }) => count + adsBlockedToday, 0), - 2, + size === "sm" ? 0 : 2, ), label: (t) => t("widget.dnsHoleSummary.data.adsBlockedToday"), color: "rgba(240, 82, 60, 0.4)", // RED }, { icon: IconPercentage, - value: (data) => { + value: (data, size) => { const totalCount = data.reduce((count, { dnsQueriesToday }) => count + dnsQueriesToday, 0); const blocked = data.reduce((count, { adsBlockedToday }) => count + adsBlockedToday, 0); - return `${formatNumber(totalCount === 0 ? 0 : (blocked / totalCount) * 100, 2)}%`; + return `${formatNumber(totalCount === 0 ? 0 : (blocked / totalCount) * 100, size === "sm" ? 0 : 2)}%`; }, label: (t) => t("widget.dnsHoleSummary.data.adsBlockedTodayPercentage"), color: "rgba(255, 165, 20, 0.4)", // YELLOW }, { icon: IconSearch, - value: (data) => + value: (data, size) => formatNumber( data.reduce((count, { dnsQueriesToday }) => count + dnsQueriesToday, 0), - 2, + size === "sm" ? 0 : 2, ), label: (t) => t("widget.dnsHoleSummary.data.dnsQueriesToday"), color: "rgba(0, 175, 218, 0.4)", // BLUE }, { icon: IconWorldWww, - value: (data) => { + value: (data, size) => { // We use a suffix to indicate that there might be more domains in the at least two lists. const suffix = data.length >= 2 ? "+" : ""; return ( formatNumber( data.reduce((count, { domainsBeingBlocked }) => count + domainsBeingBlocked, 0), - 2, + size === "sm" ? 0 : 2, ) + suffix ); }, @@ -137,7 +137,7 @@ const stats = [ interface StatItem { icon: TablerIcon; - value: (summaries: DnsHoleSummary[]) => string; + value: (summaries: DnsHoleSummary[], size: "sm" | "md") => string; tooltip?: (summaries: DnsHoleSummary[], t: TranslationFunction) => string | undefined; label: stringOrTranslation; color: string; @@ -152,6 +152,7 @@ interface StatCardProps { const StatCard = ({ item, data, usePiHoleColors, t }: StatCardProps) => { const { ref, height, width } = useElementSize(); const isLong = width > height + 20; + const hideLabel = (height <= 32 && width <= 256) || (height <= 64 && width <= 92); const tooltip = item.tooltip?.(data, t); const board = useRequiredBoard(); @@ -174,25 +175,26 @@ const StatCard = ({ item, data, usePiHoleColors, t }: StatCardProps) => { align="center" justify="center" direction={isLong ? "row" : "column"} - style={{ containerType: "size" }} + gap={0} > - + - - {item.value(data)} + + {item.value(data, width <= 64 ? "sm" : "md")} - {item.label && ( - + {!hideLabel && ( + {translateIfNecessary(t, item.label)} )}