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

react-bs4grid

v1.0.1

Published

React Boostrap 4 Grid Component

Downloads

27

Readme

react-bs4grid

A Bootstrap 4 implementation for React.

https://getbootstrap.com/docs/4.0/layout/grid/

Installation

npm install react-bs4grid

or

yarn add react-bs4grid

Importing

import { Container, Row, Col } from "react-bs4grid";

Examples

Simple 12 column across

 <Container>
    <Row>
        <Col>
            One Column
        </Col>
    </Row>
</Container>

Columns without props are spanned equally.

<Container>
    <Row>
        <Col>One</Col>
        <Col>Two</Col>
    </Row>
</Container>

Note: By default, on mobile resolutions, columns become stacked. You can override this behaviour by adding the responsive={false} prop to <Row>. ie <Row responsive={false}>.

Non equal columns

<Container>
    <Row>
        <Col w={6} md={{ size: 4 }}>
            .col-6 .col-md-4
        </Col>
        <Col w={6} md={{ size: 8 }}>
            .col-6 .col-md-8
        </Col>
    </Row>
</Container>

Bootstrap 4 grid is 'mobile-first'. So, responsive classes like *xs are replaced with the col-{width} class. In my experience, you're mostly stacking your columns on mobile anyway, so apply the w prop only when you want adjacent columns in your mobile view. (note: The w prop is an alias for width, they're interchangable.) w="auto" will work as well.

Responsive widths are sm, md, lg, xl. See the BS4 grid docs for more info.

Fluid layout

Use the fluid prop on your <Container>.

<Container fluid>
    <Row>
        <Col md={{ size: 4 }}>Larry!</Col>
        <Col md={{ size: 4 }}>Curly!</Col>
        <Col md={{ size: 4 }}>Moe!</Col>
    </Row>
</Container>

Removing the guttering

Use the noGutters prop on <Row> to remove the padding from each Col.

<Container debug>
    <Row noGutters>
        <Col md={{ size: 4 }}>Larry</Col>
        <Col md={{ size: 4 }}>Curly</Col>
        <Col md={{ size: 4 }}>Moe</Col>
    </Row>
</Container>

Horizonally aligning cols

Use the justifyContent prop in <Row>. Supported values are start|end|center|between|around.

<Container>
    <Row justifyContent="center">
        <Col sm={{ size: 5 }}>
            5 columns wide and centered.
        </Col>
    </Row>
</Container>

Vertically aligning Rows and Col Content.

Use the alignItems prop in <Row>. Row needs to be styled with a height before it will take effect.

<Container>
    <Row alignItems="center" justifyContent="center" style={{height: "100vh"}}>
        <Col sm={{ size: 5 }}>Hello World</Col>
    </Row>
</Container>

Same concept will work for <Col>. (as well as alignSelf)

<Container>
    <Row>
        <Col style={{height: 200}}>
        	Hello
        </Col>
        <Col alignItems="center">
            center of Col
        </Col>
        <Col alignItems="end">
            bottom of Col
        </Col>
    </Row>
</Container>

Debugging

Adding the debug prop within container will add borders to Cols.

Props

<Container>

| prop | type | description |------|------|------------| | fluid |bool| turns off the container width restriction. 100% of the width of the container. Default false | | noGutters |bool | Turns off all guttering for all Rows. Default false | | debug |bool | Will draw borders around your Cols, to help you figure out what's going on. | | styles |obj | applies react css styles | | className |string | appends custom classes |

<Row>

| prop | type | description |------|------|------------| | noGutters |bool| Turns off guttering (default false) | | justifyContent | string | Determines how child <Col>s are positioned horizontally. Options are start, center, end, around, between | | alignItems |string| Determines how child <Col>s are positioned vertically. Options are start, center, end | | responsive |bool | Disable default responsive behaviour | | styles |obj | applies react css styles | | className |string| appends custom classes |

<Col>

| prop | type | description |------|------|------------| | noGutter |bool| Turns off guttering for that Col. Default false. | | alignItems |string| Determines how content is vertically aligned. Options are start, center, end | | push |string| Align col. Effective when width="auto" | | w (or width)| any | Generic width. Options are 1-12 or auto | | sm / md / lg / xl | any | Width based on breakpoint. Provide an object with valid keys size, order, offset | | size | string / number | Property of width-based breakpoint. Sets width at specified breakpoint. Options are 1-12 | | order | string / number | Property of width-based breakpoint. Sets order at specified breakpoint. Options are 1-12 | | styles |obj | applies react css styles | | className |string | appends custom classes |

Some use-cases

Navigation Bar (non-responsive)

  • The logo container is only as wide as the logo.
  • Nav section stretches as much as it needs to.
  • Sign up section pushed to the far right.
<Container fluid style={{background:"#eee"}}>
    <Row>
        <Col>
            <Row alignItems="center" responsive={false}>
                <Col w="auto">
                    <h1>Logo</h1>
                </Col>
                <Col w="auto">
                    Page 1 : Page 2 : Page 3 : Page 4
                </Col>
                <Col w="auto" push="left">
                    Sign Up
                </Col>
            </Row>
        </Col>
    </Row>
</Container>

Content horizontally and vertically centred

  • Row requires an explicit height for vertical alignment.
<Container>
    <Row alignItems="center" justifyContent="center" style={{height: "100vh"}} >
        <Col w={5}>
            <div>
                In the middle
            </div>
        </Col>
    </Row>
</Container>