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 = [ const MenubarSlots = [
{ {
name: 'start', name: 'start',
description: 'Custom content before the content' description: 'Custom content before the content.'
}, },
{ {
name: 'end', name: 'end',
description: 'Custom content after the content' description: 'Custom content after the content.'
}, },
{ {
name: 'item', 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; item: MenuItem;
}): VNode[]; }): 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)" @keydown="menuButtonKeydown($event)"
v-bind="buttonProps" v-bind="buttonProps"
> >
<i class="pi pi-bars" /> <slot name="baricon">
<component :is="'BarsIcon'" />
</slot>
</a> </a>
<MenubarSub <MenubarSub
:ref="menubarRef" :ref="menubarRef"
@ -25,7 +27,7 @@
class="p-menubar-root-list" class="p-menubar-root-list"
role="menubar" role="menubar"
:items="processedItems" :items="processedItems"
:template="$slots.item" :template="$slots"
:root="true" :root="true"
:mobileActive="mobileActive" :mobileActive="mobileActive"
tabindex="0" tabindex="0"
@ -50,6 +52,7 @@
</template> </template>
<script> <script>
import BarsIcon from 'primevue/icon/bars';
import { DomHandler, ObjectUtils, UniqueComponentId, ZIndexUtils } from 'primevue/utils'; import { DomHandler, ObjectUtils, UniqueComponentId, ZIndexUtils } from 'primevue/utils';
import MenubarSub from './MenubarSub.vue'; import MenubarSub from './MenubarSub.vue';
@ -605,7 +608,8 @@ export default {
} }
}, },
components: { components: {
MenubarSub: MenubarSub MenubarSub: MenubarSub,
BarsIcon: BarsIcon
} }
}; };
</script> </script>

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="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> </a>
</template> </template>
<component v-else :is="template" :item="processedItem.item"></component> <component v-else :is="template.item" :item="processedItem.item"></component>
</div> </div>
<MenubarSub <MenubarSub
v-if="isItemVisible(processedItem) && isItemGroup(processedItem)" v-if="isItemVisible(processedItem) && isItemGroup(processedItem)"
@ -53,6 +55,8 @@
</template> </template>
<script> <script>
import AngleDownIcon from 'primevue/icon/angledown';
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 +81,7 @@ export default {
default: false default: false
}, },
template: { template: {
type: Function, type: Object,
default: null default: null
}, },
exact: { exact: {
@ -171,9 +175,6 @@ export default {
}, },
getSeparatorItemClass(processedItem) { getSeparatorItemClass(processedItem) {
return ['p-menuitem-separator', this.getItemProp(processedItem, 'class')]; 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: { computed: {
@ -181,6 +182,10 @@ export default {
return { 'p-submenu-list': !this.root, 'p-menubar-root-list': this.root }; return { 'p-submenu-list': !this.root, 'p-menubar-root-list': this.root };
} }
}, },
components: {
AngleRightIcon: AngleRightIcon,
AngleDownIcon: AngleDownIcon
},
directives: { directives: {
ripple: Ripple ripple: Ripple
} }