umami/components/charts/MetricCard.js

21 lines
557 B
JavaScript
Raw Normal View History

2020-07-30 10:08:21 +02:00
import React from 'react';
2020-07-30 05:09:41 +02:00
import { useSpring, animated } from 'react-spring';
import styles from './MetricCard.module.css';
2020-07-30 05:09:41 +02:00
function defaultFormat(n) {
return Number(n).toFixed(0);
}
const MetricCard = ({ value = 0, label, format = defaultFormat }) => {
const props = useSpring({ x: value, from: { x: 0 } });
return (
<div className={styles.card}>
<animated.div className={styles.value}>{props.x.interpolate(x => format(x))}</animated.div>
<div className={styles.label}>{label}</div>
</div>
);
};
export default MetricCard;