npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rc-pinterest-grid

v0.0.4

Published

react component pinterest layout

Downloads

85

Readme

rc-pinterest-grid(react component)

English | 简体中文

This is a react component which provides a pinterest layout grid, and :

  1. no need to provide height for each block.
  2. the height of each block can be changed by user (etc reszie) while the grid can be relayouted automatically.
  3. support automatically responsive.
  4. support self-defined responsive.

demo1

install

npm install --S rc-pinterest-grid

Usage

import PinterestGrid from 'rc-pinterest-grid';
<PinterestGrid
  columns={4}               // how many columns in one row
  columnWidth={200}         // width of each block
  gutterWidth={10}          // horizontal gutter between each block
  gutterHeight={10}         // vertical gutter between each block
>
  <div key="A">A</div>
  <div key="B">B</div>
  <div key="C">C</div>
  {
    // ... more blocks here
  }
</PinterestGrid>

PinterestGrid Props

| Prop Name | Description | Type | Required | Default | | :----- | :------- | :------- | :----- | :----- | | columns | it specifies how may columns in one row | number | true | 4 | | columnWidth | it specifies the width of every block | number | true | 200 | | gutterWidth | horizontal gutter between each block | number | false | 10 | | gutterHeight | vertical gutter between each block | number | false | 10 | | responsive | to be responsive or not responding with the screen width | boolean | ResponsiveConfigObject | undefined | false | false |

ResponsiveConfigObject

export interface ResponsiveConfigObject {
  minPadding?: number;
  maxWidth?: number;
  customBreakPoints?: BreakPoint[];
}

Note:

  1. if responsive is false or not provided(undefined), it will NOT be responsive.
  2. if responsive is true, it will calculate responsive behavior with default min-padding and max-width.
  3. if responsive.minPadding is provided, it will use responsive.minPadding to calculate responsive behavior.
  4. if responsive.maxWidth is provided, it will use responsive.maxWidth to calculate responsive behavior.
  5. if responsive.customBreakPoints is provided, it will follow the self-defined breakPoints to layout responsively to screen width.

BreakPoint ( for responsive.customBreakPoints )

| Prop Name | Description | Type | Required | Default | | :------- | :------- | :------- | :----- | :----- | | minScreenWidth | min screen width for this break point,it should be 0 for first break point | number | true | None | | maxScreenWidth | max screen width for this break point, it should be Infinity for last break point | number | true | None | | columnWidth | under this break point,the width for every block | number | true | None | | columns | under this break point, how many columns should be placed in one row | number | true | None |

Use Case 1: simple usage

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import PinterestGrid from 'rc-pinterest-grid';

const list = [1,2,3,4,5,6,7,8,9,10,11,12];

const Demo = () => (
  <PinterestGrid
    columns={4}             
    columnWidth={200}     
    gutterWidth={10}     
    gutterHeight={10}   
  >
    { 
      list.map((item, index) => (
        <div key={index} className={...} style={...}>
          ...
        </div>
      ))
    }
  </PinterestGrid>
)

ReactDOM.render(<Demo />, root);

Use Case 2:automatic responsive

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import PinterestGrid from 'rc-pinterest-grid';

const list = [1,2,3,4,5,6,7,8,9,10,11,12];

const Demo = () => (
  <PinterestGrid
    columns={4}             
    columnWidth={200}     
    gutterWidth={10}     
    gutterHeight={10}   
    responsive={true}    
  >
    { 
      list.map((item, index) => (
        <div key={index} className={...} style={...}>
          ...
        </div>
      ))
    }
  </PinterestGrid>
)

ReactDOM.render(<Demo />, root);

demo2 demo3

Use Case 3: self-defined responsive

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import PinterestGrid from 'rc-pinterest-grid';

const list = [1,2,3,4,5,6,7,8,9,10,11,12];

// self-defined break points
const breakPoints = [
  {
    minScreenWidth: 0,
    maxScreenWidth: 300,
    columns: 1,
    columnWidth: 200,
  },
  {
    minScreenWidth: 300,
    maxScreenWidth: 900,
    columns: 2,
    columnWidth: 300,
  },
  {
    minScreenWidth: 900,
    maxScreenWidth: Infinity,
    columns: 3,
    columnWidth: 600,
  },
]

const Demo = () => (
  <PinterestGrid
    columns={4}            
    columnWidth={200}      
    gutterWidth={10}       
    gutterHeight={10}      
    responsive={{customBreakPoints: breakPoints}}    
  >
    { 
      list.map((item, index) => (
        <div key={index} className={...} style={...}>
          ...
        </div>
      ))
    }
  </PinterestGrid>
)

ReactDOM.render(<Demo />, root);

License

MIT