-
Notifications
You must be signed in to change notification settings - Fork 46.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Brandon Dail
committed
Jan 3, 2017
1 parent
62c3c4b
commit 99bfa28
Showing
28 changed files
with
5,868 additions
and
576 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# See http://help.github.com/ignore-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
node_modules | ||
|
||
# testing | ||
coverage | ||
|
||
# production | ||
build | ||
|
||
# misc | ||
.DS_Store | ||
.env | ||
npm-debug.log |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1 @@ | ||
# Browser Fixtures | ||
|
||
This folder contains tools to assist in the testing of browser quirks. | ||
|
||
Each document is browsable without setting up a static file server. Just open | ||
the test case in a browser. | ||
|
||
## Browser Targets | ||
|
||
React 15+ supports all ES5 compliant browsers: | ||
|
||
https://facebook.github.io/react/docs/react-dom.html#browser-support | ||
|
||
### IE8 Support | ||
|
||
React 0.14 and lower support IE8 after including several required shims. | ||
# React Fixtures (TODO) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "_fixtures", | ||
"version": "0.1.0", | ||
"private": true, | ||
"devDependencies": { | ||
"react-scripts": "0.8.4" | ||
}, | ||
"dependencies": { | ||
"query-string": "^4.2.3", | ||
"react": "^15.4.1", | ||
"react-dom": "^15.4.1" | ||
}, | ||
"scripts": { | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test --env=jsdom", | ||
"eject": "react-scripts eject" | ||
} | ||
} |
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico"> | ||
<!-- | ||
Notice the use of %PUBLIC_URL% in the tag above. | ||
It will be replaced with the URL of the `public` folder during the build. | ||
Only files inside the `public` folder can be referenced from the HTML. | ||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | ||
work correctly both with client-side routing and a non-root public URL. | ||
Learn how to configure a non-root public URL by running `npm run build`. | ||
--> | ||
<title>React App</title> | ||
<script src="react-loader.js"></script> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<!-- | ||
This HTML file is a template. | ||
If you open it directly in the browser, you will see an empty page. | ||
You can add webfonts, meta tags, or analytics to this file. | ||
The build step will place the bundled scripts into the <body> tag. | ||
To begin the development, run `npm start`. | ||
To create a production bundle, use `npm run build`. | ||
--> | ||
</body> | ||
</html> |
This file contains 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const React = window.React; | ||
import Header from './Header'; | ||
import Fixtures from './fixtures'; | ||
import '../styles/App.css'; | ||
|
||
const App = React.createClass({ | ||
render() { | ||
return ( | ||
<div> | ||
<Header /> | ||
<div className="container" > | ||
<Fixtures /> | ||
</div> | ||
</div> | ||
); | ||
}, | ||
}); | ||
|
||
export default App; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { parse, stringify } from 'query-string'; | ||
const React = window.React; | ||
|
||
const Header = React.createClass({ | ||
getInitialState() { | ||
const query = parse(window.location.search); | ||
const version = query.version || 'local'; | ||
const versions = [version]; | ||
return { version, versions }; | ||
}, | ||
componentWillMount() { | ||
fetch('http://api.github.com/repos/facebook/react/tags') | ||
.then(res => res.json()) | ||
.then(tags => { | ||
let versions = tags.map(tag => tag.name.slice(1)); | ||
versions = ['local', ...versions]; | ||
this.setState({ versions }); | ||
}); | ||
}, | ||
handleVersionChange(event) { | ||
const query = parse(window.location.search); | ||
query.version = event.target.value; | ||
if (query.version === 'local') { | ||
delete query.version; | ||
} | ||
window.location.search = stringify(query); | ||
}, | ||
handleFixtureChange(event) { | ||
window.location.pathname = event.target.value; | ||
}, | ||
render() { | ||
return ( | ||
<header className="header"> | ||
<div className="header__inner"> | ||
<span className="header__logo"> | ||
<img src="https://facebook.github.io/react/img/logo.svg" alt="" width="32" height="32" /> | ||
React Sandbox (v{React.version}) | ||
</span> | ||
|
||
<div className="header-controls"> | ||
<label htmlFor="example"> | ||
<span className="sr-only">Select an example</span> | ||
<select value={window.location.pathname} onChange={this.handleFixtureChange}> | ||
<option value="/">Select a Fixture</option> | ||
<option value="/range-inputs">Range Inputs</option> | ||
<option value="/text-inputs">Text Inputs</option> | ||
<option value="/selects">Selects</option> | ||
<option value="/textareas">Textareas</option> | ||
</select> | ||
</label> | ||
<label htmlFor="react_version"> | ||
<span className="sr-only">Select a version to test</span> | ||
<select | ||
value={this.state.version} | ||
onChange={this.handleVersionChange}> | ||
{this.state.versions.map(version => ( | ||
<option key={version} value={version}>{version}</option> | ||
))} | ||
</select> | ||
</label> | ||
</div> | ||
</div> | ||
</header> | ||
); | ||
}, | ||
}); | ||
|
||
export default Header; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const React = window.React; | ||
|
||
const RangeInputs = React.createClass({ | ||
getInitialState() { | ||
return { value: 0.5 }; | ||
}, | ||
onChange(event) { | ||
this.setState({ value: event.target.value }); | ||
}, | ||
render() { | ||
return ( | ||
<form> | ||
<fieldset> | ||
<legend>Controlled</legend> | ||
<input type="range" value={this.state.value} onChange={this.onChange.bind(this)} /> | ||
<span className="hint">Value: {this.state.value}</span> | ||
</fieldset> | ||
|
||
<fieldset> | ||
<legend>Uncontrolled</legend> | ||
<input type="range" defaultValue={0.5} /> | ||
</fieldset> | ||
</form> | ||
); | ||
}, | ||
}); | ||
|
||
export default RangeInputs; |
Oops, something went wrong.