react-gridlist

A virtual-scrolling GridList component based on CSS Grids

Github stars Tracking Chart

React GridList

A virtual-scrolling GridList component based on CSS Grids.

  • Render anything (not just images) of a known width/height inside.
  • Variable height items in the same row.
  • Highly performant virtual scrolling (aka windowing) for buttery smoothness.
  • Customizable & Responsive.
  • Very small bundle size

Install

npm install --save react-gridlist

Example

import React from "react"
import GridList from "react-gridlist"

function getGridGap(elementWidth: number, windowHeight: number) {
  if (elementWidth > 720 && windowHeight > 480) {
    return 10
  } else {
    return 5
  }
}

function getColumnCount(elementWidth: number) {
  return Math.floor(elementWidth / 300)
}

function getWindowMargin(windowHeight: number) {
  return Math.round(windowHeight * 1.5)
}

function getItemData(image: Image, columnWidth: number) {
  let imageRatio = image.height / image.width
  let adjustedHeight = Math.round(columnWidth * imageRatio)

  return {
    key: image.url,
    height: adjustedHeight,
  }
}

function Example(props) {
  return (
    <GridList
      items={props.images}
      getGridGap={getGridGap}
      getColumnCount={getColumnCount}
      getWindowMargin={getWindowMargin}
      getItemData={getItemData}
      renderItem={(image) => {
        return (
          <img
            src={image.url}
            width={image.width}
            height={image.height}
            className={styles.image}
          />
        )
      }}
    />
  )
}

Main metrics

Overview
Name With Ownerjamiebuilds/react-gridlist
Primary LanguageTypeScript
Program languageHTML (Language Count: 2)
Platform
License:MIT License
所有者活动
Created At2020-03-30 07:32:08
Pushed At2021-05-14 21:54:13
Last Commit At2020-11-02 12:17:40
Release Count3
Last Release Namev1.1.0 (Posted on 2020-11-02 12:17:40)
First Release Namev1.0.0 (Posted on 2020-03-30 00:33:19)
用户参与
Stargazers Count426
Watchers Count5
Fork Count8
Commits Count14
Has Issues Enabled
Issues Count0
Issue Open Count0
Pull Requests Count2
Pull Requests Open Count0
Pull Requests Close Count0
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private