2022-03-04 02:03:34 +01:00
|
|
|
<template>
|
|
|
|
<div class="relative w-full h-9" v-click-outside="clickOutsideObj">
|
|
|
|
<p class="text-sm font-semibold">{{ label }}</p>
|
|
|
|
|
|
|
|
<button type="button" :disabled="disabled" class="relative h-full w-full border border-gray-600 rounded shadow-sm pl-3 pr-3 text-left focus:outline-none cursor-pointer bg-primary text-gray-100 hover:text-gray-200" aria-haspopup="listbox" aria-expanded="true" @click.stop.prevent="clickShowMenu">
|
|
|
|
<span class="flex items-center">
|
2022-03-18 23:09:17 +01:00
|
|
|
<widgets-library-icon :icon="selected" />
|
2022-03-04 02:03:34 +01:00
|
|
|
</span>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<transition name="menu">
|
|
|
|
<ul v-show="showMenu" class="absolute z-10 -mt-px w-full bg-primary border border-black-200 shadow-lg max-h-56 rounded-b-md py-1 ring-1 ring-black ring-opacity-5 overflow-auto focus:outline-none sm:text-sm" tabindex="-1" role="listbox">
|
|
|
|
<template v-for="type in types">
|
2022-03-18 23:09:17 +01:00
|
|
|
<li :key="type.id" class="text-gray-100 select-none relative py-2 cursor-pointer hover:bg-black-400 flex justify-center" id="listbox-option-0" role="option" @click="select(type)">
|
|
|
|
<widgets-library-icon :icon="type.id" />
|
2022-03-04 02:03:34 +01:00
|
|
|
</li>
|
|
|
|
</template>
|
|
|
|
</ul>
|
|
|
|
</transition>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
value: String,
|
|
|
|
disabled: Boolean,
|
|
|
|
label: {
|
|
|
|
type: String,
|
2022-03-18 23:09:17 +01:00
|
|
|
default: 'Icon'
|
2022-03-04 02:03:34 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
clickOutsideObj: {
|
|
|
|
handler: this.clickedOutside,
|
|
|
|
events: ['mousedown'],
|
|
|
|
isActive: true
|
|
|
|
},
|
|
|
|
showMenu: false,
|
|
|
|
types: [
|
|
|
|
{
|
2022-04-15 00:15:52 +02:00
|
|
|
id: 'database',
|
|
|
|
name: 'Database'
|
2022-03-04 02:03:34 +01:00
|
|
|
},
|
|
|
|
{
|
2022-03-14 15:56:24 +01:00
|
|
|
id: 'audiobook',
|
2022-03-04 02:03:34 +01:00
|
|
|
name: 'Audiobooks'
|
|
|
|
},
|
|
|
|
{
|
2022-03-14 15:56:24 +01:00
|
|
|
id: 'book',
|
2022-03-04 02:03:34 +01:00
|
|
|
name: 'Books'
|
|
|
|
},
|
|
|
|
{
|
2022-03-14 15:56:24 +01:00
|
|
|
id: 'podcast',
|
2022-03-04 02:03:34 +01:00
|
|
|
name: 'Podcasts'
|
|
|
|
},
|
|
|
|
{
|
2022-03-14 15:56:24 +01:00
|
|
|
id: 'comic',
|
2022-03-04 02:03:34 +01:00
|
|
|
name: 'Comics'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
selected: {
|
|
|
|
get() {
|
2022-04-15 00:15:52 +02:00
|
|
|
return this.value || 'database'
|
2022-03-04 02:03:34 +01:00
|
|
|
},
|
|
|
|
set(val) {
|
|
|
|
this.$emit('input', val)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
selectedItem() {
|
|
|
|
return this.types.find((t) => t.id === this.selected)
|
|
|
|
},
|
|
|
|
selectedName() {
|
2022-04-15 00:15:52 +02:00
|
|
|
return this.selectedItem ? this.selectedItem.name : 'Database'
|
2022-03-04 02:03:34 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
clickShowMenu() {
|
|
|
|
if (this.disabled) return
|
|
|
|
this.showMenu = !this.showMenu
|
|
|
|
},
|
|
|
|
clickedOutside() {
|
|
|
|
this.showMenu = false
|
|
|
|
},
|
|
|
|
select(type) {
|
|
|
|
if (this.disabled) return
|
|
|
|
this.selected = type.id
|
|
|
|
this.showMenu = false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {}
|
|
|
|
}
|
|
|
|
</script>
|