Socket
Socket
Sign inDemoInstall

react-responsive

Package Overview
Dependencies
49
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-responsive

Media queries in react for responsive design


Version published
Weekly downloads
586K
decreased by-4.02%
Maintainers
1
Install size
6.14 MB
Created
Weekly downloads
 

Changelog

Source

v0.0.10 (2015/10/08 22:50 +00:00)

  • 62af1d5 0.0.10 (@contra)
  • #28 support react 0.14 (@0x80)
  • d1dc1e9 support react 0.14 (@0x80)
  • #26 Allow for react 0.14.0-rc1 as peer-dependency (@npasserini)
  • b3e687d Allow for react 0.14.0-rc1 as peer-dependency (@npasserini)

Readme

Source

react-responsive NPM version Downloads Support us Build Status Coveralls Status

Information

Packagereact-responsive
DescriptionMedia queries in react for responsive design
Browser Version>= IE6*

This module is pretty straightforward: You specify a set of requirements, and the children will be rendered if they are met. Also handles changes so if you resize or flip or whatever it will all be cool.

Usage

A mq element functions like any other React component, which means you can nest them and do all the normal jazz.

Using CSS Media Queries

var mq = require('react-responsive');

var A = React.createClass({
  render: function(){
    return (
      <div>
        <div>Device Test!</div>
        <mq query='(min-device-width: 1224px)'>
          <div>You are a desktop or laptop</div>
          <mq query='(min-device-width: 1824px)'>
            <div>You also have a huge screen</div>
          </mq>
          <mq query='(max-width: 1224px)'>
            <div>You are sized like a tablet or mobile phone though</div>
          </mq>
        </mq>
        <mq query='(max-device-width: 1224px)'>
          <div>You are a tablet or mobile phone</div>
        </mq>
        <mq query='(orientation: portrait)'>
          <div>You are portrait</div>
        </mq>
         <mq query='(orientation: landscape)'>
          <div>You are landscape</div>
        </mq>
        <mq query='(min-resolution: 2dppx)'>
          <div>You are retina</div>
        </mq>
      </div>
    );
  }
});

Using Properties

To make things more idiomatic to react, you can use camelcased shorthands to construct media queries.

For a list of all possible shorthands and value types see https://github.com/wearefractal/react-responsive/blob/master/src/mediaQuery.js#L9

Any numbers given as a shorthand will be expanded to px (1234 will become '1234px')

var mq = require('react-responsive');

var A = React.createClass({
  render: function(){
    return (
      <div>
        <div>Device Test!</div>
        <mq minDeviceWidth={1224}>
          <div>You are a desktop or laptop</div>
          <mq minDeviceWidth={1824}>
            <div>You also have a huge screen</div>
          </mq>
          <mq maxWidth={1224}>
            <div>You are sized like a tablet or mobile phone though</div>
          </mq>
        </mq>
        <mq maxDeviceWidth={1224}>
          <div>You are a tablet or mobile phone</div>
        </mq>
        <mq orientation='portrait'>
          <div>You are portrait</div>
        </mq>
         <mq orientation='landscape'>
          <div>You are landscape</div>
        </mq>
        <mq minResolution='2dppx'>
          <div>You are retina</div>
        </mq>
      </div>
    );
  }
});

Browser Support

Out of the box

Chrome9
Firefox (Gecko)6
Internet Explorer10
Opera12.1
Safari5.1

With Polyfills

Pretty much everything. Check out these polyfills:

Keywords

FAQs

Last updated on 21 Aug 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc