|
| 1 | +<script setup lang="ts"> |
| 2 | +import { ref, computed } from 'vue'; |
| 3 | +import type { AppTopSubBarItem, BreadcrumbItemType } from '@/types'; |
| 4 | +import Breadcrumbs from '@/components/Breadcrumbs.vue'; |
| 5 | +import { Link } from "@inertiajs/vue3"; |
| 6 | +
|
| 7 | +interface Props { |
| 8 | + breadcrumbs?: BreadcrumbItemType[]; |
| 9 | + actions?: AppTopSubBarItem[]; |
| 10 | +} |
| 11 | +
|
| 12 | +const props = withDefaults(defineProps<Props>(), { |
| 13 | + breadcrumbs: () => [], |
| 14 | + actions: () => [], |
| 15 | +}); |
| 16 | +
|
| 17 | +const mobileMenuRef = ref() |
| 18 | +
|
| 19 | +const mobileMenuItems = computed(() => |
| 20 | + props.actions.map(action => ({ |
| 21 | + label: action.title, |
| 22 | + icon: action.icon, |
| 23 | + route: action.route, |
| 24 | + url: action.url, |
| 25 | + target: action.target, |
| 26 | + command: action.command |
| 27 | + })) |
| 28 | +) |
| 29 | +
|
| 30 | +console.log(props.actions) |
| 31 | +
|
| 32 | +const toggleMobileMenu = (event) => { |
| 33 | + mobileMenuRef.value.toggle(event) |
| 34 | +} |
| 35 | +
|
| 36 | +</script> |
| 37 | + |
| 38 | +<template> |
| 39 | + <div class="layout-sub-topbar"> |
| 40 | + <div class="layout-sub-topbar-content" :class="{ |
| 41 | + 'justify-end': breadcrumbs.length === 0, |
| 42 | + 'justify-between': breadcrumbs.length > 0 |
| 43 | + }"> |
| 44 | + <div class="layout-sub-topbar-breadcrumbs"> |
| 45 | + <Breadcrumbs :breadcrumbs="breadcrumbs" /> |
| 46 | + <div v-if="breadcrumbs.length === 0" class="p-[1.58rem]"></div> |
| 47 | + </div> |
| 48 | + <div v-if="actions?.length" class="layout-sub-topbar-actions hidden lg:flex space-x-2"> |
| 49 | + <template v-for="(action, index) in actions" :key="index"> |
| 50 | + <Button |
| 51 | + v-if="action.route" |
| 52 | + :key="`btn-route-${index}`" |
| 53 | + asChild |
| 54 | + v-slot="slotProps" |
| 55 | + class="inline-block" |
| 56 | + severity="secondary" |
| 57 | + > |
| 58 | + <Link :href="action.route" :class="slotProps.class"> |
| 59 | + <span v-if="action.icon" :class="action.icon" /> |
| 60 | + {{ action.title }} |
| 61 | + </Link> |
| 62 | + </Button> |
| 63 | + <Button |
| 64 | + v-else-if="action.url" |
| 65 | + :key="`btn-url-${index}`" |
| 66 | + as="a" |
| 67 | + :label="action.title" |
| 68 | + :icon="action.icon" |
| 69 | + :href="action.url" |
| 70 | + :target="action.target || '_self'" |
| 71 | + severity="secondary" |
| 72 | + /> |
| 73 | + <Button |
| 74 | + v-else |
| 75 | + :key="`btn-command-${index}`" |
| 76 | + :label="action.title" |
| 77 | + :icon="action.icon" |
| 78 | + @click="action.command" |
| 79 | + severity="secondary" |
| 80 | + /> |
| 81 | + </template> |
| 82 | + </div> |
| 83 | + <div class="lg:hidden"> |
| 84 | + <Button |
| 85 | + severity="secondary" |
| 86 | + icon="pi pi-ellipsis-v" |
| 87 | + @click="toggleMobileMenu" |
| 88 | + text |
| 89 | + /> |
| 90 | + <Menu |
| 91 | + ref="mobileMenuRef" |
| 92 | + :model="mobileMenuItems" |
| 93 | + popup |
| 94 | + > |
| 95 | + <template #item="{ item, props }"> |
| 96 | + <Link v-if="item.route" :href="item.route" v-bind="props.action"> |
| 97 | + <span v-if="item.icon" :class="item.icon" /> |
| 98 | + <span>{{ item.label }}</span> |
| 99 | + </Link> |
| 100 | + <a v-else :href="item.url" class="flex items-center" :target="item.target" v-bind="props.action"> |
| 101 | + <span v-if="item.icon" :class="item.icon" /> |
| 102 | + <span>{{ item.label }}</span> |
| 103 | + </a> |
| 104 | + </template> |
| 105 | + </Menu> |
| 106 | + </div> |
| 107 | + |
| 108 | + </div> |
| 109 | + </div> |
| 110 | +</template> |
| 111 | + |
0 commit comments