Skip to content

Commit

Permalink
Add example.
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Jun 16, 2018
1 parent 4e6b062 commit 38df581
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 1 deletion.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
example/bundle.js
example/frame-bundle.js
dist
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
node_modules
/dist
/example/bundle.js
/generated-docs.md
/example/frame-bundle.js
.eslintcache
package-lock.json
1 change: 1 addition & 0 deletions example/.babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../.babelrc');
42 changes: 42 additions & 0 deletions example/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-env browser */
/* eslint-disable jsx-a11y/label-has-for */
import React from 'react';
import ReactDOM from 'react-dom';

class MainApp extends React.Component {
constructor(props) {
super(props);

this.state = {
large: true,
};

this.handleChange = this.handleChange.bind(this);
}

handleChange(event) {
this.setState({
large: event.target.checked,
});
}

render() {
return (
<div>
<p>
<input id="size" type="checkbox" checked={this.state.large} onChange={this.handleChange} />
<label htmlFor="size">
Large iframe
</label>
</p>
<iframe
width={this.state.large ? 800 : 500}
title="demo iframe"
src="frame.html"
/>
</div>
);
}
}

ReactDOM.render(<MainApp />, document.getElementById('example'));
10 changes: 10 additions & 0 deletions example/frame.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div id="example"></div>
<script src="frame-bundle.js"></script>
</body>
</html>
23 changes: 23 additions & 0 deletions example/frame.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint-env browser */
import React from 'react';
import ReactDOM from 'react-dom';
import MediaQuery from '../';

const FrameApp = () => (
<div>
<MediaQuery
query="(min-width: 768px)"
render={matches => (
<p>Matches: {JSON.stringify(matches)}</p>
)}
/>
<MediaQuery query="(min-width: 768px)">
<p>Big screen!</p>
</MediaQuery>
<MediaQuery query="(max-width: 767px)">
<p>Small screen!</p>
</MediaQuery>
</div>
);

ReactDOM.render(<FrameApp />, document.getElementById('example'));
31 changes: 31 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>@u-wave/react-mq example</title>
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css">
<style>
.example-container {
max-width: 1280px;
margin: auto;
}
</style>
</head>
<body>
<div class="example-container">
<div class="row">
<div class="col s12">
<h1>@u-wave/react-mq example</h1>
<p>
An example responsive component using <a href="https://facebook.github.io/react">React</a>
and <a href="https://github.com/u-wave/react-mq">@u-wave/react-mq</a>.
<a href="https://github.com/u-wave/react-mq/tree/master/example">view source</a>
</p>
</div>
</div>
</div>
<div class="example-container" id="example"></div>
<script src="bundle.js"></script>
</body>
</html>
25 changes: 25 additions & 0 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"private": true,
"name": "@u-wave/react-mq-example",
"description": "react-mq example.",
"version": "0.0.0-example",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "npm run build",
"build": "npm run build:frame && npm run build:main",
"build:main": "cross-env BABEL_ENV=cjs browserify -t babelify frame.js > frame-bundle.js",
"build:frame": "cross-env BABEL_ENV=cjs browserify -t babelify app.js > bundle.js",
"start": "ecstatic ."
},
"dependencies": {
"ecstatic": "^3.0.0",
"react": "^16.0.0",
"react-dom": "^16.0.0"
},
"devDependencies": {
"@babel/core": "7.0.0-beta.51",
"babelify": "^9.0.0",
"browserify": "^16.0.0",
"cross-env": "^5.1.6"
}
}

0 comments on commit 38df581

Please sign in to comment.