2022-11-25 13:21:02 +00:00
|
|
|
<script setup lang="ts">
|
2022-11-26 06:55:54 +00:00
|
|
|
import type { Account } from 'masto'
|
|
|
|
|
2022-11-25 13:21:02 +00:00
|
|
|
const { items, command } = defineProps<{
|
2022-11-26 06:55:54 +00:00
|
|
|
items: Account[]
|
2022-11-25 13:21:02 +00:00
|
|
|
command: Function
|
|
|
|
}>()
|
|
|
|
|
|
|
|
let selectedIndex = $ref(0)
|
|
|
|
|
|
|
|
watch(items, () => {
|
|
|
|
selectedIndex = 0
|
|
|
|
})
|
|
|
|
|
|
|
|
function onKeyDown(event: KeyboardEvent) {
|
|
|
|
if (event.key === 'ArrowUp') {
|
|
|
|
selectedIndex = ((selectedIndex + items.length) - 1) % items.length
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
else if (event.key === 'ArrowDown') {
|
|
|
|
selectedIndex = (selectedIndex + 1) % items.length
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
else if (event.key === 'Enter') {
|
|
|
|
selectItem(selectedIndex)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
function selectItem(index: number) {
|
|
|
|
const item = items[index]
|
|
|
|
if (item)
|
2022-11-26 06:55:54 +00:00
|
|
|
command({ id: item.acct })
|
2022-11-25 13:21:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
defineExpose({
|
|
|
|
onKeyDown,
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-11-26 06:55:54 +00:00
|
|
|
<div relative bg-base text-base shadow border="~ base rounded" text-sm py-2 overflow-x-hidden overflow-y-auto max-h-100>
|
2022-11-25 13:21:02 +00:00
|
|
|
<template v-if="items.length">
|
|
|
|
<button
|
|
|
|
v-for="(item, index) in items"
|
|
|
|
:key="index"
|
2022-11-26 20:41:18 +00:00
|
|
|
:class="index === selectedIndex ? 'bg-active' : 'text-secondary'"
|
2022-11-25 13:21:02 +00:00
|
|
|
block m0 w-full text-left px2 py1
|
|
|
|
@click="selectItem(index)"
|
|
|
|
>
|
2022-11-26 06:55:54 +00:00
|
|
|
<AccountInfo :link="false" :account="item" />
|
2022-11-25 13:21:02 +00:00
|
|
|
</button>
|
|
|
|
</template>
|
|
|
|
<div v-else block m0 w-full text-left px2 py1 italic op30>
|
|
|
|
No result
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|