UNPKG

@selfcommunity/react-ui

Version:

React UI Components to integrate a Community created with SelfCommunity Platform.

83 lines (82 loc) 2.88 kB
import React from 'react'; import { CacheStrategies } from '@selfcommunity/utils'; import { VirtualScrollerCommonOptions } from 'virtual-scroller'; /** * VirtualizedScrollerCommonProps Interface */ export interface VirtualizedScrollerCommonProps extends VirtualScrollerCommonOptions<HTMLElement, any>, React.HTMLAttributes<HTMLElement> { scrollableContainer?: any; getScrollableContainer?: () => Element; } /** * VirtualizedScrollerProps Interface */ export interface VirtualizedScrollerProps extends VirtualizedScrollerCommonProps { /** * items to render @default [] */ items: any[]; /** * Component used to render single feed item retrieved by the endpoint * @default null */ ItemComponent: React.ElementType; /** * Uses it as a source for a React key for rendering an item * If getItemId() is not supplied, then item keys are autogenerated from a random-generated * prefix (that changes every time items are updated) and an item index */ getItemId?: (item: any) => any; /** * The initial state for VirtualScroller */ initialScrollerState?: object; /** * Callback when virtual scroller state change * @default null */ onScrollerStateChange?: (s: any) => void; /** * Callback when virtual scroller is mount * @default null */ onScrollerMount?: () => void; /** * Callback when virtual scroller change position of the scroll * @default null */ onScrollerPositionChange?: (p: any) => void; /** * Callback when virtual scroller state is saved * @default null */ onScrollerSaveState?: (s: any) => void; /** * Cache Strategy * @default CacheStrategies.CACHE_FIRST */ cacheStrategy?: CacheStrategies; /** * Cache state key * @default 'virtual_scroller_st' */ cacheScrollStateKey?: string; /** * Cache position key * @default 'virtual_scroller_sp' */ cacheScrollerPositionKey?: string; } /** * VirtualizedScroller * A component for efficiently rendering large lists of variable height items. * VirtualScroller works by measuring each list item's height as it's being rendered, and then, as the user scrolls, * it hides the items that are no longer visible, and shows the now-visible items as they're scrolled to. * The hidden items at the top are compensated by setting padding-top on the list element, and the hidden items * at the bottom are compensated by setting padding-bottom on the list element. * The component listens to scroll / resize events and re-renders the currently visible items as the user * scrolls (or if the browser window is resized). * Set window['VirtualScrollerDebug'] = true; to output debug messages to console. */ export default function VirtualizedScroller(props: any): JSX.Element;