Hangar/frontend/components/layouts/Dropdown.vue

51 lines
1.5 KiB
Vue
Raw Normal View History

<template>
<v-list dense>
<slot name="pre" />
2021-02-07 13:44:53 +08:00
<template v-for="(control, index) in controls">
<v-list-item
v-if="!control.isDivider"
:key="control.title"
link
:to="isRouterLink(control) ? control.link : null"
:nuxt="isRouterLink(control)"
:href="isRouterLink(control) ? null : control.link"
2021-02-08 06:06:06 +08:00
exact
2021-02-07 13:44:53 +08:00
@click="control.action ? control.action() : null"
>
<v-list-item-icon>
<v-icon color="white">{{ control.icon }}</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>{{ control.title }}</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-divider v-else :key="index" class="my-2" />
</template>
<slot name="post" />
</v-list>
</template>
<script lang="ts">
import { Component, Prop, Vue } from 'nuxt-property-decorator';
import { PropType } from 'vue';
2021-01-23 06:36:52 +08:00
import { TranslateResult } from 'vue-i18n';
export interface Control {
2021-02-07 13:44:53 +08:00
icon?: String;
title?: String | TranslateResult;
2021-01-22 11:11:24 +08:00
link?: String;
action?: Function;
2021-02-07 13:44:53 +08:00
isDivider?: boolean;
}
@Component
2021-01-24 04:27:15 +08:00
export default class Dropdown extends Vue {
@Prop({ type: Array as PropType<Control[]>, required: true })
2021-01-22 07:08:06 +08:00
controls!: Control[];
isRouterLink(control: Control): Boolean {
2021-01-22 11:11:24 +08:00
return !!control.link && control.link.startsWith('/');
}
}
</script>