-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
142 lines (124 loc) · 4.91 KB
/
index.html
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE html>
<html>
<head>
<script src="bower_components/react/react.js"></script>
<script src="bower_components/react/JSXTransformer.js"></script>
<link href="bower_components/bootstrap/dist/css/bootstrap.css" rel="stylesheet" type="text/css" />
<title>Practice Day 1!</title>
</head>
<style>
.spacer {
margin-top: 100px;
}
</style>
<body>
<h1>hello world</h1>
<div id="container" class="container">
</div>
<script type="text/jsx">
/** @jsx React.DOM */
var SearchBar = React.createClass({
handleChange: function(){
this.props.onFilterInput(
this.refs.filterTextInput.getDOMNode().value
);
},
render: function() {
return (
<div className ="row spacer">
<form action="" className=" pull-left form-inline">
<div className="form-group">
<input ref="filterTextInput" value={this.props.filterText} onChange={this.handleChange} className="form-control" type="text" placeholder="search by name"/>
</div>
</form>
</div>
);
}
});
var CustomerRow = React.createClass({
handleDelete: function(e){
e.preventDefault();
var node =this.getDOMNode();
React.unmountComponentAtNode(node);
node.remove();
},
render:function () {
return(
<tr>
<td>{this.props.user}</td>
<td><a href="" ref="removeThisElement"onClick={this.handleDelete} className="btn btn-danger">Remove</a></td>
</tr>
);
}
});
var CustomerTable = React.createClass({
render: function() {
var props = this.props
var rows = props.users
.filter(function(user){
return user.name.toLowerCase().indexOf(props.filterText.toLowerCase()) > -1;
})
.map(function(user){
return <CustomerRow key={user.name} user={user.name} />
})
return (
<div className="row col-sm-6">
<table className="table">
<thead>
<tr>
<th>Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{rows}
</tbody>
</table>
</div>
);
}
});
var CustomerApp = React.createClass({
getInitialState: function(){
return {
filterText: '',
users:[],
name:''
};
},
handleSubmit:function(e){
e.preventDefault();
var newData = this.state.users.concat({name: this.state.name});
this.setState({
users: newData
})
},
handleFilterInput: function(filterText){
this.setState({
filterText: filterText
});
},
onChangeName:function(e){
this.setState({name: e.target.value});
},
render: function() {
return (
<div>
<h1> Add a customer </h1>
<form onSubmit={this.handleSubmit} action="" className="form-inline">
<div className="form-group">
<label>Customer Name</label>
<input ref="handleUserInput" value={this.props.name} onChange={this.onChangeName} className="form-control" type="text"/>
<input type="submit" className="btn btn-primary" value="Add"/>
</div>
</form>
<SearchBar onFilterInput={this.handleFilterInput} filterText={this.state.filterText} />
<CustomerTable filterText={this.state.filterText} users={this.state.users} />
</div>
);
}
});
React.renderComponent(<CustomerApp />, document.getElementById('container'));
</script>
</body>
</html>