Hangar/frontend/components/layouts/Dropdown.vue

56 lines
1.8 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 : undefined"
2021-02-07 13:44:53 +08:00
:nuxt="isRouterLink(control)"
:href="isRouterLink(control) ? undefined : control.link"
2021-02-08 06:06:06 +08:00
exact
@click="control.action ? control.action() : undefined"
2021-02-07 13:44:53 +08:00
>
<v-list-item-icon>
<v-badge v-if="control.badge" offset-y="7" offset-x="7" left :content="control.badgeContent" :value="control.badgeContent">
<v-icon color="white">{{ control.icon }}</v-icon>
</v-badge>
<v-icon v-else color="white">{{ control.icon }}</v-icon>
2021-02-07 13:44:53 +08:00
</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 {
icon?: string;
title?: TranslateResult;
badge?: boolean;
badgeContent?: any;
link?: string;
2021-01-22 11:11:24 +08:00
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>