Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Contra committed Jul 14, 2017
2 parents 40fe34e + f0c9f8d commit 516f270
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 21 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,34 @@ var A = React.createClass({
});
```

### Common use cases

```javascript
import Responsive from 'react-responsive';

// Desktop, tablet and mobile setup
const Desktop = ({ children }) => <Responsive minWidth={992} children={children} />;
const Tablet = ({ children }) => <Responsive minWidth={768} maxWidth={992} children={children} />;
const Mobile = ({ children }) => <Responsive maxWidth={768} children={children} />;

// Default (desktop, tablet) and mobile setup
const Default = ({ children }) => <Responsive minWidth={768} children={children} />;
const Mobile = ({ children }) => <Responsive maxWidth={768} children={children} />;

const Example = () => (
<div>
<Desktop>You are a desktop or laptop</Desktop>
<Tablet>You are a tablet</Tablet>
<Mobile>You are a mobile phone</Mobile>

<Default>You are not a mobile phone</Default>
<Mobile>You are a mobile phone</Mobile>
</div>
);

export default Example;
```

## Browser Support

### Out of the box
Expand Down
13 changes: 10 additions & 3 deletions dist/react-responsive.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/react-responsive.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/react-responsive.min.js

Large diffs are not rendered by default.

91 changes: 86 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-responsive",
"description": "Media queries in react for responsive design",
"version": "1.3.0",
"version": "1.3.1",
"homepage": "http://github.com/contra/react-responsive",
"repository": {
"type": "git",
Expand All @@ -28,7 +28,7 @@
],
"dependencies": {
"hyphenate-style-name": "^1.0.0",
"matchmedia": "^0.1.2",
"matchmediaquery": "^0.2.0",
"prop-types": "^15.5.7"
},
"peerDependencies": {
Expand All @@ -47,6 +47,7 @@
"babel-preset-stage-0": "^6.16.0",
"babel-register": "^6.18.0",
"chai": "^3.5.0",
"cross-env": "^5.0.1",
"eslint": "^3.9.0",
"eslint-config-rackt": "^1.1.1",
"github-changes": "^1.0.4",
Expand All @@ -63,12 +64,14 @@
"scripts": {
"preversion": "npm run clean && npm run build && npm docs",
"postversion": "npm run changelog",
"start": "$(npm bin)/webpack-dev-server --config webpack.config.samples.js --content-base samples/sandbox/src --host 0.0.0.0 --hot --inline --port 3333",
"build": "$(npm bin)/webpack",
"start": "webpack-dev-server --config webpack.config.samples.js --content-base samples/sandbox/src --host 0.0.0.0 --hot --inline --port 3333",
"build:umd": "cross-env BUILD_MODE=umd webpack",
"build:umd-min": "cross-env BUILD_MODE=umd-min webpack",
"build": "npm run build:umd && npm run build:umd-min",
"build:watch": "npm run build -- --watch",
"clean": "rimraf dist",
"lint": "$(npm bin)/eslint src",
"test": "NODE_PATH=$NODE_PATH:$PWD/src $(npm bin)/mocha -R spec --compilers js:babel-register --require ./test/setup.js test/*_test.js",
"lint": "eslint src",
"test": "cross-env NODE_PATH=$NODE_PATH:$PWD/src mocha -R spec --compilers js:babel-register --require ./test/setup.js test/*_test.js",
"changelog": "github-changes -o contra -r react-responsive -b master -f ./CHANGELOG.md --order-semver --use-commit-body",
"docs": "npm run docs:pre && npm run docs:build && npm run docs:publish",
"docs:pre": "gitbook install && rimraf _book",
Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import PropTypes from 'prop-types'
import matchMedia from 'matchmedia'
import matchMedia from 'matchmediaquery'
import hyphenate from 'hyphenate-style-name'
import mediaQuery from './mediaQuery'
import toQuery from './toQuery'
Expand Down Expand Up @@ -62,6 +62,7 @@ export default class MediaQuery extends React.Component {

if (this._mql) {
this._mql.removeListener(this.updateMatches)
this._mql.dispose();
}

this._mql = matchMedia(this.query, values)
Expand All @@ -74,7 +75,7 @@ export default class MediaQuery extends React.Component {
this.props.onBeforeChange(this.state.matches)
}
}

componentDidUpdate(_, prevState) {
if(this.props.onChange && prevState.matches !== this.state.matches) {
this.props.onChange(this.state.matches)
Expand All @@ -83,6 +84,7 @@ export default class MediaQuery extends React.Component {

componentWillUnmount() {
this._mql.removeListener(this.updateMatches)
this._mql.dispose();
}

updateMatches = () => {
Expand Down
2 changes: 1 addition & 1 deletion test/index_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var React = require('react');
var MediaQuery = require('index');
var mm = { default: require('matchmedia') };
var mm = { default: require('matchmediaquery') };
var assert = require('chai').assert;
var sinon = require('sinon');
var TestUtils = require('react-addons-test-utils');
Expand Down
2 changes: 1 addition & 1 deletion test/setup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var jsdom = require('jsdom').jsdom;
var matchMedia = require('matchmedia');
var matchMedia = require('matchmediaquery');

process.env.NODE_ENV = 'test';

Expand Down
7 changes: 5 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const webpack = require('webpack')
module.exports = {
entry: './src/index.js',
output: {
filename: './dist/react-responsive.js',
filename: (process.env.BUILD_MODE == 'umd') ? './dist/react-responsive.js' :
'./dist/react-responsive.min.js',
sourceMapFilename: './dist/react-responsive.js.map',
libraryTarget: 'umd',
library: 'MediaQuery'
Expand All @@ -16,7 +17,9 @@ module.exports = {
},
plugins: [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.DedupePlugin()
new webpack.optimize.DedupePlugin(),
...((process.env.BUILD_MODE == 'umd-min') ?
[new webpack.optimize.UglifyJsPlugin()] : [])
],
resolve: {
extensions: [ '', '.js' ],
Expand Down

0 comments on commit 516f270

Please sign in to comment.