1.1.0 • Published 5 years ago

@trendmicro/react-grid-system v1.1.0

Weekly downloads
391
License
MIT
Repository
github
Last release
5 years ago

react-grid-system build status Coverage Status

NPM

React Grid System component

Demo: https://trendmicro-frontend.github.io/react-grid-system

Installation

  1. Install the latest version of react and react-grid-system:

    npm install --save react @trendmicro/react-grid-system
  2. At this point you can import @trendmicro/react-grid-system and its styles in your application as follows:

    import {
        Provider as GridSystemProvider,
        Container, Row, Col,
        Visible, Hidden
    } from '@trendmicro/react-grid-system';
    
    // Be sure to include styles at some point, probably during your bootstraping
    import '@trendmicro/react-grid-system/dist/react-grid-system.css';

Recommended Setup

Create a common components directory including the GridSystem component, as shown below:

components/
  GridSystem/
    index.js

components/GridSystem/index.js

import '@trendmicro/react-grid-system/dist/react-grid-system.css';
export {
      Provider,
      Container, Row, Col,
      Visible, Hidden
} from '@trendmicro/react-grid-system';

Then, import components like below:

import {
      Provider as GridSystemProvider,
      Container, Row, Col,
      Visible, Hidden
} from './components/GridSystem';

Usage

<Container fluid gutterWidth={0}>
    <Row>
        <Col xs md={8}>col-md-8</Col>
        <Col width={6} md={4}>col-6 col-md-4</Col>
    </Row>
    <Row>
        <Col width={6} md={4}>col-6 col-md-4</Col>
        <Col width={6} md={4}>col-6 col-md-4</Col>
        <Col width={6} md={4}>col-6 col-md-4</Col>
    </Row>
    <Row>
        <Col width={6}>col-6</Col>
        <Col width={6}>col-6</Col>
    </Row>
</Container>

Provider

You can wrap <Container />, <Row />, and <Col /> in <Provider /> to pass grid system config through context.

<Provider
    breakpoints={[576, 768, 992, 1200, 1600]}
    containerWidths={[540, 720, 960, 1140, 1440]}
    columns={12}
    gutterWidth={0}
    layout="flexbox"
>
    <Container fluid>
        <Row>
            <Col>col</Col>
            <Col>col</Col>
            <Col>col</Col>
        </Row>
    </Container>
    <Container
        fluid
        columns={24}
        gutterWidth={30}
        layout="floats"
    >
        <Row>
            <Col>col</Col>
            <Col>col</Col>
        </Row>
    </Container>
</Provider>

Responsive Utilities

Use responsive utilities for showing and hiding content based on current viewport.

Hidden

Make an element hidden when the viewport is at the given breakpoint.

<Hidden xs sm>
    Hidden on extra small and small
</Hidden>
<Hidden md lg>
    Hidden on medium and large
</Hidden>

Visible

Make an element visible when the viewport is at the given breakpoint.

<Visible xs>
    Visible on extra small
</Visible>
<Visible sm>
    Visible on small
</Visible>
<Visible md>
    Visible on medium
</Visible>
<Visible lg>
    Visible on large
</Visible>
<Visible xl>
    Visible on extra large
</Visible>
<Visible xxl>
    Visible on double extra large
</Visible>

ScreenClass

Render content based on the screen class.

<ScreenClass>
    {screenClass => <div>{screenClass}</div>}
</ScreenClass>
<ScreenClass
    render={screenClass => <div>{screenClass}</div> }
/>

API

Properties

Provider

NameTypeDefaultDescription
breakpointsNumber[]576, 768, 992, 1200, 0The breakpoints (minimum width) of devices in screen class sm, md, lg, xl, and xxl.
containerWidthsNumber[]540, 720, 960, 1140, 0The container widths in pixels of devices in screen class sm, md, lg, xl, and xxl.
columnsNumber12The number of columns.
gutterWidthNumber0The horizontal padding (called gutter) between two columns. A gutter width of 30 means 15px on each side of a column.
layoutOne of:'flexbox''floats''flexbox'The grid system layout.

Container

NameTypeDefaultDescription
fluidBooleanfalseTrue makes the container full-width, false fixed-width.
xsBooleanfalseTrue makes container fluid only in xs, not present means fluid everywhere.
smBooleanfalseTrue makes container fluid only in sm, not present means fluid everywhere.
mdBooleanfalseTrue makes container fluid only in md, not present means fluid everywhere.
lgBooleanfalseTrue makes container fluid only in lg, not present means fluid everywhere.
xlBooleanfalseTrue makes container fluid only in xl, not present means fluid everywhere.
xxlBooleanfalseTrue makes container fluid only in xxl, not present means fluid everywhere.
columnsNumberinheritedThe number of columns.
gutterWidthNumberinheritedThe horizontal padding (called gutter) between two columns. A gutter width of 30 means 15px on each side of a column.
layoutOne of:'flexbox''floats'inheritedThe grid system layout.

Row

NameTypeDefaultDescription

Col

NameTypeDefaultDescription
widthNumber or 'auto'The width of the column for all screen classes.Note: 'auto' is only supported with the flexbox layout.
xsNumber, Boolean or 'auto'The width of the column for screen class xs.Note: 'auto' and true are only supported with the flexbox layout.
smNumber, Boolean or 'auto'The width of the column for screen class sm.Note: 'auto' and true are only supported with the flexbox layout.
mdNumber, Boolean or 'auto'The width of the column for screen class md.Note: 'auto' and true are only supported with the flexbox layout.
lgNumber, Boolean or 'auto'The width of the column for screen class lg.Note: 'auto' and true are only supported with the flexbox layout.
xlNumber, Boolean or 'auto'The width of the column for screen class xl.Note: 'auto' and true are only supported with the flexbox layout.
xxlNumber, Boolean or 'auto'The width of the column for screen class xxl.Note: 'auto' and true are only supported with the flexbox layout.
offset{ xs, sm, md, lg, xl, xxl }The offset of this column for all screen classes.
pull{ xs, sm, md, lg, xl, xxl }The amount this column is pulled to the left for all screen classes.
push{ xs, sm, md, lg, xl, xxl }The amount this column is pushed to the right for all screen classes.

Visible

NameTypeDefaultDescription
xsBooleanfalseVisible on extra small devices.
smBooleanfalseVisible on small devices.
mdBooleanfalseVisible on medimum devices.
lgBooleanfalseVisible on large devices.
xlBooleanfalseVisible on extra large devices.
xxlBooleanfalseVisible on double extra large devices.

Hidden

NameTypeDefaultDescription
xsBooleanfalseHidden on extra small devices.
smBooleanfalseHidden on small devices.
mdBooleanfalseHidden on medimum devices.
lgBooleanfalseHidden on large devices.
xlBooleanfalseHidden on extra large devices.
xxlBooleanfalseHidden on double extra large devices.

ScreenClass

NameTypeDefaultDescription
renderFunction(screenClass)The render function that returns a React element.

License

MIT