2022-04-08 18:07:31 -05:00
|
|
|
<template>
|
2023-06-11 11:12:52 -05:00
|
|
|
<modals-modal v-model="show" :width="width" height="100%">
|
2022-04-08 18:07:31 -05:00
|
|
|
<template #outer>
|
2023-11-02 16:10:55 -05:00
|
|
|
<div v-if="title" class="absolute top-10 left-4 z-40 pt-1 pb-1.5" style="max-width: 80%">
|
2023-02-26 14:41:18 -06:00
|
|
|
<p class="text-white text-xl truncate">{{ title }}</p>
|
2022-04-08 18:07:31 -05:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<div class="w-full h-full overflow-hidden absolute top-0 left-0 flex items-center justify-center" @click="show = false">
|
2023-12-10 17:53:27 -06:00
|
|
|
<div ref="container" class="w-full overflow-x-hidden overflow-y-auto bg-primary rounded-lg border border-fg/20 p-2" style="max-height: 75%" @click.stop>
|
2022-04-08 18:07:31 -05:00
|
|
|
<ul class="h-full w-full" role="listbox" aria-labelledby="listbox-label">
|
2023-06-11 11:12:52 -05:00
|
|
|
<template v-for="item in itemsToShow">
|
2022-08-22 16:02:35 -05:00
|
|
|
<slot :name="item.value" :item="item" :selected="item.value === selected">
|
2023-12-10 17:53:27 -06:00
|
|
|
<li :key="item.value" :ref="`item-${item.value}`" class="text-fg select-none relative cursor-pointer hover:bg-black-400" :class="selected === item.value ? 'bg-success bg-opacity-10' : ''" :style="{ paddingTop: itemPaddingY, paddingBottom: itemPaddingY }" role="option" @click="clickedOption(item.value)">
|
2022-08-22 16:02:35 -05:00
|
|
|
<div class="relative flex items-center px-3">
|
2023-12-10 17:53:27 -06:00
|
|
|
<span v-if="item.icon" class="material-icons-outlined text-xl mr-2 text-fg text-opacity-80">{{ item.icon }}</span>
|
|
|
|
<p class="font-normal block truncate text-base text-fg text-opacity-80">{{ item.text }}</p>
|
2022-08-22 16:02:35 -05:00
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</slot>
|
2022-04-08 18:07:31 -05:00
|
|
|
</template>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</modals-modal>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
value: Boolean,
|
|
|
|
title: String,
|
|
|
|
items: {
|
|
|
|
type: Array,
|
|
|
|
default: () => []
|
2022-06-01 19:38:26 -05:00
|
|
|
},
|
2023-06-11 11:12:52 -05:00
|
|
|
selected: [String, Number], // optional
|
|
|
|
itemPaddingY: {
|
|
|
|
type: String,
|
|
|
|
default: '16px'
|
|
|
|
},
|
|
|
|
width: {
|
|
|
|
type: Number,
|
|
|
|
default: 300
|
|
|
|
}
|
2022-04-08 18:07:31 -05:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {}
|
|
|
|
},
|
2023-06-11 11:12:52 -05:00
|
|
|
watch: {
|
|
|
|
show: {
|
|
|
|
immediate: true,
|
|
|
|
handler(newVal) {
|
|
|
|
if (newVal) this.$nextTick(this.init)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-04-08 18:07:31 -05:00
|
|
|
computed: {
|
|
|
|
show: {
|
|
|
|
get() {
|
|
|
|
return this.value
|
|
|
|
},
|
|
|
|
set(val) {
|
|
|
|
this.$emit('input', val)
|
|
|
|
}
|
2023-06-11 11:12:52 -05:00
|
|
|
},
|
|
|
|
itemsToShow() {
|
|
|
|
return this.items.map((i) => {
|
|
|
|
if (typeof i === 'string') {
|
|
|
|
return {
|
|
|
|
text: i,
|
|
|
|
value: i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
|
|
|
})
|
2022-04-08 18:07:31 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
clickedOption(action) {
|
|
|
|
this.$emit('action', action)
|
2023-06-11 11:12:52 -05:00
|
|
|
},
|
|
|
|
init() {
|
|
|
|
if (this.selected && this.$refs[`item-${this.selected}`]?.[0]) {
|
|
|
|
// Set scroll position so that selected item is in the center
|
|
|
|
const containerOffset = this.$refs.container.offsetTop + this.$refs.container.clientHeight / 2
|
|
|
|
const scrollAmount = this.$refs[`item-${this.selected}`][0].offsetTop - containerOffset
|
|
|
|
this.$refs.container.scrollTo({
|
|
|
|
top: scrollAmount
|
|
|
|
})
|
|
|
|
}
|
2022-04-08 18:07:31 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {}
|
|
|
|
}
|
|
|
|
</script>
|