pull/3868/head
Kerem YILDAN 2023-04-17 09:44:12 +03:00
commit 9f248077d3
13 changed files with 157 additions and 20 deletions

View File

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

View File

@ -42,6 +42,10 @@ const TabMenuSlots = [
{ {
name: 'item', name: 'item',
description: 'Template of a menuitem.' description: 'Template of a menuitem.'
},
{
name: 'itemicon',
description: 'Custom item icon template.'
} }
]; ];

View File

@ -45,6 +45,10 @@ const TieredMenuSlots = [
{ {
name: 'submenuicon', name: 'submenuicon',
description: 'Custom submenu icon template.' description: 'Custom submenu icon template.'
},
{
name: 'itemicon',
description: 'Custom item icon template.'
} }
]; ];

View File

@ -89,6 +89,34 @@ export interface PanelMenuSlots {
*/ */
active: boolean; active: boolean;
}): VNode[]; }): 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"> <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> <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)"> <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="$slots.headericon || (getItemProp(item, 'icon') ? 'span' : undefined)" :item="item" :class="getHeaderIconClass(item)" />
<span class="p-menuitem-text">{{ getItemLabel(item) }}</span> <span class="p-menuitem-text">{{ getItemLabel(item) }}</span>
</a> </a>
</router-link> </router-link>
@ -26,7 +26,7 @@
<slot v-if="getItemProp(item, 'items')" name="submenuicon" :active="isItemActive(item)"> <slot v-if="getItemProp(item, 'items')" name="submenuicon" :active="isItemActive(item)">
<component :is="isItemActive(item) ? 'ChevronDownIcon' : 'ChevronRightIcon'" class="p-submenu-icon" /> <component :is="isItemActive(item) ? 'ChevronDownIcon' : 'ChevronRightIcon'" class="p-submenu-icon" />
</slot> </slot>
<span v-if="getItemProp(item, 'icon')" :class="getHeaderIconClass(item)"></span> <component :is="$slots.headericon || (getItemProp(item, 'icon') ? 'span' : undefined)" :item="item" :class="getHeaderIconClass(item)" />
<span class="p-menuitem-text">{{ getItemLabel(item) }}</span> <span class="p-menuitem-text">{{ getItemLabel(item) }}</span>
</a> </a>
</template> </template>
@ -36,7 +36,7 @@
<transition name="p-toggleable-content"> <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-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"> <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>
</div> </div>
</transition> </transition>

View File

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

View File

@ -14,20 +14,20 @@
:aria-posinset="getAriaPosInset(index)" :aria-posinset="getAriaPosInset(index)"
> >
<div class="p-menuitem-content" @click="onItemClick($event, processedItem)"> <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> <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">
<component v-if="isItemGroup(processedItem)" :is="template.submenuicon || (isItemActive(processedItem) ? 'ChevronDownIcon' : 'ChevronRightIcon')" class="p-submenu-icon" :active="isItemActive(processedItem)" /> <component v-if="isItemGroup(processedItem)" :is="templates.submenuicon || (isItemActive(processedItem) ? 'ChevronDownIcon' : 'ChevronRightIcon')" class="p-submenu-icon" :active="isItemActive(processedItem)" />
<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>
</template> </template>
<component v-else :is="template.item" :item="processedItem.item"></component> <component v-else :is="templates.item" :item="processedItem.item"></component>
</div> </div>
<transition name="p-toggleable-content"> <transition name="p-toggleable-content">
<div v-show="isItemActive(processedItem)" class="p-toggleable-content"> <div v-show="isItemActive(processedItem)" class="p-toggleable-content">
@ -39,7 +39,7 @@
:focusedItemId="focusedItemId" :focusedItemId="focusedItemId"
:items="processedItem.items" :items="processedItem.items"
:level="level + 1" :level="level + 1"
:template="template" :templates="templates"
:activeItemPath="activeItemPath" :activeItemPath="activeItemPath"
:exact="exact" :exact="exact"
@item-toggle="onItemToggle" @item-toggle="onItemToggle"
@ -78,7 +78,7 @@ export default {
type: Number, type: Number,
default: 0 default: 0
}, },
template: { templates: {
type: Object, type: Object,
default: null default: null
}, },

View File

