react-virtualized#WindowScroller JavaScript Examples

The following examples show how to use react-virtualized#WindowScroller. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: list.js    From Nextjs-ja-translation-docs with MIT License 5 votes vote down vote up
render() {
    const { width } = this.state;
    const isTablet = width < 960;
    const isMobile = width < 640;

    return (
      <Container wide gray center>
        <div className="container">
          <style jsx>{`
            .container {
              margin: 1rem 0 6rem;
            }
            .spacer {
              margin-top: 2rem;
            }
            .icon-label {
              margin-right: 0.625rem;
            }
            .flex-center {
              display: flex;
              justify-content: center;
              align-items: center;
            }
          `}</style>
          <WindowScroller serverHeight={800}>
            {({ height, isScrolling, onChildScroll, scrollTop }) => (
              <List
                autoHeight
                height={height}
                isScrolling={isScrolling}
                onScroll={onChildScroll}
                scrollTop={scrollTop}
                width={width}
                rowCount={Math.ceil(dataSource.length / (isMobile ? 1 : isTablet ? 2 : 3))}
                estimatedRowSize={500}
                rowHeight={args => getRowHeight(args, isMobile ? 1 : isTablet ? 2 : 3) * ROW_HEIGHT}
                rowRenderer={isMobile ? MobileRow : isTablet ? TabletRow : Row}
                overscanRowCount={5}
                overscanIndicesGetter={args => this.overscanIndicesGetter(args, isTablet)}
                style={{
                  willChange: '',
                  margin: 'auto'
                }}
                ref={list => {
                  const columnCount = isMobile ? 1 : isTablet ? 2 : 3;
                  if (columnCount !== this.lastColumnCount) {
                    // reset row height for responsive width
                    this.lastColumnCount = columnCount;
                    list.recomputeRowHeights();
                  }
                }}
              />
            )}
          </WindowScroller>
          <div className="spacer" />
          <Button onClick={() => scrollTo(0)}>
            <div className="flex-center">
              <span className="icon-label">Back to Top</span>
              <ArrowUpIcon color="#0070f3" />
            </div>
          </Button>
          <div className="spacer" />
          <Button href={links.submitShowcase} invert>
            <span className="icon-label">Share Your Website</span>
            <HeartIcon color="white" />
          </Button>
        </div>
      </Container>
    );
  }
Example #2
Source File: channels.js    From iptv-player with MIT License 5 votes vote down vote up
Channels = ({className, searchTerm}) => {
  const [channels, setChannels] = React.useState([]);

  React.useEffect(() => {
    const fetchChannels = async () => {
      const channelsData = await getChannels();
      setChannels(channelsData);
    }
    fetchChannels();
  }, []);

  const searchedChannels = searchTerm ? channels.filter(channel => (
    channel.name.toLowerCase().includes(searchTerm.toLowerCase())
    )) : channels;

  const Cell = ({ columnIndex, key, rowIndex, style }) => {
    const channelIndex = (rowIndex * 6) + columnIndex; 
    if (!searchedChannels[channelIndex]) return; // exit if the channel on that index doesn't exist
    return (
    <li className="list-none" key={key} style={style}>
      <div className="p-3 h-full w-full">
      <ChannelCard channel={searchedChannels[channelIndex]} />
      </div>
    </li>
  )};

  // To choose a good number for height & width, go to https://nerdcave.com/tailwind-cheat-sheet and select a size as per Tailwind standards
  const columnWidth = 192; // This is the cell width. Card size will be smaller due to padding
  const rowHeight = 224; // This is the cell height. Card size will be smaller due to padding
  return (
    <div className={`${className} min-h-screen container mx-auto`}>
      <WindowScroller>
        {({ height, isScrolling, onChildScroll, scrollTop }) => (
          <AutoSizer disableHeight>
            {
              ({width}) => {
                const columnCount = Math.floor(width/columnWidth);
                return (
                  <Grid
                    autoHeight
                    cellRenderer={Cell}
                    columnCount={columnCount}
                    columnWidth={columnWidth}
                    height={height}
                    isScrolling={isScrolling}
                    onScroll={onChildScroll}
                    scrollTop={scrollTop}
                    rowCount={Math.ceil(searchedChannels.length/columnCount)}
                    rowHeight={rowHeight}
                    width={width}
                    className = "flex justify-center"
                  />
                )
              }
            }
          </AutoSizer>
        )}
      </WindowScroller>
    </div>
  );
}