import React from 'react'; import { Icon } from 'UI'; import styles from './countBadge.module.css'; import cn from 'classnames'; const getFixedValue = (val) => { let accuracy = 0; while (Math.trunc(val * Math.pow(10, accuracy)) === 0) { accuracy += 1; } const parsed = parseFloat(val).toFixed(accuracy).toString(); return parsed; }; // eslint-disable-next-line complexity const 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;