@ -68,6 +68,20 @@ export interface TabMenuSlots {
*/ */
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[];
} }
/** /**

View File

@ -17,7 +17,7 @@
@click="onItemClick($event, item, i, navigate)" @click="onItemClick($event, item, i, navigate)"
@keydown="onKeydownItem($event, item, i, navigate)" @keydown="onKeydownItem($event, item, i, navigate)"
> >
<span v-if="item.icon" :class="getItemIcon(item)"></span> <component :is="$slots.itemicon || (item.icon ? 'span' : undefined)" :item="item" :class="getItemIcon(item)" />
<span class="p-menuitem-text">{{ label(item) }}</span> <span class="p-menuitem-text">{{ label(item) }}</span>
</a> </a>
</template> </template>
@ -27,7 +27,7 @@
<li v-else-if="visible(item)" ref="tab" :class="getItemClass(item, i)" role="presentation" @click="onItemClick($event, item, i)" @keydown="onKeydownItem($event, item, i)"> <li v-else-if="visible(item)" ref="tab" :class="getItemClass(item, i)" role="presentation" @click="onItemClick($event, item, i)" @keydown="onKeydownItem($event, item, i)">
<template v-if="!$slots.item"> <template v-if="!$slots.item">
<a ref="tabLink" v-ripple role="menuitem" :href="item.url" class="p-menuitem-link" :target="item.target" :aria-label="label(item)" :aria-disabled="disabled(item)" :tabindex="setTabIndex(i)"> <a ref="tabLink" v-ripple role="menuitem" :href="item.url" class="p-menuitem-link" :target="item.target" :aria-label="label(item)" :aria-disabled="disabled(item)" :tabindex="setTabIndex(i)">
<span v-if="item.icon" :class="getItemIcon(item)"></span> <component :is="$slots.itemicon || (item.icon ? 'span' : undefined)" :item="item" :class="getItemIcon(item)" />
<span class="p-menuitem-text">{{ label(item) }}</span> <span class="p-menuitem-text">{{ label(item) }}</span>
</a> </a>
</template> </template>

View File

@ -86,6 +86,20 @@ export interface TieredMenuSlots {
*/ */
active: boolean; active: boolean;
}): 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[];
} }
/** /**

View File

@ -16,7 +16,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"
: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.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> <span v-if="getItemProp(processedItem, 'icon')" :class="getItemIconClass(processedItem)"></span>
@ -26,10 +26,10 @@
<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>
<component v-if="getItemProp(processedItem, 'items')" :is="template.submenuicon || 'AngleRightIcon'" class="p-submenu-icon" :active="isItemActive(processedItem)" /> <component v-if="getItemProp(processedItem, 'items')" :is="templates.submenuicon || 'AngleRightIcon'" class="p-submenu-icon" :active="isItemActive(processedItem)" />
</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>
<TieredMenuSub <TieredMenuSub
v-if="isItemVisible(processedItem) && isItemGroup(processedItem)" v-if="isItemVisible(processedItem) && isItemGroup(processedItem)"
@ -39,7 +39,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"
@ -77,7 +77,7 @@ export default {
type: Number, type: Number,
default: 0 default: 0
}, },
template: { templates: {
type: Object, type: Object,
default: null default: null
}, },

View File

@ -16134,6 +16134,19 @@
], ],
"returnType": "VNode<RendererNode, RendererElement, Object>[]", "returnType": "VNode<RendererNode, RendererElement, Object>[]",
"description": "Custom submenu icon template." "description": "Custom submenu icon template."
},
{
"name": "itemicon",
"parameters": [
{
"name": "scope",
"optional": false,
"type": "{\n \t <b>item</b>: MenuItem, // Menuitem instance\n \t <b>class</b>: any, // Style class of the item icon element.\n }",
"description": "item icon slot's params."
}
],
"returnType": "VNode<RendererNode, RendererElement, Object>[]",
"description": "Custom item icon template."
} }
] ]
}, },
@ -16497,6 +16510,19 @@
], ],
"returnType": "VNode<RendererNode, RendererElement, Object>[]", "returnType": "VNode<RendererNode, RendererElement, Object>[]",
"description": "Custom submenu icon template." "description": "Custom submenu icon template."
},
{
"name": "itemicon",
"parameters": [
{
"name": "scope",
"optional": false,
"type": "{\n \t <b>item</b>: MenuItem, // Menuitem instance\n \t <b>class</b>: any, // Style class of the item icon element.\n }",
"description": "item icon slot's params."
}
],
"returnType": "VNode<RendererNode, RendererElement, Object>[]",
"description": "Custom item icon template."
} }
] ]
}, },
@ -19060,6 +19086,32 @@
], ],
"returnType": "VNode<RendererNode, RendererElement, Object>[]", "returnType": "VNode<RendererNode, RendererElement, Object>[]",
"description": "Custom submenu icon template." "description": "Custom submenu icon template."
},
{
"name": "headericon",
"parameters": [
{
"name": "scope",
"optional": false,
"type": "{\n \t <b>item</b>: MenuItem, // Menuitem instance\n \t <b>class</b>: any, // Style class of the item icon element.\n }",
"description": "header icon slot's params."
}
],
"returnType": "VNode<RendererNode, RendererElement, Object>[]",
"description": "Custom header icon template."
},
{
"name": "itemicon",
"parameters": [
{
"name": "scope",
"optional": false,
"type": "{\n \t <b>item</b>: MenuItem, // Menuitem instance\n \t <b>class</b>: any, // Style class of the item icon element.\n }",
"description": "item icon slot's params."
}
],
"returnType": "VNode<RendererNode, RendererElement, Object>[]",
"description": "Custom item icon template."
} }
] ]
}, },
@ -22699,6 +22751,19 @@
], ],
"returnType": "VNode<RendererNode, RendererElement, Object>[]", "returnType": "VNode<RendererNode, RendererElement, Object>[]",
"description": "Custom content for each item." "description": "Custom content for each item."
},
{
"name": "itemicon",
"parameters": [
{
"name": "scope",
"optional": false,
"type": "{\n \t <b>item</b>: MenuItem, // Menuitem instance\n \t <b>class</b>: any, // Style class of the item icon element.\n }",
"description": "item icon slot's params."
}
],
"returnType": "VNode<RendererNode, RendererElement, Object>[]",
"description": "Custom item icon template."
} }
] ]
}, },