-
Notifications
You must be signed in to change notification settings - Fork 47.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
181 additions
and
21 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,3 @@ | ||
# Input Test Case | ||
|
||
More information around the history of inputs could go here. |
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,124 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
|
||
<title>Inputs</title> | ||
|
||
<style> | ||
body { | ||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; | ||
} | ||
|
||
label { | ||
display: block; | ||
text-transform: uppercase; | ||
letter-spacing: 0.01em; | ||
font-size: 12px; | ||
margin-bottom: 4px; | ||
} | ||
|
||
h1 { | ||
text-align: center; | ||
} | ||
|
||
.field { | ||
padding: 8px; | ||
} | ||
|
||
form { | ||
display: flex; | ||
max-width: 900px; | ||
margin: 0 auto; | ||
width: 100%; | ||
} | ||
|
||
fieldset { | ||
border: 1px solid #aaa; | ||
padding: 16px; | ||
flex-grow: 1; | ||
flex-basis: 50%; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="container">Loading...</div> | ||
|
||
<script src="../react-loader.js"></script> | ||
|
||
<script type="text/babel"> | ||
var Inputs = React.createClass({ | ||
|
||
getInitialState() { | ||
return { | ||
color: "#ffaaee" | ||
} | ||
}, | ||
|
||
renderControlled(type) { | ||
let id = `controlled_${type}` | ||
|
||
let onChange = e => { | ||
let value = e.target.value | ||
|
||
if (type === 'number') { | ||
value = value == '' ? '' : parseFloat(value, 10) || 0 | ||
} | ||
|
||
this.setState({ | ||
[type] : value | ||
}) | ||
} | ||
|
||
let state = this.state[type] || '' | ||
|
||
return ( | ||
<div key={type} className="field"> | ||
<label htmlFor={id}>{type}</label> | ||
<input id={id} type={type} value={state} onChange={onChange} /> | ||
→ {JSON.stringify(state)} | ||
</div> | ||
) | ||
}, | ||
|
||
renderUncontrolled(type) { | ||
let id = `uncontrolled_${type}` | ||
|
||
return ( | ||
<div key={type} className="field"> | ||
<label htmlFor={id}>{type}</label> | ||
<input id={id} type={type} /> | ||
</div> | ||
) | ||
}, | ||
|
||
render() { | ||
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input | ||
let types = [ | ||
'text', 'email', 'number', 'url', 'tel', | ||
'color', 'date', 'datetime-local', | ||
'time', 'month', 'week', 'range', 'password' | ||
] | ||
|
||
return ( | ||
<div> | ||
<h1>Input Kitchen Sink</h1> | ||
<form onSubmit={e=>e.preventDefault()}> | ||
<fieldset> | ||
<legend>Controlled</legend> | ||
{types.map(this.renderControlled)} | ||
</fieldset> | ||
<fieldset> | ||
<legend>Uncontrolled</legend> | ||
{types.map(this.renderUncontrolled)} | ||
</fieldset> | ||
</form> | ||
</div> | ||
) | ||
} | ||
}) | ||
|
||
ReactDOM.render(<Inputs />, document.getElementById('container')) | ||
</script> | ||
</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 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