Skip to content

Commit 5deb982

Browse files
Brandon Dailnhunzaker
authored andcommitted
Use create-react-app for fixtures application
This moves the current fixture architecture to one based around create-react-app. There are a few important things to note: * The react-loader.js script is always loaded before the bundle and will populate React and ReactDOM on the window. It is then read from the window by all components. * The UI for the "React Sandbox" or "React Fixtures App" is also rendered with whatever version of React the user has selected. This means we dont have to deal with iframes or worry about multiple versions of React potentially interferring. But it also means that all components must be written using createClass to be fully backwards compatable. I tested back to 0.13.1 and it works fine.
1 parent bf23548 commit 5deb982

File tree

27 files changed

+5867
-560
lines changed

27 files changed

+5867
-560
lines changed

fixtures/.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# dependencies
4+
node_modules
5+
6+
# testing
7+
coverage
8+
9+
# production
10+
build
11+
12+
# misc
13+
.DS_Store
14+
.env
15+
npm-debug.log

fixtures/package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "_fixtures",
3+
"version": "0.1.0",
4+
"private": true,
5+
"devDependencies": {
6+
"react-scripts": "0.8.4"
7+
},
8+
"dependencies": {
9+
"query-string": "^4.2.3",
10+
"react": "^15.4.1",
11+
"react-dom": "^15.4.1"
12+
},
13+
"scripts": {
14+
"start": "react-scripts start",
15+
"build": "react-scripts build",
16+
"test": "react-scripts test --env=jsdom",
17+
"eject": "react-scripts eject"
18+
}
19+
}

fixtures/public/favicon.ico

24.3 KB
Binary file not shown.

fixtures/public/index.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
7+
<!--
8+
Notice the use of %PUBLIC_URL% in the tag above.
9+
It will be replaced with the URL of the `public` folder during the build.
10+
Only files inside the `public` folder can be referenced from the HTML.
11+
12+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
13+
work correctly both with client-side routing and a non-root public URL.
14+
Learn how to configure a non-root public URL by running `npm run build`.
15+
-->
16+
<title>React App</title>
17+
<script src="react-loader.js"></script>
18+
</head>
19+
<body>
20+
<div id="root"></div>
21+
<!--
22+
This HTML file is a template.
23+
If you open it directly in the browser, you will see an empty page.
24+
25+
You can add webfonts, meta tags, or analytics to this file.
26+
The build step will place the bundled scripts into the <body> tag.
27+
28+
To begin the development, run `npm start`.
29+
To create a production bundle, use `npm run build`.
30+
-->
31+
</body>
32+
</html>
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* (Loads React 15.4.1)
88
*/
99

10-
var REACT_PATH = '../../build/react.js';
11-
var DOM_PATH = '../../build/react-dom.js';
10+
var REACT_PATH = 'react.js';
11+
var DOM_PATH = 'react-dom.js';
1212
var BABEL_PATH = 'https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.19.0/babel.js';
1313

1414
function parseQuery(qstr) {
@@ -25,9 +25,11 @@ function parseQuery(qstr) {
2525
return query;
2626
}
2727

28-
var query = parseQuery(window.location.search.slice(1));
28+
var query = parseQuery(window.location.search);
2929
var version = query.version || 'local';
3030

31+
console.log(query)
32+
3133
if (version !== 'local') {
3234
REACT_PATH = 'https://unpkg.com/react@' + version + '/dist/react.min.js';
3335
DOM_PATH = 'https://unpkg.com/react-dom@' + version + '/dist/react-dom.min.js';

fixtures/range-inputs/index.html

Lines changed: 0 additions & 82 deletions
This file was deleted.

fixtures/selects/index.html

Lines changed: 0 additions & 84 deletions
This file was deleted.

fixtures/src/components/App.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const React = window.React;
2+
import Header from './Header';
3+
import Fixtures from './fixtures';
4+
import '../styles/App.css';
5+
6+
const App = React.createClass({
7+
render() {
8+
return (
9+
<div>
10+
<Header />
11+
<div className="container" >
12+
<Fixtures />
13+
</div>
14+
</div>
15+
);
16+
},
17+
});
18+
19+
export default App;

fixtures/src/components/Header.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { parse, stringify } from 'query-string';
2+
const React = window.React;
3+
4+
const Header = React.createClass({
5+
getInitialState() {
6+
const query = parse(window.location.search);
7+
const version = query.version || 'local';
8+
const versions = [version];
9+
return { version, versions };
10+
},
11+
componentWillMount() {
12+
fetch('http://api.github.com/repos/facebook/react/tags')
13+
.then(res => res.json())
14+
.then(tags => {
15+
let versions = tags.map(tag => tag.name.slice(1));
16+
versions = ['local', ...versions];
17+
this.setState({ versions });
18+
});
19+
},
20+
handleVersionChange(event) {
21+
const query = parse(window.location.search);
22+
query.version = event.target.value;
23+
if (query.version === 'local') {
24+
delete query.version;
25+
}
26+
window.location.search = stringify(query);
27+
},
28+
handleFixtureChange(event) {
29+
window.location.pathname = event.target.value;
30+
},
31+
render() {
32+
return (
33+
<header className="header">
34+
<div className="header__inner">
35+
<span className="header__logo">
36+
<img src="https://facebook.github.io/react/img/logo.svg" alt="" width="32" height="32" />
37+
React Sandbox (v{React.version})
38+
</span>
39+
40+
<div className="header-controls">
41+
<label htmlFor="example">
42+
<span className="sr-only">Select an example</span>
43+
<select value={window.location.pathname} onChange={this.handleFixtureChange}>
44+
<option value="/">Select a Fixture</option>
45+
<option value="/range-inputs">Range Inputs</option>
46+
<option value="/text-inputs">Text Inputs</option>
47+
<option value="/selects">Selects</option>
48+
<option value="/textareas">Textareas</option>
49+
</select>
50+
</label>
51+
<label htmlFor="react_version">
52+
<span className="sr-only">Select a version to test</span>
53+
<select
54+
value={this.state.version}
55+
onChange={this.handleVersionChange}>
56+
{this.state.versions.map(version => (
57+
<option key={version} value={version}>{version}</option>
58+
))}
59+
</select>
60+
</label>
61+
</div>
62+
</div>
63+
</header>
64+
);
65+
},
66+
});
67+
68+
export default Header;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const React = window.React;
2+
3+
const RangeInputs = React.createClass({
4+
getInitialState() {
5+
return { value: 0.5 };
6+
},
7+
onChange(event) {
8+
this.setState({ value: event.target.value });
9+
},
10+
render() {
11+
return (
12+
<form>
13+
<fieldset>
14+
<legend>Controlled</legend>
15+
<input type="range" value={this.state.value} onChange={this.onChange.bind(this)} />
16+
<span className="hint">Value: {this.state.value}</span>
17+
</fieldset>
18+
19+
<fieldset>
20+
<legend>Uncontrolled</legend>
21+
<input type="range" defaultValue={0.5} />
22+
</fieldset>
23+
</form>
24+
);
25+
},
26+
});
27+
28+
export default RangeInputs;

0 commit comments

Comments
 (0)