Skip to content

Commit e6e9dc1

Browse files
committed
Added search compact layout
1 parent a426856 commit e6e9dc1

File tree

1 file changed

+58
-16
lines changed

1 file changed

+58
-16
lines changed

components/Search/index.vue

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<template>
22
<div>
3-
<div class="search" :class="{ 'is-open': openSuggestion }">
3+
<div class="search" :class="{
4+
'is-open': openSuggestion,
5+
'has-selected': hasSelected,
6+
'has-province': hasSelected && provinces.length && provinces[0].province
7+
}">
48
<div class="search-container">
59
<div class="countries-wrapper">
610
<input
@@ -14,11 +18,7 @@
1418
@input="change"
1519
/>
1620
</div>
17-
<div
18-
class="provinces-wrapper"
19-
:class="{
20-
'is-show': hasSelected && provinces.length && provinces[0].province
21-
}">
21+
<div class="provinces-wrapper">
2222
<select
2323
ref="provinces"
2424
@focus="onFocus"
@@ -94,6 +94,9 @@ export default {
9494
return (
9595
this.country !== '' && this.matches.length != 0 && this.open
9696
)
97+
},
98+
isProvinceFocus() {
99+
return this.$refs.provinces && this.hasSelected && this.provinces.length && this.provinces[0].province
97100
}
98101
},
99102
data() {
@@ -124,7 +127,7 @@ export default {
124127
value: this.country
125128
})
126129
this.$nextTick(_ => {
127-
if (this.$refs.provinces) this.$refs.provinces.focus()
130+
if (this.isProvinceFocus) this.$refs.provinces.focus()
128131
})
129132
}
130133
},
@@ -154,7 +157,9 @@ export default {
154157
this.tempValue = this.country
155158
this.open = false
156159
this.hasSelected = true
157-
if (this.$refs.provinces) this.$refs.provinces.focus()
160+
if (this.isProvinceFocus) {
161+
this.$refs.provinces.focus()
162+
}
158163
this.$gtag('event', 'click', {
159164
event_category: 'select',
160165
event_label: 'select click',
@@ -203,7 +208,7 @@ export default {
203208
position: absolute;
204209
left: 50%;
205210
bottom: 56px;
206-
z-index: 1;
211+
z-index: 10;
207212
padding: 0;
208213
width: calc(100% - 48px);
209214
transform: translateX(-50%);
@@ -224,14 +229,45 @@ export default {
224229
}
225230
}
226231
232+
&.has-selected {
233+
234+
button {
235+
border-radius: 0 0 4px 4px;
236+
}
237+
238+
.countries-wrapper {
239+
border-radius: 4px 4px 0 0;
240+
transform: translateY(calc(100% + 2px));
241+
}
242+
243+
.provinces-wrapper {
244+
border-radius: 4px 4px 0 0;
245+
box-shadow: none;
246+
transform: translateY(0%);
247+
}
248+
}
249+
250+
&.has-province {
251+
252+
.countries-wrapper {
253+
transform: translateY(2px);
254+
}
255+
256+
.provinces-wrapper {
257+
transform: translateY(-2px);
258+
}
259+
}
260+
227261
button {
228262
position:relative;
263+
z-index: 7;
229264
top: 0px;
230265
border: none;
231266
color: #f2f2f2;
232267
border-radius: 4px;
233268
padding: 8px 16px;
234269
width: 100%;
270+
height: 52px;
235271
font-size: 18px;
236272
background-color: #3232ff;
237273
box-shadow: 0px 6px 2px -1px rgba(0, 0, 0, 0.2);
@@ -248,11 +284,15 @@ export default {
248284
249285
.countries-wrapper,
250286
.provinces-wrapper {
287+
position: relative;
288+
z-index: 9;
251289
border-radius: 4px;
252-
margin: 0 auto 12px;
290+
margin: 0 auto;
253291
padding: 12px 16px;
254292
background-color: #ffffff;
255293
box-shadow: 0px 6px 2px -1px rgba(0, 0, 0, 0.2);
294+
transform: translateY(100%);
295+
transition: 0.6s cubic-bezier(0.83, 0, 0.17, 1);
256296
257297
input,
258298
select {
@@ -262,20 +302,22 @@ export default {
262302
font-size: 24px;
263303
width: 100%;
264304
background-color: transparent;
305+
outline: none;
265306
}
266307
}
267308
268-
.provinces-wrapper {
269-
display: none;
309+
.countries-wrapper {
310+
transform: translateY(calc(200% + 2px));
311+
}
270312
271-
&.is-show {
272-
display: block;
273-
}
313+
.provinces-wrapper {
314+
transform: translateY(calc(100% - 1px));
315+
z-index: 6;
274316
}
275317
276318
.dropdown-menu {
277319
position: absolute;
278-
top: -1px;
320+
top: calc(100% - 52px);
279321
margin: 0;
280322
padding: 0;
281323
display: none;

0 commit comments

Comments
 (0)