Refactor #3832 Refactor #3833 - For ContextMenu

pull/3868/head
mertsincan 2023-04-17 08:59:08 +03:00
parent 46f63c068e
commit 2d114831e0
3 changed files with 22 additions and 8 deletions

View File

@ -73,6 +73,20 @@ export interface ContextMenuSlots {
*/ */
item: MenuItem; item: MenuItem;
}): VNode[]; }): VNode[];
/**
* Custom item icon template.
* @param {Object} scope - item icon slot's params.
*/
itemicon(scope: {
/**
* Menuitem instance
*/
item: MenuItem;
/**
* Style class of the item icon element.
*/
class: any;
}): VNode[];
/** /**
* Custom submenu icon template. * Custom submenu icon template.
*/ */

View File

@ -14,7 +14,7 @@
:menuId="id" :menuId="id"
:focusedItemId="focused ? focusedItemId : undefined" :focusedItemId="focused ? focusedItemId : undefined"
:items="processedItems" :items="processedItems"
:template="$slots" :templates="$slots"
:activeItemPath="activeItemPath" :activeItemPath="activeItemPath"
:exact="exact" :exact="exact"
:aria-labelledby="ariaLabelledby" :aria-labelledby="ariaLabelledby"

View File

@ -17,20 +17,20 @@
: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.item"> <template v-if="!templates.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> <component :is="templates.itemicon || (getItemProp(processedItem, 'icon') ? 'span' : undefined)" :item="processedItem.item" :class="getItemIconClass(processedItem)" />
<span class="p-menuitem-text">{{ getItemLabel(processedItem) }}</span> <span class="p-menuitem-text">{{ getItemLabel(processedItem) }}</span>
</a> </a>
</router-link> </router-link>
<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> <component :is="templates.itemicon || (getItemProp(processedItem, 'icon') ? 'span' : undefined)" :item="processedItem.item" :class="getItemIconClass(processedItem)" />
<span class="p-menuitem-text">{{ getItemLabel(processedItem) }}</span> <span class="p-menuitem-text">{{ getItemLabel(processedItem) }}</span>
<component v-if="getItemProp(processedItem, 'items')" :is="template.submenuicon || 'AngleRightIcon'" :active="isItemActive(processedItem)" class="p-submenu-icon" /> <component v-if="getItemProp(processedItem, 'items')" :is="templates.submenuicon || 'AngleRightIcon'" :active="isItemActive(processedItem)" class="p-submenu-icon" />
</a> </a>
</template> </template>
<component v-else :is="template.item" :item="processedItem.item"></component> <component v-else :is="templates.item" :item="processedItem.item"></component>
</div> </div>
<ContextMenuSub <ContextMenuSub
v-if="isItemVisible(processedItem) && isItemGroup(processedItem)" v-if="isItemVisible(processedItem) && isItemGroup(processedItem)"
@ -40,7 +40,7 @@
:menuId="menuId" :menuId="menuId"
:focusedItemId="focusedItemId" :focusedItemId="focusedItemId"
:items="processedItem.items" :items="processedItem.items"
:template="template" :templates="templates"
:activeItemPath="activeItemPath" :activeItemPath="activeItemPath"
:exact="exact" :exact="exact"
:level="level + 1" :level="level + 1"
@ -88,7 +88,7 @@ export default {
type: Number, type: Number,
default: 0 default: 0
}, },
template: { templates: {
type: Object, type: Object,
default: null default: null
}, },