diff --git a/desktop-app/renderer/components/custom/panel/panelCard.tsx b/desktop-app/renderer/components/custom/panel/panelCard.tsx index dcc481cd..3d32b6bb 100644 --- a/desktop-app/renderer/components/custom/panel/panelCard.tsx +++ b/desktop-app/renderer/components/custom/panel/panelCard.tsx @@ -22,7 +22,7 @@ interface CardComponentProps { children: React.ReactNode className?: string title?: ReactNode - badge?: string + badge?: ReactNode description?: string descriptionClassName?: string tooltip?: string @@ -38,7 +38,6 @@ const CardComponent = React.forwardRef( title, badge, description, - descriptionClassName, cardType, onClick, ...props @@ -59,11 +58,14 @@ const CardComponent = React.forwardRef( {(title || badge) && ( {title} - {badge && ( - - {badge} - - )} + {badge && + (typeof badge === 'string' ? ( + + {badge} + + ) : ( + {badge} + ))} )} ( } > {children} - {description && ( - - {description} - - )} + {description && {description}} ) @@ -91,7 +89,6 @@ export default function PanelCard({ title = '', badge = '', description = '', - descriptionClassName = '', cardType = 'button', tooltip = '', onClick = () => {} @@ -99,9 +96,8 @@ export default function PanelCard({ children: ReactNode className?: string title?: ReactNode - badge?: string + badge?: ReactNode description?: string - descriptionClassName?: string cardType?: CardType tooltip?: ReactNode onClick?: () => void @@ -116,7 +112,6 @@ export default function PanelCard({ badge={badge} onClick={onClick} description={description} - descriptionClassName={descriptionClassName} cardType={cardType} > {children} @@ -132,7 +127,6 @@ export default function PanelCard({ badge={badge} onClick={onClick} description={description} - descriptionClassName={descriptionClassName} cardType={cardType} > {children} diff --git a/desktop-app/renderer/components/custom/panel/valuePanelCard.tsx b/desktop-app/renderer/components/custom/panel/valuePanelCard.tsx index d7b3a9d6..2b66b82a 100644 --- a/desktop-app/renderer/components/custom/panel/valuePanelCard.tsx +++ b/desktop-app/renderer/components/custom/panel/valuePanelCard.tsx @@ -1,54 +1,76 @@ -import PanelCard from '@/components/custom/panel/panelCard' -import React from 'react' +import PanelCard, { CardType } from '@/components/custom/panel/panelCard' +import { BadgeDelta } from '@tremor/react' +import { ReactNode } from 'react' -function changeValueColor(value: number): string { - if (value > 0) { - return 'text-green-600' - } else if (value < 0) { - return 'text-red-500' - } else { - return 'text-muted-foreground' +function getDeltaType({ delta }: { delta: number }): string { + // switch case on delta if delta is not defined + if (delta >= 5) { + return 'increase' } -} - -function formatChangeValue(delta: number): string { - return `${delta >= 0 ? '+' : ''}${Intl.NumberFormat('us-US', { - maximumSignificantDigits: 3 - }).format(delta)}%` + if (delta > 0 && delta < 5) { + return 'moderateIncrease' + } + if (delta === 0) { + return 'unchanged' + } + if (delta < 0 && delta > -5) { + return 'moderateDecrease' + } + return 'decrease' } function formatCurrencyValue(value: number): string { - return Intl.NumberFormat('us-US', { - style: 'currency', - currency: 'USD' - }).format(value) + return `$${value.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')}` } function ValuePanelCard({ title = '', - badge = '', value = 0, - delta = 0, + delta = 2, + description = '', + cardType = 'button', tooltip = '', onClick = () => {} }: { - title: string | React.ReactNode - badge?: string + title?: ReactNode value: number delta?: number + description?: string + cardType?: CardType tooltip?: string onClick?: () => void }): JSX.Element { + const badge = ( + + {delta >= 0 + ? `+${delta.toFixed(delta % 1 == 0 ? 0 : 1)}` + : delta.toFixed(delta % 1 == 0 ? 0 : 1)}{' '} + % + + ) return ( -
{formatCurrencyValue(value)}
+
+ {formatCurrencyValue(value)} +
) }