Created
August 4, 2015 11:18
-
-
Save nelix/aaf6b7282e81541c38f7 to your computer and use it in GitHub Desktop.
npm i && npm start && open index.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const React = require('react'); | |
| const { TransitionSpring } = require('react-motion'); | |
| const Router = require('react-router'); | |
| const RouteTransition = React.createClass({ | |
| propTypes: { | |
| pathname: React.PropTypes.string.isRequired | |
| }, | |
| willEnter() { | |
| const { children } = this.props; | |
| return { | |
| handler: children, | |
| opacity: { val: 0 }, | |
| scale: { val: 0.95 } | |
| }; | |
| }, | |
| willLeave(key, value) { | |
| return { | |
| handler: value.handler, | |
| opacity: { val: 0 }, | |
| scale: { val: 0.95 } | |
| }; | |
| }, | |
| getEndValue() { | |
| const { children, pathname } = this.props; | |
| return { | |
| [pathname]: { | |
| handler: children, | |
| opacity: { val: 1 }, | |
| scale: { val: 1 } | |
| } | |
| }; | |
| }, | |
| render() { | |
| return ( | |
| <TransitionSpring | |
| endValue={this.getEndValue} | |
| willEnter={this.willEnter} | |
| willLeave={this.willLeave} | |
| > | |
| {interpolated => | |
| <div> | |
| {Object.keys(interpolated).map(key => | |
| <div | |
| key={`${key}-transition`} | |
| style={{ | |
| position: 'absolute', | |
| opacity: interpolated[key].opacity.val, | |
| transform: `scale(${interpolated[key].scale.val})` | |
| }} | |
| > | |
| {interpolated[key].handler} | |
| </div> | |
| )} | |
| </div> | |
| } | |
| </TransitionSpring> | |
| ); | |
| } | |
| }); | |
| var App = React.createClass({ | |
| contextTypes: { | |
| router: React.PropTypes.func | |
| }, | |
| render: function () { | |
| var name = this.context.router.getCurrentPath(); | |
| return ( | |
| <div> | |
| <ul> | |
| <li><Router.Link to="page1">Page 1</Router.Link></li> | |
| <li><Router.Link to="page2">Page 2</Router.Link></li> | |
| </ul> | |
| <RouteTransition pathname={name}> | |
| <Router.RouteHandler/> | |
| </RouteTransition> | |
| </div> | |
| ); | |
| } | |
| }); | |
| var Page1 = React.createClass({ | |
| render: function () { | |
| return ( | |
| <div className="Image"> | |
| <h1>Page 1</h1> | |
| <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> | |
| </div> | |
| ); | |
| } | |
| }); | |
| var Page2 = React.createClass({ | |
| render: function () { | |
| return ( | |
| <div className="Image"> | |
| <h1>Page 2</h1> | |
| <p>Consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> | |
| </div> | |
| ); | |
| } | |
| }); | |
| var routes = ( | |
| <Router.Route handler={App}> | |
| <Router.Route name="page1" handler={Page1} /> | |
| <Router.Route name="page2" handler={Page2} /> | |
| </Router.Route> | |
| ); | |
| Router.run(routes, function (Handler) { | |
| React.render(<Handler/>, document.getElementById('appdiv')); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <body> | |
| <div id='appdiv'></div> | |
| <script src="dist/app.js"></script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "router-motion", | |
| "version": "1.0.0", | |
| "description": "", | |
| "main": "index.js", | |
| "scripts": { | |
| "start": "webpack", | |
| "test": "echo \"Error: no test specified\" && exit 1" | |
| }, | |
| "author": "", | |
| "license": "ISC", | |
| "dependencies": { | |
| "babel-loader": "^5.3.2", | |
| "react": "^0.13.3", | |
| "react-motion": "^0.2.6", | |
| "react-router": "^0.13.3", | |
| "webpack": "^1.10.5" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var path = require('path'); | |
| var webpack = require('webpack'); | |
| var entry = { | |
| app: ['./app'], | |
| }; | |
| module.exports = { | |
| devtool: 'source-map', | |
| debug: true, | |
| entry: entry, | |
| output: { | |
| filename: '[name].js', | |
| path: path.join(__dirname, 'dist'), | |
| }, | |
| resolve: { | |
| extensions: ['', '.txt', '.js', '.jsx', '.css', '.mcss'], | |
| }, | |
| module: { | |
| loaders: [ | |
| { | |
| test: /\.js$/, | |
| exclude: /(node_modules)/, | |
| loader: 'babel?cacheDirectory&stage=0', | |
| }, | |
| ], | |
| }, | |
| }; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment