funkwhale/front/src/components/common/InlineSearchBar.vue

69 wiersze
1.5 KiB
Vue
Czysty Zwykły widok Historia

2022-05-02 08:25:37 +00:00
<script setup lang="ts">
import { useVModel } from '@vueuse/core'
import { computed } from 'vue'
import { useGettext } from 'vue3-gettext'
2022-08-30 20:23:17 +00:00
interface Events {
(e: 'update:modelValue', value: string): void
(e: 'search', query: string): void
}
2022-05-02 08:25:37 +00:00
interface Props {
modelValue: string
placeholder?: string
}
2022-08-30 20:23:17 +00:00
const emit = defineEmits<Events>()
2022-05-02 08:25:37 +00:00
const props = withDefaults(defineProps<Props>(), {
placeholder: ''
})
const value = useVModel(props, 'modelValue', emit)
const { $pgettext } = useGettext()
const labels = computed(() => ({
searchPlaceholder: $pgettext('Content/Search/Input.Placeholder', 'Search…'),
clear: $pgettext('Content/Library/Button.Label', 'Clear')
}))
const search = () => {
value.value = ''
emit('search', value.value)
}
</script>
<template>
2021-12-06 10:35:20 +00:00
<form
class="ui inline form"
2022-05-02 08:25:37 +00:00
@submit.stop.prevent="emit('search', value)"
2021-12-06 10:35:20 +00:00
>
2022-05-02 08:25:37 +00:00
<div :class="['ui', 'action', {icon: value}, 'input']">
2021-12-06 10:35:20 +00:00
<label
for="search-query"
class="hidden"
>
<translate translate-context="Content/Search/Input.Label/Noun">Search</translate>
</label>
2021-12-06 10:35:20 +00:00
<input
id="search-query"
2022-05-02 08:25:37 +00:00
v-model="value"
2021-12-06 10:35:20 +00:00
name="search-query"
type="text"
:placeholder="placeholder || labels.searchPlaceholder"
>
<i
2022-05-02 08:25:37 +00:00
v-if="value"
2021-12-06 10:35:20 +00:00
class="x link icon"
:title="labels.clear"
2022-05-02 08:25:37 +00:00
@click.stop.prevent="search"
2021-12-06 10:35:20 +00:00
/>
<button
type="submit"
class="ui icon basic button"
>
<i class="search icon" />
</button>
</div>
</form>
</template>