import React from 'react'; import { useSpring, animated } from 'react-spring'; import { formatNumber } from 'lib/format'; import styles from './MetricCard.module.css'; const MetricCard = ({ value = 0, change = 0, label, reverseColors = false, format = formatNumber, hideComparison = false, }) => { const props = useSpring({ x: Number(value) || 0, from: { x: 0 } }); const changeProps = useSpring({ x: Number(change) || 0, from: { x: 0 } }); return (
{props.x.interpolate(x => format(x))}
{label} {~~change !== 0 && !hideComparison && ( = 0 ? !reverseColors ? styles.positive : styles.negative : !reverseColors ? styles.negative : styles.positive } ${change >= 0 ? styles.plusSign : ''}`} > {changeProps.x.interpolate(x => format(x))} )}
); }; export default MetricCard;