GithubHelp home page GithubHelp logo

styled-bootstrap-grid's Introduction

styled-bootstrap-grid

npm version

Credits

This module is based on the styled-components module.

This module is highly inspired by the awesome work done on the react-bootstrap module.

This module is also based on the Twitter Bootstrap v4.0.0-alpha.6 layout CSS. The css provided to styled bootstrap grid is not mine.

For more information about how does this grid system works (I mean with classes like containers, row, col, offset, push) , please refer to the official Twitter Bootstrap layout documentation.

Install

npm i -S styled-bootstrap-grid

Prerequisites

Bootstrap is developed mobile first, a strategy in which we optimize code for mobile devices first and then scale up components as necessary using CSS media queries. To ensure proper rendering and touch zooming for all devices, add the responsive viewport meta tag to your <head>. from Bootstrap documentation

<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

You also must inject the bootstrap base CSS in your application root file, like this.

// app.js

import { injectLayoutBaseCSS } from 'styled-bootstrap-grid';

injectLayoutBaseCSS();

You also can inject your own css like this :

const customCSS = `
  body {
    // whatever
  }
`;

injectLayoutBaseCSS(customCSS);

Basicaly, injectLayoutBaseCSS takes a string in param, and append the default bootstrap layout base CSS with this string with it.

the defaut bootstrap layout CSS is :

@-ms-viewport {
  width: device-width;
}

html {
  -webkit-box-sizing: border-box;
          box-sizing: border-box;
  -ms-overflow-style: scrollbar;
}

*,
*::before,
*::after {
  -webkit-box-sizing: inherit;
          box-sizing: inherit;
}

Basics

import React from 'react';
import { Container, Row, Col } from 'styled-bootstrap-grid';

export default (props) =>
  <Whatever>
    <Container>
      <Row>
        <Col xl="1" lg="2" md="3" sm="12">
            Hello Bootstrap Layout
        </Col>
      </Row>
    </Container>
    <Container fluid>
      <Row>
        <Col xl={1} xlOffset={4}>
            Hello Bootstrap Fluid Layout
        </Col>
      </Row>
    </Container>
  </Whatever>;

Advanced

This packages also exposes the media element. It can be used in your styled-components like this :

import styled from 'styled-components';
import { media } from 'styled-bootstrap-grid';

const CustomDiv = styled.div`
  color: black;
  ${media.phone`
    color: blue;
  `}
  ${media.tablet`
    color: red;
  `}
  ${media.desktop`
    color: purple;
  `}
  ${media.giant`
    color: yellow;
  `}
`;

export default CustomDiv;

Using this media object will help you to build media-queries that will fit the same way as Bootstrap do.

name css generated
phone @media (min-width: 576px) { /* */ }
tablet @media (min-width: 768px) { /* */ }
desktop @media (min-width: 992px) { /* */ }
giant @media (min-width: 1200px) { /* */ }

Props definition

Container

props default type description
fluid false boolean Equivalent to container and container-fluid

Plus the ones inherited from styled-components div.

Row

Row element has no props, except the ones inherited from styled-components div.

Col

props default type description
sm 0 number or string Goes from 1 to 12. Equivalent to col-sm-*
smOffset 0 number or string Goes from 1 to 11. Equivalent to offset-sm-*
smPush 0 number or string Goes from 1 to 11. Equivalent to push-sm-*
md 0 number or string Goes from 1 to 12. Equivalent to col-md-*
mdOffset 0 number or string Goes from 1 to 11. Equivalent to offset-md-*
mdPush 0 number or string Goes from 1 to 11. Equivalent to push-md-*
lg 0 number or string Goes from 1 to 12. Equivalent to col-lg-*
lgOffset 0 number or string Goes from 1 to 11. Equivalent to offset-lg-*
lgPush 0 number or string Goes from 1 to 11. Equivalent to push-lg-*
xl 0 number or string Goes from 1 to 12. Equivalent to col-xl-*
xlOffset 0 number or string Goes from 1 to 11. Equivalent to offset-xl-*
xlPush 0 number or string Goes from 1 to 11. Equivalent to push-xl-*

Plus the ones inherited from styled-components div.

Dependencies

todo

Any idea ? Please leave a suggestion.

styled-bootstrap-grid's People

Contributors

dragma avatar kenny26 avatar

Watchers

 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.