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'; import styles from './ListTable.module.css'; import { ReactNode } from 'react'; const ITEM_SIZE = 30; export interface ListTableProps { data?: any[]; title?: string; metric?: string; className?: string; renderLabel?: (row: any, index: number) => ReactNode; renderChange?: (row: any, index: number) => ReactNode; animate?: boolean; virtualize?: boolean; showPercentage?: boolean; itemCount?: number; } export function ListTable({ data = [], title, metric, className, renderLabel, renderChange, animate = true, virtualize = false, showPercentage = true, itemCount = 10, }: ListTableProps) { const { formatMessage, labels } = useMessages(); const getRow = (row: { x: any; y: any; z: any }, index: number) => { const { x: label, y: value, z: percent } = row; return ( ); }; const Row = ({ index, style }) => { return
{getRow(data[index], index)}
; }; return (
{title}
{metric}
{data?.length === 0 && } {virtualize && data.length > 0 ? ( {Row} ) : ( data.map(getRow) )}
); } const AnimatedRow = ({ label, value = 0, percent, change, animate, showPercentage = true }) => { const props = useSpring({ width: percent, y: value, from: { width: 0, y: 0 }, config: animate ? config.default : { duration: 0 }, }); return (
{label}
{change} {props.y?.to(formatLongNumber)}
{showPercentage && (
`${n}%`) }} /> {props.width.to(n => `${n?.toFixed?.(0)}%`)}
)}
); }; export default ListTable;