Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-bounds

casesandberg1.8kMIT0.3.1

Element Queries in React

react, react-tool, element query, media query, modular components

readme

React Bounds Element Queries in React

  • Like Media Queries - Set min and max values like breakpoints.

  • Use the Bounds in JS - Active bounds are passed down as props.

  • Use the Bounds in CSS - Use the bound names to style the component with CSS.

Installation & Usage

npm install react-bounds --save

Wrap a Component

Require react-bounds into a component. Wrap the export with bounds.wrap and react-bounds will start tracking the width and height of the component.

var React = require('react');
var bounds = require('react-bounds');

var SomeComponent = React.createClass({
  render(){
    return <div>Some Component</div>
  }
});

module.exports = bounds.wrap(SomeComponent);

Define Bounds

Create a bounds method that returns an object with all of the bound information for that component:

var React = require('react');
var bounds = require('react-bounds');

var SomeComponent = React.createClass({

  bounds() {
    return {
      'bound-name': {
        minWidth: 0,
        maxWidth: 500,
      },
    };
  }

  render(){
    return <div>{ this.props.activeBounds }</div>
  }
});

module.exports = bounds.wrap(SomeComponent);

Use with inline styles via ReactCSS

changelog

Changelog

0.3.1

  • Fix Max Height on calculateHeight #10