Coder Social home page Coder Social logo

greatgumz / react-virtualized-cssgrid Goto Github PK

View Code? Open in Web Editor NEW
3.0 0.0 0.0 8.04 MB

React Virtualized CSS Grid Component

Home Page: https://www.npmjs.com/package/react-virtualized-cssgrid

License: MIT License

JavaScript 100.00%
react css-grid javascript virtualization react-virtualized

react-virtualized-cssgrid's Introduction

React Virtualized CSS Grid

React Virtualized CSS Grid is a React component for efficiently rendering a large, scrollable list of items while utilizing CSS Grid. Inspired by react-virtualized to render a virtualized grid of an arbitrary number of rows and columns based on the provided row and container heights to calculate and generate virtualized list items.

Demo

TBD

Installation

npm i react-virtualized-cssgrid

Usage

Functional Stateless Component

function MyList({ items }) {
  return (
    <VirtualizedCSSGrid containerWidth={1080} rowHeight={240} columnWidth={360} columns={3} listLength={items.length}>
      {items.map(el => (
        <img key={el} src={`https://hiring.verkada.com/thumbs/${el}.jpg`} style={{ width: 360 }} />
      ))}
    </VirtualizedCSSGrid>
  );
}

Functional Stateless Component

class List extends Component {
  render() {
    return (
      <VirtualizedCSSGrid containerWidth={1080} rowHeight={240} columnWidth={360} columns={3} listLength={items.length}>
        {items.map(el => (
          <img key={el} src={`https://hiring.verkada.com/thumbs/${el}.jpg`} style={{ width: 360 }} />
        ))}
      </VirtualizedCSSGrid>
    );
  }
}

Props

children

children is required and must be provided as an array within the <VirtualizedCSSGrid /> component.

<VirtualizedCSSGrid containerWidth={1080} rowHeight={240} columnWidth={360} columns={3} listLength={items.length}>
  {items.map(el => (
    <img key={el} src={`https://hiring.verkada.com/thumbs/${el}.jpg`} style={{ width: 360 }} />
  ))}
</VirtualizedCSSGrid>

className

If className is provided, it will be attached to the outermost Grid div.

function MyList({ items }) {
  return <VirtualizedItemGrid className="my-grid-class" containerWidth={1080} rowHeight={240} columnWidth={360} columns={3} listLength={items.length} />;
}

containerWidth

className is required and must be a number or a function which returns a number.

It represents the max width of the outermost grid container div.

function getContainerWidth({ containerWidth }) {
  return containerWidth;
}

function MyList() {
  return <VirtualizedCSSGrid containerWidth={getContainerWidth} rowHeight={240} columnWidth={360} columns={3} listLength={items.length} />;
}

rowHeight

rowHeight is required and must be a number or a function which returns a number.

It represents the row height of each grid row, which will also represent the height a single grid element.

function getRowHeight({ rowHeight }) {
  return rowHeight;
}

function MyList({ items }) {
  return <VirtualizedCSSGrid containerWidth={1080} rowHeight={getRowHeight} columnWidth={360} columns={3} listLength={items.length} />;
}

columnWidth

columnWidth is required and must be a number or a function which returns a number.

It represents the column width of each grid column, which will also represent the width a single grid element.

function getColumnWidth({ columnWidth }) {
  return columnWidth;
}

function MyList({ items }) {
  return <VirtualizedCSSGrid containerWidth={1080} rowHeight={240} columnWidth={getColumnWidth} columns={3} listLength={items.length} />;
}

columns

columns is required and must be a number or a function which returns a number.

It represents the number of columns provided in each row container.

function getColumns({ columns }) {
  return columns;
}

function MyList({ items }) {
  return <VirtualizedCSSGrid containerWidth={1080} rowHeight={240} columnWidth={360} columns={getColumns} listLength={items.length} />;
}

listLength

listLength is required and must be a number or a function which returns a number.

It represents the total number of elements provided.

function getListLength({ listLength }) {
  return listLength;
}

function MyList({ items }) {
  return <VirtualizedCSSGrid containerWidth={1080} rowHeight={240} columnWidth={360} columns={3} listLength={getListLength} />;
}

react-virtualized-cssgrid's People

Contributors

greatgumz avatar

Stargazers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.