1.7.0 • Published 6 years ago

grid-breakpoint v1.7.0

Weekly downloads
88
License
MIT
Repository
github
Last release
6 years ago

grid-breakpoint NPM version Build Status Dependency Status

Automatically add breakpoints to your grid (This project is build on top of flexboxgrid, which is a 12 column grid system).

Installation

$ npm install --save grid-breakpoint

Problem in writing grids

Grid is great! But one big commonly problem in writing grids is when you have a big list of columns, you can't just push all the columns into a row. If the containers have different height, your items will end up displaying unexpected.

So let's turn

<Row>
  <Col span={6}/>
  <Col span={6}/>
  <Col span={6}/>
  <Col span={6}/>
  <Col span={6}/>
  <Col span={6}/>
  <Col span={6}/>
  {....}
</Row>

to automatically

<Row>
  <Col span={6}/>
  <Col span={6}/>
</Row>
<Row>
  <Col span={6}/>
  <Col span={6}/>
</Row>
<Row>
  <Col span={6}/>
  <Col span={6}/>
</Row>
<Row>
  <Col span={6}/>
  <Col span={6}/>
</Row>
<Row>
  <Col span={6}/>
  <Col span={6}/>
</Row>

grid-breakpoint automatically calculate how many columns should in a row and wrapped <Row/> for <Col/>!

Usage

And add to your component as below.

NOTICE: You need to import react-flexbox-grid's css in order to let it work correctly

import React, {Component} from 'react';
import GridBreakPoint from 'grid-breakpoint';

import 'react-flexbox-grid/dist/react-flexbox-grid.css';

class GridExample extends Component {
  render() {
    const list = range(20).map((col, i) => {
      return <div key={i}>{col}</div>;
    });

    // in this example, when the screen width is large(lg)
    // it'll wrap <Col/> as structure below
    // <Row> ---> automaticlly wrapped
    //   <Col/>
    //   <Col/>
    //   <Col/>
    // </Row>

    // in md screen
    // <Row> ---> automaticlly wrapped
    //   <Col/>
    //   <Col/>
    // </Row>

    // in xs screen (xs + xsOffset = 6)
    // <Row> ---> automaticlly wrapped
    //   <Col/>
    //   <Col/>
    // </Row>

    return (
      <GridBreakpoint
        lg={4}
        md={6}
        xs={3}
        xsOffset={3}
        detectContainerWidth={true} // whether detect container width or not, if not will detect window width.
        rowClassName="row-test"
        colClassName="col-test">
        {list}
      </GridBreakpoint>
    );
  }
}

Start example server

npm start

License

MIT © Canner

1.7.0

6 years ago

1.6.2

6 years ago

1.6.1

6 years ago

1.6.0

6 years ago

1.5.0

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

7 years ago

0.4.0

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago