-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathSample.js
45 lines (43 loc) · 1.44 KB
/
Sample.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// jshint ignore: start
var React = require('react');
var _ = require('underscore');
module.exports = React.createClass({
getInitialState: function() {
return {
texts: [
"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz 0123456789",
"Font Name",
"Grumpy wizards make toxic brew for the evil Queen and Jack.",
"Bright vixens jump dozy fowl quack",
"Waltz bad nymph for quick jugs vex",
"Brick quiz whangs jumpy veldt fox",
"The quick brown fox jumps over the lazy dog."
]
};
},
componentWillMount: function () {
this.delayedCallback = _.debounce(function(event) {
var value = event.target.value;
this.props.onChange({text: value});
}, 500);
},
onChange: function (event) {
event.persist();
this.delayedCallback(event);
},
refresh: function() {
var value = this.state.texts.shift();
this.state.texts.push(value);
React.findDOMNode(this.refs.text).value = value;
this.props.onChange({text: value});
},
render: function() {
return (
<div className="text">
<h2>Preview Text</h2>
<input type="text" ref="text" onChange={this.onChange} defaultValue="The quick brown fox jumps over the lazy dog." />
<span className="refresh" onClick={this.refresh} title="Load Pangram"><i className="fa fa-refresh"></i></span>
</div>
);
}
});