react-gridlist

A virtual-scrolling GridList component based on CSS Grids

Github星跟踪图

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}
          />
        )
      }}
    />
  )
}

主要指标

概览
名称与所有者jamiebuilds/react-gridlist
主编程语言TypeScript
编程语言HTML (语言数: 2)
平台
许可证MIT License
所有者活动
创建于2020-03-30 07:32:08
推送于2021-05-14 21:54:13
最后一次提交2020-11-02 12:17:40
发布数3
最新版本名称v1.1.0 (发布于 2020-11-02 12:17:40)
第一版名称v1.0.0 (发布于 2020-03-30 00:33:19)
用户参与
星数426
关注者数5
派生数8
提交数14
已启用问题?
问题数0
打开的问题数0
拉请求数2
打开的拉请求数0
关闭的拉请求数0
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?