import { ReactElement, forwardRef, useRef } from "react"; import { ViewportComponentAttributes } from "./types"; import { Virtualizer, VirtualizerHandle, VirtualizerProps, } from "./Virtualizer"; /** * Methods of {@link VList}. */ export interface VListHandle extends VirtualizerHandle {} /** * Props of {@link VList}. */ export interface VListProps extends Pick< VirtualizerProps, | "children" | "count" | "overscan" | "itemSize" | "shift" | "horizontal" | "cache" | "ssrCount" | "item" | "onScroll" | "onScrollEnd" | "keepMounted" >, ViewportComponentAttributes { /** * If true, items are aligned to the end of the list when total size of items are smaller than viewport size. It's useful for chat like app. */ reverse?: boolean; } /** * Virtualized list component. See {@link VListProps} and {@link VListHandle}. */ export const VList = forwardRef( ( { children, count, overscan, itemSize, shift, horizontal, keepMounted, reverse, cache, ssrCount, item, onScroll, onScrollEnd, style, ...attrs }, ref ): ReactElement => { const scrollRef = useRef(null); const shouldReverse = reverse && !horizontal; let element = ( {children} ); if (shouldReverse) { element = (
{element}
); } return (
{element}
); } );