2.1.2 • Published 6 years ago

react-flexbox-grid v2.1.2

Weekly downloads
36,091
License
MIT
Repository
github
Last release
6 years ago

react-flexbox-grid

npm version Build Status NPM Status

react-flexbox-grid is a set of React components that implement flexboxgrid.css. It even has an optional support for CSS Modules with some extra configuration.

http://roylee0704.github.io/react-flexbox-grid/

Setup

Installation

react-flexbox-grid can be installed as an npm package:

npm install --save react-flexbox-grid

Minimal configuration

The recommended way to use react-flexbox-grid is with a tool like webpack or Meteor, make sure you set it up to support requiring CSS files. For example, the minimum required loader configuration for webpack would look like this:

{
  test: /\.css$/,
  loader: 'style-loader!css-loader',
  include: /flexboxgrid/
}

react-flexbox-grid imports the styles from flexboxgrid, that's why we're configuring the loader for it.

CSS Modules

If you want to use CSS Modules (this is mandatory for versions earlier than v1), webpack's css-loader supports this by passing modules param in the loader configuration.

First, install style-loader and css-loader as development dependencies:

npm install --save-dev style-loader css-loader

Next, add a loader for flexboxgrid with CSS Modules enabled:

{
  test: /\.css$/,
  loader: 'style-loader!css-loader?modules',
  include: /flexboxgrid/
}

Make sure you don't have another CSS loader which also affects flexboxgrid. In case you do, exclude flexboxgrid, for example:

{
  test: /\.css$/,
  loader: 'style-loader!css-loader!postcss-loader',
  include: path.join(__dirname, 'node_modules'), // oops, this also includes flexboxgrid
  exclude: /flexboxgrid/ // so we have to exclude it
}

Otherwise you would end up with an obscure error because webpack stacks loaders together, it doesn't override them.

Isomorphic support

Try: this comment.

If this doesn't work for you, use the build located in the dist directory. This build removes all .css imports and extracts the relevant css into react-flexbox-grid/dist/react-flexbox-grid.css.

Not using a bundler?

Use the pre-bundled build located in the dist directory. It contains a single umd js distributable and built css file.

Usage

Now you can import and use the components:

import React from 'react';
import { Grid, Row, Col } from 'react-flexbox-grid';

class App extends React.Component {
  render() {
    return (
      <Grid fluid>
        <Row>
          <Col xs={6} md={3}>
            Hello, world!
          </Col>
        </Row>
      </Grid>
    );
  }
}

Gotcha

For the time being always use fluid for <Grid> to prevent horizontal overflow issues.

Example

Looking for a complete example? Head over to react-flexbox-grid-example.

Advanced composition

We also export functions for generating Row and Column class names for use in other components.

For example, suppose you're using a third party component that accepts className and you would like it to be rendered as Col. You could do so by extracting the column sizing props that MyComponent uses and then pass the generated className on to SomeComponent

import React from 'react';
import { Row, Col, getRowProps, getColumnProps } from 'react-flexbox-grid';
// a component that accepts a className
import SomeComponent from 'some-package';

export default function MyComponent(props) {
  const colProps = getColumnProps(props);
  const rowProps = getRowProps(props);

  return (
    <form className={rowProps.className}>
      <SomeComponent classname={colProps.className} />
      <input value={props.value} onChange={props.onChange} />
    </form>
  );
}

MyComponent.propTypes = Object.assign({
  onChange: React.PropTypes.func.isRequired,
  value: React.PropTypes.string.isRequired,
}, Col.propTypes, Row.propTypes);  // Re-use existing Row and Col propType validations

// Can now be rendered as: <MyComponent end="sm" sm={8} value="my input value" onChange={...} />

Contributors

Roy LeeHelder SantanaMatija Marohnić
Roy LeeHelder SantanaMatija Marohnić

License

MIT

hero-style@geodashboard/gd-core__old@geodashboard/gd-gltg__oldsc-modulehighstreet-studiomint-course-component-libmarin-stageplayer@workrails/wr-catalog-baseform-generator-maxclub-design-systemreact-approveme-uiskill-f3@infinitebrahmanuniverse/nolb-react-fl@everything-registry/sub-chunk-2555liba_laboratoriahippo-fwhixme-uilanes-frameworklalauiledger-analyticsnobel-react-aztecinvois-headermammoth-uilyra-ui-kitmaterial-ui-react-express-mongodb@radargovernamental/orbit-styledynamic-material-uigm-react-compgrid-breakpointoddsmarket-site@reactivers/generic-uinutec-componentsnutec-ui@zalastax/nolb-react-flReact-Redux-Docker-Ngnix-Seedplanning-core-v@vytalos/ui-shared-components@alaneicker/atomik-ui@sphinxdoc/gatsby-theme@sovtech/everblue-uiotd-explorer@rooft/widgets@ambassadorai/payment-webviewreact-pickatablereact-pdf-simulatoras-app-cloner@app-masters/react-creatureastrazeneca-vdcreact-settings-panelreact-block-full-uiabt.api.webslyesmedia-react-crud@cybercongress/gravity@cybercongress/uichippiesshiftgrillacrudsm-react-crudsymphony-bdk-app-templatesymphony-bdk-mock-clientdash-flexbox-gridrokket-partstemplate-uidiva-reactcanner-document-websitebdmsui@bestdoctor/keblakit-react-material-componentsslackercode-ui-reactss-react-components@cashremit/login@element-softworks/daintree@hbsis.uikit.ambev/react@hbsis.uikit/react@homehero/hero-style@ivancmonaco/react-block-editorugrowth-admin-uiui-kit-ck-consultantviewer3dtre.crm.web@k-int/address-plugin-british-isles@k-int/address-plugin-generic@k-int/address-plugin-north-america@kaytwo/network-viewer@joao.jesus.ambevtech/uikit-ppmswb-ui-kitwebmashupwms_uikit_reactyui-mdtrinit2vav1.1@hixme-ui/modal@hixme/modal@geostreams/core__old@mree/mre-react-widget@mammut-fe/bdms-ui@prague-digi/react-shared-components
2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.10.2

8 years ago

0.10.1

8 years ago

0.10.0

8 years ago

0.9.6

8 years ago

0.9.5

8 years ago

0.9.4

8 years ago

0.9.2

8 years ago

0.9.1

8 years ago

0.8.3

8 years ago

0.8.2

8 years ago

0.8.1

8 years ago

0.8.0

8 years ago

0.7.5

8 years ago

0.7.4

8 years ago

0.7.3

8 years ago

0.7.2

8 years ago

0.7.1

8 years ago

0.7.0

8 years ago

0.6.11

8 years ago

0.6.10

8 years ago

0.6.9

8 years ago

0.6.8

8 years ago

0.6.7

8 years ago

0.6.6

8 years ago

0.6.4

8 years ago

0.4.0

8 years ago

0.3.0

8 years ago

0.1.0

8 years ago