2022-04-13 01:07:13 +02:00
|
|
|
<template>
|
|
|
|
<div ref="wrapper" class="relative" v-click-outside="clickOutside">
|
2023-06-10 22:46:12 +02:00
|
|
|
<button type="button" class="relative w-full h-full border border-gray-500 hover:border-gray-400 rounded shadow-sm pl-3 pr-3 py-0 text-left focus:outline-none cursor-pointer" aria-haspopup="listbox" aria-expanded="true" aria-labelledby="listbox-label" @click.prevent="showMenu = !showMenu">
|
2022-04-13 01:07:13 +02:00
|
|
|
<span class="flex items-center justify-between">
|
|
|
|
<span class="block truncate text-xs" :class="!selectedText ? 'text-gray-300' : ''">{{ selectedText }}</span>
|
|
|
|
<span class="material-icons text-lg text-yellow-400">{{ descending ? 'expand_more' : 'expand_less' }}</span>
|
|
|
|
</span>
|
|
|
|
</button>
|
|
|
|
|
2023-06-10 22:46:12 +02:00
|
|
|
<ul v-show="showMenu" class="absolute z-10 mt-1 w-full bg-bg border border-black-200 shadow-lg max-h-80 rounded-md py-1 ring-1 ring-black ring-opacity-5 overflow-auto focus:outline-none text-sm" role="listbox" aria-labelledby="listbox-label">
|
2022-04-13 01:07:13 +02:00
|
|
|
<template v-for="item in items">
|
2023-06-10 22:46:12 +02:00
|
|
|
<li :key="item.value" class="select-none relative py-2 pr-9 cursor-pointer hover:bg-white/5" :class="item.value === selected ? 'bg-white/5 text-yellow-400' : 'text-gray-200 hover:text-white'" role="option" @click="clickedOption(item.value)">
|
2022-04-13 01:07:13 +02:00
|
|
|
<div class="flex items-center">
|
2023-06-10 22:46:12 +02:00
|
|
|
<span class="font-normal ml-3 block truncate">{{ item.text }}</span>
|
2022-04-13 01:07:13 +02:00
|
|
|
</div>
|
|
|
|
<span v-if="item.value === selected" class="text-yellow-400 absolute inset-y-0 right-0 flex items-center pr-4">
|
|
|
|
<span class="material-icons text-xl">{{ descending ? 'expand_more' : 'expand_less' }}</span>
|
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
</template>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
value: String,
|
2022-10-29 01:10:19 +02:00
|
|
|
descending: Boolean,
|
|
|
|
items: {
|
|
|
|
type: Array,
|
|
|
|
default: () => []
|
|
|
|
}
|
2022-04-13 01:07:13 +02:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2022-10-29 01:10:19 +02:00
|
|
|
showMenu: false
|
2022-04-13 01:07:13 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
selected: {
|
|
|
|
get() {
|
|
|
|
return this.value
|
|
|
|
},
|
|
|
|
set(val) {
|
|
|
|
this.$emit('input', val)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
selectedDesc: {
|
|
|
|
get() {
|
|
|
|
return this.descending
|
|
|
|
},
|
|
|
|
set(val) {
|
|
|
|
this.$emit('update:descending', val)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
selectedText() {
|
|
|
|
var _selected = this.selected
|
|
|
|
if (!_selected) return ''
|
|
|
|
var _sel = this.items.find((i) => i.value === _selected)
|
|
|
|
if (!_sel) return ''
|
|
|
|
return _sel.text
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
clickOutside() {
|
|
|
|
this.showMenu = false
|
|
|
|
},
|
|
|
|
clickedOption(val) {
|
|
|
|
if (this.selected === val) {
|
|
|
|
this.selectedDesc = !this.selectedDesc
|
|
|
|
} else {
|
|
|
|
this.selected = val
|
|
|
|
}
|
|
|
|
this.showMenu = false
|
|
|
|
this.$nextTick(() => this.$emit('change', val))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|