-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhoneList.html
132 lines (129 loc) · 3.68 KB
/
PhoneList.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
<html>
<header>
<title>MyReact</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser.js"></script>
<style>
.contacts{
width: 300px;
margin: 0 auto;
}
.search-field{
width: 100%;
padding: 10px;
font-size: 16px;
}
.contacts-list{
padding: 0;
width: 100%;
}
.contact{
display: flex;
align-items: center;
font-family: sans-srif;
width: 100%;
padding: 5px;
border-bottom: 1px dotted grey;
}
.contact-image{
border-radius: 50%;
margin: 5px;
}
.contact-name{
font-size: 20px;
font-weight: bold;
}
.contact-number{
font-size: 18px;
color: grey;
}
</style>
</header>
<body>
<div id="content"></div>
<script type="text/babel">
var _contacts = [
{
id: 1,
name: "Dart Vader",
phoneNumber: "+2235245",
image: "http://68.media.tumblr.com/tumblr_m8m79qxtr41rvwq31o1_250.gif"
},
{
id: 2,
name: "Princess Leia",
phoneNumber: "+1165487",
image: "http://images6.fanpop.com/image/photos/33100000/CARRIE-FISHER-anakin-vader-and-princess-leia-33186069-190-149.gif"
},
{
id: 3,
name: "Luke Skywalker",
phoneNumber: "+15678641",
image: "http://i.imgur.com/cRaR2VI.gif"
},
{
id: 4,
name: "Chewbacca",
phoneNumber: "+2504878561",
image: "https://media.giphy.com/media/RUUdVZqwpfTRS/giphy.gif"
}
];
class Contact extends React.Component{
render(){
return (
<li className="contact">
<img className="contact-image" src={this.props.image} width="60px" height="60px"/>
<div className="contact-info">
<div className="contact-name">{this.props.name}</div>
<div className="contact-number">{this.props.phoneNumber}</div>
</div>
</li>
);
}
}
class ContactsList extends React.Component{
constructor(props) {
super(props);
this.state = {
displayedContacts: _contacts
};
this.handleSearch = this.handleSearch.bind(this)
}
handleSearch(event){
var searchQuery = event.target.value.toLowerCase();
var displayedContacts = _contacts.filter(function(item){
var searchValue = item.name.toLowerCase();
return (searchValue.indexOf(searchQuery) !== -1);
});
this.setState({
displayedContacts: displayedContacts
});
}
render(){
return(
<div className="contacts">
<input type="text" className="search-field"
onChange={this.handleSearch}/>
<ul className="contacts-list">
{
this.state.displayedContacts.map(function(item){
return <Contact key={item.id}
name={item.name}
phoneNumber={item.phoneNumber}
image={item.image}
/>;
})
}
</ul>
</div>
);
}
}
ReactDOM.render(
<ContactsList/>,
document.getElementById("content")
);
</script>
</body>
</html>