JSFiddle - React, Tailwind, and code Playground
by ahnfelt
HTML
<script src="http://fb.me/react-with-addons-0.11.0.js"></script>
<script src="http://fb.me/JSXTransformer-0.11.0.js"></script>
<script src="http://fb.me/react-js-fiddle-integration.js"></script>
CSS
body {
margin: 0;
}
.add {
margin-left: 20px;
visibility: hidden;
cursor: pointer;
}
h3:hover .add, li:hover .add {
visibility: visible;
}
.method {
margin-left: 10px;
}
.method li {
border-radius: 3px;
margin-right: 30px;
cursor: pointer;
padding: 2px;
}
.method li:hover {
text-decoration: underline;
}
.method li.active {
text-decoration: underline;
font-weight: bold;
}
.picker {
height: 150px;
overflow: hidden;
position: fixed;
bottom: 0;
left: 0;
right: 0;
background-color: #f0f0f0;
}
.picker input {
display: block;
width: 100%;
height: 25px;
padding-left: 10px;
border: none;
border-top: 1px solid #a0a0a0;
border-bottom: 1px solid #b0b0b0;
}
.picker .active {
font-weight: bold;
text-decoration: underline;
}
JavaScript 1.7
/** @jsx React.DOM */
var Method = React.createClass({
render: function() {
return (
<div className="method">
<h3>Method:<button className='add'>+</button></h3>
<ul>
{this.props.steps.map((function(s, i) {
var className = this.props.currentStepIndex == i ? 'active' : '';
return <li key={i} className={className}>{s.command}<button className='add'>+</button></li>;
}).bind(this))}
</ul>
</div>
);
}
});
var CommandPicker = React.createClass({
getInitialState: function() {
return {
query: '',
currentPick: 0,
picks: [
"Add INGREDIENTS",
"Blend INGREDIENTS",
"Churn the drink",
"Lightly stir INGREDIENTS",
"Stir INGREDIENTS",
"Serve with straws",
"Serve without straws"
]
};
},
onKeyDown: function(event) {
switch(event.which) {
case 38: this.state.currentPick -= 1; break;
case 40: this.state.currentPick += 1; break;
case 9: this.state.currentPick += event.shiftKey ? -1 : 1; break;
default: return;
}
event.preventDefault();
this.state.currentPick = Math.min(Math.max(0, this.state.currentPick), this.state.picks.length - 1);
this.setState(this.state);
},
onChangeQuery: function() {
this.state.query = this.refs.search.getDOMNode().value;
this.state.currentPick = 0;
this.setState(this.state);
},
search: function() {
var terms = this.state.query.toLowerCase().split(/\s+/).filter(function(t) { return t.length != 0; });
var scoredPicks = this.state.picks.map(function(p) {
var score = 0;
var text = ' ' + p.toLowerCase();
...