import { FixedSizeList } from 'react-window'; import { useSpring, animated, config } from '@react-spring/web'; import classNames from 'classnames'; import Empty from 'components/common/Empty'; import { formatLongNumber } from 'lib/format'; import useMessages from 'components/hooks/useMessages'; import styles from './ListTable.module.css'; const ITEM_SIZE = 30; export function ListTable({ data = [], title, metric, className, renderLabel, animate = true, virtualize = false, showPercentage = true, itemCount = 10, }) { const { formatMessage, labels } = useMessages(); const getRow = row => { const { x: label, y: value, z: percent } = row; return ( ); }; const Row = ({ index, style }) => { return
{getRow(data[index])}
; }; return (
{title}
{metric}
{data?.length === 0 && } {virtualize && data.length > 0 ? ( {Row} ) : ( data.map(row => getRow(row)) )}
); } const AnimatedRow = ({ label, value = 0, percent, animate, showPercentage = true }) => { const props = useSpring({ width: percent, y: value, from: { width: 0, y: 0 }, config: animate ? config.default : { duration: 0 }, }); return (
{label}
{props.y?.to(formatLongNumber)}
{showPercentage && (
`${n}%`) }} /> {props.width.to(n => `${n?.toFixed?.(0)}%`)}
)}
); }; export default ListTable;