import React from 'react'; import { Icon } from 'UI'; import cn from 'classnames'; import styles from './countBadge.module.css'; const getFixedValue = (val) => { let accuracy = 0; while (Math.trunc(val * 10 ** accuracy) === 0) { accuracy += 1; } const parsed = parseFloat(val).toFixed(accuracy).toString(); return parsed; }; function CountBadge({ title, icon, count = '', unit = '', change, oppositeColors = false, component, className, }) { const viewChange = typeof change === 'number' && change !== 0; const changeIncrease = change > 0; const colorGreen = oppositeColors ? !changeIncrease : changeIncrease; return (
{icon && ( )} {component || count} {unit}
{viewChange && (
{`${getFixedValue(change)}%`}
)}
); } CountBadge.displayName = 'CountBadge'; export default CountBadge;