|
1 | 1 | <script setup lang="ts"> |
2 | | -const query = defineModel<string>(); |
| 2 | +import { useRouter } from "vue-router"; |
| 3 | +import type { MaintainersCollectionItem } from "@nuxt/content"; |
3 | 4 |
|
4 | | -const inputRef = ref<HTMLInputElement | null>(null); |
5 | | -defineExpose({ focus: () => inputRef.value?.focus?.() }); |
| 5 | +const props = defineProps<{ |
| 6 | + modelValue: string; |
| 7 | + maintainers?: MaintainersCollectionItem[]; |
| 8 | + placeholder?: string; |
| 9 | +}>(); |
| 10 | +
|
| 11 | +const emit = defineEmits(["update:modelValue"]); |
| 12 | +
|
| 13 | +const router = useRouter(); |
| 14 | +
|
| 15 | +const goToRandomMaintainer = () => { |
| 16 | + const list = props.maintainers || []; |
| 17 | + if (list.length === 0) return; |
| 18 | +
|
| 19 | + const randomIndex = Math.floor(Math.random() * list.length); |
| 20 | + const randomMaintainer = list[randomIndex]; |
| 21 | +
|
| 22 | + if (randomMaintainer.path) { |
| 23 | + router.push(randomMaintainer.path); |
| 24 | + } else { |
| 25 | + console.warn("Missing path in random maintainer", randomMaintainer); |
| 26 | + } |
| 27 | +}; |
6 | 28 | </script> |
| 29 | + |
7 | 30 | <template> |
8 | | - <div |
9 | | - class="flex items-center px-4 py-2 gap-4 border has-focus:outline-1 transition-all duration-300 ease-linear" |
10 | | - > |
11 | | - <IconsSearch class="w-4 h-4" /> |
12 | | - <input |
13 | | - ref="inputRef" |
14 | | - v-model="query" |
15 | | - type="text" |
16 | | - placeholder="Search" |
17 | | - class="input w-full dark:placeholder:text-secondary-dark placeholder:text-secondary-light text-sm focus:outline-none" |
18 | | - /> |
19 | | - <span class="text-xs border rounded px-2 hidden md:inline-block opacity-50"> |
20 | | - ctrl+k |
21 | | - </span> |
| 31 | + <div class="grid grid-cols-1 sm:grid-cols-[1fr_auto] gap-2 items-center"> |
| 32 | + <div class="flex items-center px-4 py-2 gap-4 border transition-all"> |
| 33 | + <IconsSearch class="w-4 h-4" /> |
| 34 | + <input |
| 35 | + :value="modelValue" |
| 36 | + @input="emit('update:modelValue', $event.target.value)" |
| 37 | + type="text" |
| 38 | + :placeholder="placeholder || 'Search'" |
| 39 | + class="input w-full dark:placeholder:text-secondary-dark placeholder:text-secondary-light text-sm focus:outline-none" |
| 40 | + /> |
| 41 | + <span |
| 42 | + class="text-xs border rounded px-2 hidden md:inline-block opacity-50" |
| 43 | + > |
| 44 | + ctrl+k |
| 45 | + </span> |
| 46 | + </div> |
| 47 | + |
| 48 | + <button |
| 49 | + @click="goToRandomMaintainer" |
| 50 | + class="ml-2 flex text-sm gap-2 items-center btn-subtle w-fit" |
| 51 | + > |
| 52 | + Surprise Me! |
| 53 | + </button> |
22 | 54 | </div> |
23 | 55 | </template> |
0 commit comments