Refactor #3832 Refactor #3833 - For TieredMenu

pull/3841/head
Tuğçe Küçükoğlu 2023-04-05 14:57:18 +03:00
parent 27c4bbec31
commit 058fa9673b
4 changed files with 24 additions and 5 deletions

View File

@ -41,6 +41,10 @@ const TieredMenuSlots = [
{ {
name: 'item', name: 'item',
description: 'Template of a menuitem.' description: 'Template of a menuitem.'
},
{
name: 'submenuicon',
description: 'Custom submenu icon template.'
} }
]; ];

View File

@ -77,6 +77,15 @@ export interface TieredMenuSlots {
*/ */
item: MenuItem; item: MenuItem;
}): VNode[]; }): VNode[];
/**
* Custom submenu icon template.
*/
submenuicon(scope: {
/**
* Whether item is active
*/
active: boolean;
}): VNode[];
} }
/** /**

View File

@ -16,7 +16,7 @@
:menuId="id" :menuId="id"
:focusedItemId="focused ? focusedItemId : undefined" :focusedItemId="focused ? focusedItemId : undefined"
:items="processedItems" :items="processedItems"
:template="$slots.item" :template="$slots"
:activeItemPath="activeItemPath" :activeItemPath="activeItemPath"
:exact="exact" :exact="exact"
:level="0" :level="0"

View File

@ -16,7 +16,7 @@
:aria-posinset="getAriaPosInset(index)" :aria-posinset="getAriaPosInset(index)"
> >
<div class="p-menuitem-content" @click="onItemClick($event, processedItem)" @mouseenter="onItemMouseEnter($event, processedItem)"> <div class="p-menuitem-content" @click="onItemClick($event, processedItem)" @mouseenter="onItemMouseEnter($event, processedItem)">
<template v-if="!template"> <template v-if="!template.item">
<router-link v-if="getItemProp(processedItem, 'to') && !isItemDisabled(processedItem)" v-slot="{ navigate, href, isActive, isExactActive }" :to="getItemProp(processedItem, 'to')" custom> <router-link v-if="getItemProp(processedItem, 'to') && !isItemDisabled(processedItem)" v-slot="{ navigate, href, isActive, isExactActive }" :to="getItemProp(processedItem, 'to')" custom>
<a v-ripple :href="href" :class="getItemActionClass(processedItem, { isActive, isExactActive })" tabindex="-1" aria-hidden="true" @click="onItemActionClick($event, navigate)"> <a v-ripple :href="href" :class="getItemActionClass(processedItem, { isActive, isExactActive })" tabindex="-1" aria-hidden="true" @click="onItemActionClick($event, navigate)">
<span v-if="getItemProp(processedItem, 'icon')" :class="getItemIconClass(processedItem)"></span> <span v-if="getItemProp(processedItem, 'icon')" :class="getItemIconClass(processedItem)"></span>
@ -26,10 +26,12 @@
<a v-else v-ripple :href="getItemProp(processedItem, 'url')" :class="getItemActionClass(processedItem)" :target="getItemProp(processedItem, 'target')" tabindex="-1" aria-hidden="true"> <a v-else v-ripple :href="getItemProp(processedItem, 'url')" :class="getItemActionClass(processedItem)" :target="getItemProp(processedItem, 'target')" tabindex="-1" aria-hidden="true">
<span v-if="getItemProp(processedItem, 'icon')" :class="getItemIconClass(processedItem)"></span> <span v-if="getItemProp(processedItem, 'icon')" :class="getItemIconClass(processedItem)"></span>
<span class="p-menuitem-text">{{ getItemLabel(processedItem) }}</span> <span class="p-menuitem-text">{{ getItemLabel(processedItem) }}</span>
<span v-if="isItemGroup(processedItem)" class="p-submenu-icon pi pi-angle-right"></span> <slot v-if="getItemProp(processedItem, 'items')" name="submenuicon">
<component :is="template.submenuicon || 'AngleRightIcon'" class="p-submenu-icon" :active="isItemActive(processedItem)" />
</slot>
</a> </a>
</template> </template>
<component v-else :is="template" :item="processedItem.item"></component> <component v-else :is="template.item" :item="processedItem.item"></component>
</div> </div>
<TieredMenuSub <TieredMenuSub
v-if="isItemVisible(processedItem) && isItemGroup(processedItem)" v-if="isItemVisible(processedItem) && isItemGroup(processedItem)"
@ -53,6 +55,7 @@
</template> </template>
<script> <script>
import AngleRightIcon from 'primevue/icon/angleright';
import Ripple from 'primevue/ripple'; import Ripple from 'primevue/ripple';
import { ObjectUtils } from 'primevue/utils'; import { ObjectUtils } from 'primevue/utils';
@ -77,7 +80,7 @@ export default {
default: 0 default: 0
}, },
template: { template: {
type: Function, type: Object,
default: null default: null
}, },
activeItemPath: { activeItemPath: {
@ -160,6 +163,9 @@ export default {
return ['p-menuitem-separator', this.getItemProp(processedItem, 'class')]; return ['p-menuitem-separator', this.getItemProp(processedItem, 'class')];
} }
}, },
components: {
AngleRightIcon: AngleRightIcon
},
directives: { directives: {
ripple: Ripple ripple: Ripple
} }