Refactor #3832 Refactor #3833 - For PanelMenu

pull/3868/head
mertsincan 2023-04-17 09:30:28 +03:00
parent 1f86a9b8bb
commit 3ed2355a45
5 changed files with 48 additions and 12 deletions

View File

@ -27,6 +27,14 @@ const PanelMenuSlots = [
{
name: 'submenuicon',
description: 'Custom submenu icon template.'
},
{
name: 'headericon',
description: 'Custom header icon template.'
},
{
name: 'itemicon',
description: 'Custom item icon template.'
}
];

View File

@ -89,6 +89,34 @@ export interface PanelMenuSlots {
*/
active: boolean;
}): VNode[];
/**
* Custom header icon template.
* @param {Object} scope - header icon slot's params.
*/
headericon(scope: {
/**
* Menuitem instance
*/
item: MenuItem;
/**
* Style class of the item icon element.
*/
class: any;
}): 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[];
}
/**

View File

@ -18,7 +18,7 @@
<template v-if="!$slots.item">
<router-link v-if="getItemProp(item, 'to') && !isItemDisabled(item)" v-slot="{ navigate, href, isActive, isExactActive }" :to="getItemProp(item, 'to')" custom>
<a :href="href" :class="getHeaderActionClass(item, { isActive, isExactActive })" :tabindex="-1" @click="onHeaderActionClick($event, navigate)">
<span v-if="getItemProp(item, 'icon')" :class="getHeaderIconClass(item)"></span>
<component :is="templates.headericon || (getItemProp(item, 'icon') ? 'span' : undefined)" :item="item" :class="getHeaderIconClass(item)" />
<span class="p-menuitem-text">{{ getItemLabel(item) }}</span>
</a>
</router-link>
@ -26,7 +26,7 @@
<slot v-if="getItemProp(item, 'items')" name="submenuicon" :active="isItemActive(item)">
<component :is="isItemActive(item) ? 'ChevronDownIcon' : 'ChevronRightIcon'" class="p-submenu-icon" />
</slot>
<span v-if="getItemProp(item, 'icon')" :class="getHeaderIconClass(item)"></span>
<component :is="templates.headericon || (getItemProp(item, 'icon') ? 'span' : undefined)" :item="item" :class="getHeaderIconClass(item)" />
<span class="p-menuitem-text">{{ getItemLabel(item) }}</span>
</a>
</template>
@ -36,7 +36,7 @@
<transition name="p-toggleable-content">
<div v-show="isItemActive(item)" :id="getContentId(index)" class="p-toggleable-content" role="region" :aria-labelledby="getHeaderId(index)">
<div v-if="getItemProp(item, 'items')" class="p-panelmenu-content">
<PanelMenuList :panelId="getPanelId(index)" :items="getItemProp(item, 'items')" :template="$slots" :expandedKeys="expandedKeys" @item-toggle="changeExpandedKeys" @header-focus="updateFocusedHeader" :exact="exact" />
<PanelMenuList :panelId="getPanelId(index)" :items="getItemProp(item, 'items')" :templates="$slots" :expandedKeys="expandedKeys" @item-toggle="changeExpandedKeys" @header-focus="updateFocusedHeader" :exact="exact" />
</div>
</div>
</transition>

View File

@ -8,7 +8,7 @@
:panelId="panelId"
:focusedItemId="focused ? focusedItemId : undefined"
:items="processedItems"
:template="template"
:templates="templates"
:activeItemPath="activeItemPath"
:exact="exact"
@focus="onFocus"
@ -34,7 +34,7 @@ export default {
type: Array,
default: null
},
template: {
templates: {
type: Object,
default: null
},

View File

@ -14,20 +14,20 @@
:aria-posinset="getAriaPosInset(index)"
>
<div class="p-menuitem-content" @click="onItemClick($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>
<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>
</a>
</router-link>
<a v-else v-ripple :href="getItemProp(processedItem, 'url')" :class="getItemActionClass(processedItem)" :target="getItemProp(processedItem, 'target')" tabindex="-1" aria-hidden="true">
<component v-if="isItemGroup(processedItem)" :is="template.submenuicon || (isItemActive(processedItem) ? 'ChevronDownIcon' : 'ChevronRightIcon')" class="p-submenu-icon" :active="isItemActive(processedItem)" />
<span v-if="getItemProp(processedItem, 'icon')" :class="getItemIconClass(processedItem)"></span>
<component v-if="isItemGroup(processedItem)" :is="templates.submenuicon || (isItemActive(processedItem) ? 'ChevronDownIcon' : 'ChevronRightIcon')" class="p-submenu-icon" :active="isItemActive(processedItem)" />
<component :is="templates.itemicon || (getItemProp(processedItem, 'icon') ? 'span' : undefined)" :item="processedItem.item" :class="getItemIconClass(processedItem)" />
<span class="p-menuitem-text">{{ getItemLabel(processedItem) }}</span>
</a>
</template>
<component v-else :is="template.item" :item="processedItem.item"></component>
<component v-else :is="templates.item" :item="processedItem.item"></component>
</div>
<transition name="p-toggleable-content">
<div v-show="isItemActive(processedItem)" class="p-toggleable-content">
@ -39,7 +39,7 @@
:focusedItemId="focusedItemId"
:items="processedItem.items"
:level="level + 1"
:template="template"
:templates="templates"
:activeItemPath="activeItemPath"
:exact="exact"
@item-toggle="onItemToggle"
@ -78,7 +78,7 @@ export default {
type: Number,
default: 0
},
template: {
templates: {
type: Object,
default: null
},