Refactor #3832 Refactor #3833 - For Menubar

pull/3841/head
Tuğçe Küçükoğlu 2023-04-05 14:56:52 +03:00
parent 181732c1c8
commit 27c4bbec31
4 changed files with 47 additions and 13 deletions

View File

@ -16,15 +16,23 @@ const MenubarProps = [
const MenubarSlots = [
{
name: 'start',
description: 'Custom content before the content'
description: 'Custom content before the content.'
},
{
name: 'end',
description: 'Custom content after the content'
description: 'Custom content after the content.'
},
{
name: 'item',
description: 'Template of a menuitem.'
description: 'Custom menuitem template.'
},
{
name: 'baricon',
description: 'Custom bar icon template.'
},
{
name: 'submenuicon',
description: 'Custom submenu icon template.'
}
];

View File

@ -60,6 +60,23 @@ export interface MenubarSlots {
*/
item: MenuItem;
}): VNode[];
/**
* Custom bar icon template.
*/
baricon(): VNode[];
/**
* Custom submenu icon template.
*/
submenuicon(scope: {
/**
* Whether item is root
*/
root: boolean;
/**
* Whether item is active
*/
active: boolean;
}): VNode[];
}
/**

View File

@ -17,7 +17,9 @@
@keydown="menuButtonKeydown($event)"
v-bind="buttonProps"
>
<i class="pi pi-bars" />
<slot name="baricon">
<component :is="'BarsIcon'" />
</slot>
</a>
<MenubarSub
:ref="menubarRef"
@ -25,7 +27,7 @@
class="p-menubar-root-list"
role="menubar"
:items="processedItems"
:template="$slots.item"
:template="$slots"
:root="true"
:mobileActive="mobileActive"
tabindex="0"
@ -50,6 +52,7 @@
</template>
<script>
import BarsIcon from 'primevue/icon/bars';
import { DomHandler, ObjectUtils, UniqueComponentId, ZIndexUtils } from 'primevue/utils';
import MenubarSub from './MenubarSub.vue';
@ -605,7 +608,8 @@ export default {
}
},
components: {
MenubarSub: MenubarSub
MenubarSub: MenubarSub,
BarsIcon: BarsIcon
}
};
</script>

View File

@ -16,7 +16,7 @@
:aria-posinset="getAriaPosInset(index)"
>
<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>
<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>
@ -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">
<span v-if="getItemProp(processedItem, 'icon')" :class="getItemIconClass(processedItem)"></span>
<span class="p-menuitem-text">{{ getItemLabel(processedItem) }}</span>
<span v-if="getItemProp(processedItem, 'items')" :class="getSubmenuIcon()"></span>
<slot v-if="getItemProp(processedItem, 'items')" name="submenuicon">
<component :is="template.submenuicon || (root ? 'AngleDownIcon' : 'AngleRightIcon')" :root="root" :active="isItemActive(processedItem)" class="p-submenu-icon" />
</slot>
</a>
</template>
<component v-else :is="template" :item="processedItem.item"></component>
<component v-else :is="template.item" :item="processedItem.item"></component>
</div>
<MenubarSub
v-if="isItemVisible(processedItem) && isItemGroup(processedItem)"
@ -53,6 +55,8 @@
</template>
<script>
import AngleDownIcon from 'primevue/icon/angledown';
import AngleRightIcon from 'primevue/icon/angleright';
import Ripple from 'primevue/ripple';
import { ObjectUtils } from 'primevue/utils';
@ -77,7 +81,7 @@ export default {
default: false
},
template: {
type: Function,
type: Object,
default: null
},
exact: {
@ -171,9 +175,6 @@ export default {
},
getSeparatorItemClass(processedItem) {
return ['p-menuitem-separator', this.getItemProp(processedItem, 'class')];
},
getSubmenuIcon() {
return ['p-submenu-icon pi', { 'pi-angle-right': !this.root, 'pi-angle-down': this.root }];
}
},
computed: {
@ -181,6 +182,10 @@ export default {
return { 'p-submenu-list': !this.root, 'p-menubar-root-list': this.root };
}
},
components: {
AngleRightIcon: AngleRightIcon,
AngleDownIcon: AngleDownIcon
},
directives: {
ripple: Ripple
}