2023-07-11 08:16:17 +00:00
|
|
|
import { Loading, cloneChildren } from 'react-basics';
|
2020-10-04 05:36:51 +00:00
|
|
|
import ErrorMessage from 'components/common/ErrorMessage';
|
2023-10-04 23:04:10 +00:00
|
|
|
import { formatLongNumber } from 'lib/format';
|
2023-10-03 06:51:26 +00:00
|
|
|
import styles from './MetricsBar.module.css';
|
2023-07-11 08:16:17 +00:00
|
|
|
|
|
|
|
|
export function MetricsBar({ children, isLoading, isFetched, error }) {
|
2023-10-04 23:04:10 +00:00
|
|
|
const formatFunc = n => (n >= 0 ? formatLongNumber(n) : `-${formatLongNumber(Math.abs(n))}`);
|
2020-07-29 02:04:45 +00:00
|
|
|
|
|
|
|
|
return (
|
2023-10-04 23:04:10 +00:00
|
|
|
<div className={styles.bar}>
|
2023-02-04 16:59:52 +00:00
|
|
|
{isLoading && !isFetched && <Loading icon="dots" />}
|
2020-10-04 05:36:51 +00:00
|
|
|
{error && <ErrorMessage />}
|
2023-10-03 06:51:26 +00:00
|
|
|
{!isLoading &&
|
|
|
|
|
!error &&
|
|
|
|
|
isFetched &&
|
|
|
|
|
cloneChildren(children, child => {
|
|
|
|
|
return { format: child.props.format || formatFunc };
|
|
|
|
|
})}
|
2020-07-29 02:04:45 +00:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-04-21 15:00:42 +00:00
|
|
|
|
|
|
|
|
export default MetricsBar;
|