2021-08-21 22:40:22 +00:00
|
|
|
<template>
|
|
|
|
<form
|
|
|
|
class="search"
|
2021-08-22 23:54:22 +00:00
|
|
|
@submit.prevent="() => search()"
|
2021-08-21 22:40:22 +00:00
|
|
|
>
|
|
|
|
<input
|
|
|
|
v-model="query"
|
|
|
|
:placeholder="placeholder || 'Search'"
|
|
|
|
class="query"
|
2021-08-22 23:54:22 +00:00
|
|
|
@input="() => search(true)"
|
2021-08-21 22:40:22 +00:00
|
|
|
>
|
|
|
|
|
|
|
|
<button
|
|
|
|
type="submit"
|
|
|
|
class="search-button"
|
|
|
|
><Icon icon="search" /></button>
|
|
|
|
</form>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-08-22 23:54:22 +00:00
|
|
|
function search(typing) {
|
|
|
|
if (!typing || this.eager) {
|
2021-08-23 00:38:16 +00:00
|
|
|
this.$router.replace({
|
|
|
|
query: { query: this.query || undefined },
|
|
|
|
params: { ...this.$route.params, pageNumber: 1 },
|
|
|
|
});
|
2021-08-22 23:54:22 +00:00
|
|
|
}
|
2021-08-21 22:40:22 +00:00
|
|
|
}
|
|
|
|
|
2021-08-22 20:25:20 +00:00
|
|
|
function resetQuery() {
|
|
|
|
this.query = this.$route.query.query || null;
|
|
|
|
}
|
|
|
|
|
2021-08-21 22:40:22 +00:00
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
placeholder: {
|
|
|
|
type: String,
|
|
|
|
default: null,
|
|
|
|
},
|
2021-08-22 23:54:22 +00:00
|
|
|
eager: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2021-08-21 22:40:22 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
query: this.$route.query.query || null,
|
|
|
|
};
|
|
|
|
},
|
2021-08-22 20:25:20 +00:00
|
|
|
watch: {
|
|
|
|
$route: resetQuery,
|
|
|
|
},
|
2021-08-21 22:40:22 +00:00
|
|
|
methods: {
|
|
|
|
search,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.search {
|
|
|
|
display: flex;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.query {
|
2021-08-21 23:26:09 +00:00
|
|
|
max-width: 40rem;
|
|
|
|
min-width: 10rem;
|
2021-08-21 22:40:22 +00:00
|
|
|
color: var(--text);
|
|
|
|
background: var(--background);
|
|
|
|
flex-grow: 1;
|
|
|
|
box-sizing: border-box;
|
|
|
|
padding: 1rem;
|
|
|
|
border: none;
|
|
|
|
box-sizing: border-box;
|
|
|
|
box-shadow: 0 0 3px var(--darken-weak);
|
|
|
|
font-size: 1rem;
|
|
|
|
outline: none;
|
|
|
|
|
|
|
|
&:focus {
|
|
|
|
box-shadow: 0 0 3px var(--primary);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.search-button {
|
|
|
|
padding: 1rem;
|
|
|
|
background: none;
|
|
|
|
border: none;
|
|
|
|
|
|
|
|
.icon {
|
|
|
|
fill: var(--shadow);
|
|
|
|
}
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
.icon {
|
|
|
|
fill: var(--primary);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|