import { Tag, Typography } from 'antd'; import { useTheme } from 'antd-style'; import { CSSProperties, memo } from 'react'; import { Flexbox } from 'react-layout-kit'; import { calcGrowthPercentage } from './growthPercentage'; const { Title } = Typography; interface TitleWithPercentageProps { count?: number; inverseColor?: boolean; prvCount?: number; title: string; } const TitleWithPercentage = memo( ({ inverseColor, title, prvCount, count }) => { const percentage = calcGrowthPercentage(count || 0, prvCount || 0); const theme = useTheme(); const upStyle: CSSProperties = { background: theme.colorSuccessBg, borderColor: theme.colorSuccessBorder, color: theme.colorSuccess, }; const downStyle: CSSProperties = { backgroundColor: theme.colorWarningBg, borderColor: theme.colorWarningBorder, color: theme.colorWarning, }; return ( {title} {count && prvCount && percentage && percentage !== 0 ? ( 0 ? downStyle : upStyle : percentage > 0 ? upStyle : downStyle), }} > {percentage > 0 ? '+' : ''} {percentage.toFixed(1)}% ) : null} ); }, ); export default TitleWithPercentage;