2
0
mirror of https://github.com/frappe/books.git synced 2025-02-10 16:08:35 +00:00
books/src/components/DropdownWithActions.vue
18alantom d0fe62946c fix(ux): handle directory does not exist
- type DatabaseSelector
- fix dialog button width, varios types, injection
2023-04-04 22:10:32 -07:00

65 lines
1.4 KiB
Vue

<template>
<Dropdown
v-if="actions && actions.length"
class="text-xs"
:items="items"
:doc="doc"
right
>
<template v-slot="{ toggleDropdown }">
<Button :type="type" :icon="icon" @click="toggleDropdown()">
<slot>
<feather-icon name="more-horizontal" class="w-4 h-4" />
</slot>
</Button>
</template>
</Dropdown>
</template>
<script lang="ts">
import { Doc } from 'fyo/model/doc';
import { Action } from 'fyo/model/types';
import Button from 'src/components/Button.vue';
import Dropdown from 'src/components/Dropdown.vue';
import { DropdownItem } from 'src/utils/types';
import { defineComponent, PropType } from 'vue';
export default defineComponent({
name: 'DropdownWithActions',
props: {
actions: { type: Array as PropType<Action[]>, default: () => [] },
type: { type: String, default: 'secondary' },
icon: { type: Boolean, default: true },
},
inject: {
injectedDoc: {
from: 'doc',
default: undefined,
},
},
components: {
Dropdown,
Button,
},
computed: {
doc() {
// @ts-ignore
const doc = this.injectedDoc;
if (doc instanceof Doc) {
return doc;
}
return undefined;
},
items(): DropdownItem[] {
return this.actions.map(({ label, group, component, action }) => ({
label,
group,
action,
component,
}));
},
},
});
</script>