-
Notifications
You must be signed in to change notification settings - Fork 98
/
Typeahead.vue
145 lines (121 loc) · 2.66 KB
/
Typeahead.vue
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
143
144
145
<template>
<div class="Typeahead">
<i class="fa fa-spinner fa-spin" v-if="loading"></i>
<template v-else>
<i class="fa fa-search" v-show="isEmpty"></i>
<i class="fa fa-times" v-show="isDirty" @click="reset"></i>
</template>
<input type="text"
class="Typeahead__input"
placeholder="Search twitter user"
autocomplete="off"
v-model="query"
@keydown.down="down"
@keydown.up="up"
@keydown.enter="hit"
@keydown.esc="reset"
@blur="reset"
@input="update"/>
<ul v-show="hasItems">
<li v-for="(item, $item) in items" :class="activeClass($item)" @mousedown="hit" @mousemove="setActive($item)">
<span class="name" v-text="item.name"></span>
<span class="screen-name" v-text="item.screen_name"></span>
</li>
</ul>
</div>
</template>
<script>
import VueTypeahead from '../src/main'
export default {
extends: VueTypeahead,
data () {
return {
src: 'https://typeahead-js-twitter-api-proxy.herokuapp.com/demo/search',
limit: 5,
minChars: 3
}
},
methods: {
onHit (item) {
window.location.href = 'http://twitter.com/' + item.screen_name
}
}
}
</script>
<style scoped>
.Typeahead {
position: relative;
}
.Typeahead__input {
width: 100%;
font-size: 14px;
color: #2c3e50;
line-height: 1.42857143;
box-shadow: inset 0 1px 4px rgba(0,0,0,.4);
-webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
font-weight: 300;
padding: 12px 26px;
border: none;
border-radius: 22px;
letter-spacing: 1px;
box-sizing: border-box;
}
.Typeahead__input:focus {
border-color: #4fc08d;
outline: 0;
box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px #4fc08d;
}
.fa-times {
cursor: pointer;
}
i {
float: right;
position: relative;
top: 30px;
right: 29px;
opacity: 0.4;
}
ul {
position: absolute;
padding: 0;
margin-top: 8px;
min-width: 100%;
background-color: #fff;
list-style: none;
border-radius: 4px;
box-shadow: 0 0 10px rgba(0,0,0, 0.25);
z-index: 1000;
}
li {
padding: 10px 16px;
border-bottom: 1px solid #ccc;
cursor: pointer;
}
li:first-child {
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}
li:last-child {
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-bottom: 0;
}
span {
display: block;
color: #2c3e50;
}
.active {
background-color: #3aa373;
}
.active span {
color: white;
}
.name {
font-weight: 700;
font-size: 18px;
}
.screen-name {
font-style: italic;
}
</style>