RuralDatabase/apps/web/components/common/table/DataTableRowActions.vue

56 lines
1.8 KiB
Vue
Raw Normal View History

2024-07-05 02:07:18 +08:00
<script setup lang="ts" generic="Task extends { [key: string]: any;}">
2024-06-30 21:39:37 +08:00
import type { Row } from '@tanstack/vue-table'
interface DataTableRowActionsProps {
row: Row<Task>
2024-07-05 02:07:18 +08:00
menus: {
label: string
divider?: boolean
icon?: string
click: (row: Row<Task>) => void
child?: {
label: string
icon?: string
click: (row: Row<Task>) => void
}[]
}[]
2024-06-30 21:39:37 +08:00
}
2024-07-05 02:07:18 +08:00
defineProps<DataTableRowActionsProps>()
2024-06-30 21:39:37 +08:00
</script>
<template>
<DropdownMenu>
<DropdownMenuTrigger as-child>
<Button
variant="ghost"
class="flex h-8 w-8 p-0 data-[state=open]:bg-muted"
>
2024-07-05 02:07:18 +08:00
<Iconify icon="ph:dots-three-outline-fill" class="w-4 h-4" />
2024-06-30 21:39:37 +08:00
<span class="sr-only">Open menu</span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" class="w-[160px]">
2024-07-05 02:07:18 +08:00
<template v-for="menu in menus" :key="menu.label">
<DropdownMenuSeparator v-if="menu.divider" />
<DropdownMenuSub v-else-if="(menu?.child?.length ?? 0) > 0" :label="menu.label">
<DropdownMenuSubTrigger>{{ menu.label }}</DropdownMenuSubTrigger>
<DropdownMenuSubContent>
<DropdownMenuItem v-for="child in menu.child" :key="child.label" @click="child.click(row)">
{{ child.label }}
<DropdownMenuShortcut>
<Iconify :icon="child.icon" class="size-4" />
</DropdownMenuShortcut>
</DropdownMenuItem>
</DropdownMenuSubContent>
</DropdownMenuSub>
<DropdownMenuItem v-else @click="menu.click(row)">
{{ menu.label }}
<DropdownMenuShortcut>
<Iconify :icon="menu.icon" class="size-4" />
</DropdownMenuShortcut>
</DropdownMenuItem>
</template>
2024-06-30 21:39:37 +08:00
</DropdownMenuContent>
</DropdownMenu>
</template>