2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
2022-10-13 15:18:47 +00:00
|
|
|
<form id="searchForm" role="search" @submit.prevent="onSubmit">
|
2022-10-24 16:43:05 +00:00
|
|
|
<span class="icon">
|
|
|
|
<icon :icon="faSearch"/>
|
|
|
|
</span>
|
|
|
|
|
2022-04-15 14:24:30 +00:00
|
|
|
<input
|
2022-04-24 20:23:20 +00:00
|
|
|
ref="input"
|
|
|
|
v-model="q"
|
2022-04-15 14:24:30 +00:00
|
|
|
:class="{ dirty: q }"
|
2022-10-24 11:04:25 +00:00
|
|
|
:placeholder="placeholder"
|
2022-04-15 14:24:30 +00:00
|
|
|
autocorrect="false"
|
2022-04-24 20:23:20 +00:00
|
|
|
name="q"
|
2022-10-24 11:04:25 +00:00
|
|
|
required
|
2022-04-15 14:24:30 +00:00
|
|
|
spellcheck="false"
|
2022-04-24 20:23:20 +00:00
|
|
|
type="search"
|
2022-10-13 15:18:47 +00:00
|
|
|
@focus="maybeGoToSearchScreen"
|
2022-04-24 20:23:20 +00:00
|
|
|
@input="onInput"
|
2022-04-15 14:24:30 +00:00
|
|
|
>
|
2022-10-24 16:43:05 +00:00
|
|
|
|
2022-10-13 15:18:47 +00:00
|
|
|
<button type="submit" title="Search">
|
|
|
|
<icon :icon="faSearch"/>
|
|
|
|
</button>
|
|
|
|
</form>
|
2022-04-15 14:24:30 +00:00
|
|
|
</template>
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
<script lang="ts" setup>
|
2022-10-13 15:18:47 +00:00
|
|
|
import isMobile from 'ismobilejs'
|
|
|
|
import { faSearch } from '@fortawesome/free-solid-svg-icons'
|
2022-04-15 17:00:08 +00:00
|
|
|
import { ref } from 'vue'
|
2022-04-15 14:24:30 +00:00
|
|
|
import { debounce } from 'lodash'
|
2022-10-08 10:54:25 +00:00
|
|
|
import { eventBus, requireInjection } from '@/utils'
|
|
|
|
import { RouterKey } from '@/symbols'
|
|
|
|
|
2022-10-13 15:18:47 +00:00
|
|
|
const placeholder = isMobile.any ? 'Search' : 'Press F to search'
|
|
|
|
|
2022-10-08 10:54:25 +00:00
|
|
|
const router = requireInjection(RouterKey)
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-24 20:23:20 +00:00
|
|
|
const input = ref<HTMLInputElement>()
|
2022-04-15 17:00:08 +00:00
|
|
|
const q = ref('')
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-05-15 20:44:19 +00:00
|
|
|
let onInput = () => {
|
2022-04-15 17:00:08 +00:00
|
|
|
const _q = q.value.trim()
|
|
|
|
_q && eventBus.emit('SEARCH_KEYWORDS_CHANGED', _q)
|
2022-05-15 20:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (process.env.NODE_ENV !== 'test') {
|
|
|
|
onInput = debounce(onInput, 500)
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-10-13 15:18:47 +00:00
|
|
|
const onSubmit = () => {
|
|
|
|
eventBus.emit('TOGGLE_SIDEBAR')
|
2022-10-24 11:04:25 +00:00
|
|
|
router.go('search')
|
2022-10-13 15:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const maybeGoToSearchScreen = () => isMobile.any || router.go('search')
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
eventBus.on({
|
2022-09-12 11:11:56 +00:00
|
|
|
FOCUS_SEARCH_FIELD: () => {
|
2022-04-24 20:23:20 +00:00
|
|
|
input.value?.focus()
|
|
|
|
input.value?.select()
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
#searchForm {
|
2022-10-13 15:18:47 +00:00
|
|
|
display: flex;
|
|
|
|
align-items: stretch;
|
|
|
|
color: var(--color-text-secondary);
|
2022-10-24 16:43:05 +00:00
|
|
|
background: rgba(0, 0, 0, .2);
|
2022-10-13 15:18:47 +00:00
|
|
|
border: 1px solid transparent;
|
|
|
|
border-radius: 5px;
|
2022-10-24 16:43:05 +00:00
|
|
|
transition: border .3s ease-in-out, .3s background-color ease-in-out;
|
2022-10-13 15:18:47 +00:00
|
|
|
overflow: hidden;
|
2022-10-24 16:43:05 +00:00
|
|
|
padding: 0 0 0 1rem;
|
|
|
|
gap: .5rem;
|
|
|
|
|
|
|
|
.icon {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
opacity: .7;
|
|
|
|
|
|
|
|
@media screen and (max-width: 768px) {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-10-13 15:18:47 +00:00
|
|
|
button {
|
|
|
|
display: none;
|
2022-10-24 16:43:05 +00:00
|
|
|
padding: 0 1.2rem;
|
2022-10-13 15:18:47 +00:00
|
|
|
background: rgba(255, 255, 255, .05);
|
|
|
|
border-radius: 0;
|
|
|
|
|
|
|
|
@media screen and (max-width: 768px) {
|
|
|
|
display: block;
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
2022-10-13 15:18:47 +00:00
|
|
|
&:focus-within {
|
|
|
|
border: 1px solid rgba(255, 255, 255, .2);
|
2022-10-24 16:43:05 +00:00
|
|
|
background: rgba(0, 0, 0, .5);
|
2022-10-13 15:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
input[type="search"] {
|
2022-04-15 14:24:30 +00:00
|
|
|
width: 100%;
|
2022-10-13 15:18:47 +00:00
|
|
|
border-radius: 0;
|
|
|
|
height: 36px;
|
|
|
|
color: var(--color-text-primary);
|
2022-10-24 16:43:05 +00:00
|
|
|
background-color: transparent;
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-10-13 15:18:47 +00:00
|
|
|
&::placeholder {
|
|
|
|
color: rgba(255, 255, 255, .5);
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|