2021-10-17 00:06:13 +00:00
|
|
|
<template>
|
|
|
|
<v-menu offset-y>
|
|
|
|
<template #activator="{ on, attrs }">
|
2021-10-19 03:41:41 +00:00
|
|
|
<v-btn color="primary" v-bind="attrs" :class="btnClass" :disabled="disabled" v-on="on">
|
2021-10-17 00:06:13 +00:00
|
|
|
<v-icon v-if="activeObj.icon" left>
|
|
|
|
{{ activeObj.icon }}
|
|
|
|
</v-icon>
|
2021-10-19 03:41:41 +00:00
|
|
|
{{ mode === MODES.model ? activeObj.text : btnText }}
|
2021-10-17 00:06:13 +00:00
|
|
|
<v-icon right>
|
|
|
|
{{ $globals.icons.chevronDown }}
|
|
|
|
</v-icon>
|
|
|
|
</v-btn>
|
|
|
|
</template>
|
2021-10-19 03:41:41 +00:00
|
|
|
<!-- Model -->
|
|
|
|
<v-list v-if="mode === MODES.model" dense>
|
2021-10-17 00:06:13 +00:00
|
|
|
<v-list-item-group v-model="itemGroup">
|
|
|
|
<v-list-item v-for="(item, index) in items" :key="index" @click="setValue(item)">
|
|
|
|
<v-list-item-icon v-if="item.icon">
|
|
|
|
<v-icon>{{ item.icon }}</v-icon>
|
|
|
|
</v-list-item-icon>
|
|
|
|
<v-list-item-title>{{ item.text }}</v-list-item-title>
|
|
|
|
</v-list-item>
|
|
|
|
</v-list-item-group>
|
|
|
|
</v-list>
|
2021-10-19 03:41:41 +00:00
|
|
|
<!-- Event -->
|
|
|
|
<v-list v-else-if="mode === MODES.link" dense>
|
|
|
|
<v-list-item-group v-model="itemGroup">
|
|
|
|
<v-list-item v-for="(item, index) in items" :key="index" :to="item.to">
|
|
|
|
<v-list-item-icon v-if="item.icon">
|
|
|
|
<v-icon>{{ item.icon }}</v-icon>
|
|
|
|
</v-list-item-icon>
|
|
|
|
<v-list-item-title>{{ item.text }}</v-list-item-title>
|
|
|
|
</v-list-item>
|
|
|
|
</v-list-item-group>
|
|
|
|
</v-list>
|
|
|
|
<!-- Event -->
|
|
|
|
<v-list v-else-if="mode === MODES.event" dense>
|
|
|
|
<v-list-item v-for="(item, index) in items" :key="index" @click="$emit(item.event)">
|
|
|
|
<v-list-item-icon v-if="item.icon">
|
|
|
|
<v-icon>{{ item.icon }}</v-icon>
|
|
|
|
</v-list-item-icon>
|
|
|
|
<v-list-item-title>{{ item.text }}</v-list-item-title>
|
|
|
|
</v-list-item>
|
|
|
|
</v-list>
|
2021-10-17 00:06:13 +00:00
|
|
|
</v-menu>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { defineComponent, ref } from "@nuxtjs/composition-api";
|
|
|
|
|
|
|
|
const INPUT_EVENT = "input";
|
|
|
|
|
2021-10-19 03:41:41 +00:00
|
|
|
type modes = "model" | "link" | "event";
|
|
|
|
|
|
|
|
const MODES = {
|
|
|
|
model: "model",
|
|
|
|
link: "link",
|
|
|
|
event: "event",
|
|
|
|
};
|
|
|
|
|
2021-10-17 00:06:13 +00:00
|
|
|
export default defineComponent({
|
|
|
|
props: {
|
2021-10-19 03:41:41 +00:00
|
|
|
mode: {
|
|
|
|
type: String as () => modes,
|
|
|
|
default: "model",
|
|
|
|
},
|
2021-10-17 00:06:13 +00:00
|
|
|
items: {
|
|
|
|
type: Array,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-10-19 03:41:41 +00:00
|
|
|
disabled: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
},
|
2021-10-17 00:06:13 +00:00
|
|
|
value: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: "",
|
|
|
|
},
|
|
|
|
btnClass: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: "",
|
|
|
|
},
|
2021-10-19 03:41:41 +00:00
|
|
|
btnText: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: "Actions",
|
|
|
|
},
|
2021-10-17 00:06:13 +00:00
|
|
|
},
|
|
|
|
setup(props, context) {
|
|
|
|
const activeObj = ref({
|
|
|
|
text: "DEFAULT",
|
|
|
|
value: "",
|
|
|
|
});
|
|
|
|
|
|
|
|
let startIndex = 0;
|
|
|
|
props.items.forEach((item, index) => {
|
|
|
|
// @ts-ignore
|
|
|
|
if (item.value === props.value) {
|
|
|
|
startIndex = index;
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
activeObj.value = item;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const itemGroup = ref(startIndex);
|
|
|
|
|
|
|
|
function setValue(v: any) {
|
|
|
|
context.emit(INPUT_EVENT, v.value);
|
|
|
|
activeObj.value = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2021-10-19 03:41:41 +00:00
|
|
|
MODES,
|
2021-10-17 00:06:13 +00:00
|
|
|
activeObj,
|
|
|
|
itemGroup,
|
|
|
|
setValue,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|