2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2022-12-08 11:04:25 +00:00
|
|
|
<ul>
|
|
|
|
<template v-for="(processedItem, index) of items" :key="getItemKey(processedItem)">
|
|
|
|
<li
|
|
|
|
v-if="isItemVisible(processedItem) && !getItemProp(processedItem, 'separator')"
|
|
|
|
:id="getItemId(processedItem)"
|
|
|
|
:style="getItemProp(processedItem, 'style')"
|
|
|
|
:class="getItemClass(processedItem)"
|
|
|
|
role="menuitem"
|
|
|
|
:aria-label="getItemLabel(processedItem)"
|
|
|
|
:aria-disabled="isItemDisabled(processedItem) || undefined"
|
|
|
|
:aria-expanded="isItemGroup(processedItem) ? isItemActive(processedItem) : undefined"
|
|
|
|
:aria-haspopup="isItemGroup(processedItem) && !getItemProp(processedItem, 'to') ? 'menu' : undefined"
|
|
|
|
:aria-level="level + 1"
|
|
|
|
:aria-setsize="getAriaSetSize()"
|
|
|
|
:aria-posinset="getAriaPosInset(index)"
|
|
|
|
>
|
|
|
|
<div class="p-menuitem-content" @click="onItemClick($event, processedItem)" @mouseenter="onItemMouseEnter($event, processedItem)">
|
2023-04-17 06:10:56 +00:00
|
|
|
<template v-if="!templates.item">
|
2022-12-08 11:04:25 +00:00
|
|
|
<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)">
|
2023-04-18 10:50:13 +00:00
|
|
|
<component v-if="templates.itemicon" :is="templates.itemicon" :item="processedItem.item" :class="getItemIconClass(processedItem)" />
|
|
|
|
<span v-else-if="getItemProp(processedItem, 'icon')" :class="getItemIconClass(processedItem)" />
|
2022-12-08 11:04:25 +00:00
|
|
|
<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">
|
2023-04-18 10:50:13 +00:00
|
|
|
<component v-if="templates.itemicon" :is="templates.itemicon" :item="processedItem.item" :class="getItemIconClass(processedItem)" />
|
|
|
|
<span v-else-if="getItemProp(processedItem, 'icon')" :class="getItemIconClass(processedItem)" />
|
2022-12-08 11:04:25 +00:00
|
|
|
<span class="p-menuitem-text">{{ getItemLabel(processedItem) }}</span>
|
2023-04-18 10:50:13 +00:00
|
|
|
<template v-if="getItemProp(processedItem, 'items')">
|
|
|
|
<component v-if="templates.submenuicon" :is="templates.submenuicon" :root="root" :active="isItemActive(processedItem)" class="p-submenu-icon" />
|
|
|
|
<component v-else :is="root ? 'AngleDownIcon' : 'AngleRightIcon'" class="p-submenu-icon" />
|
|
|
|
</template>
|
2022-09-06 12:03:37 +00:00
|
|
|
</a>
|
2022-12-08 11:04:25 +00:00
|
|
|
</template>
|
2023-04-17 06:10:56 +00:00
|
|
|
<component v-else :is="templates.item" :item="processedItem.item"></component>
|
2022-12-08 11:04:25 +00:00
|
|
|
</div>
|
2022-09-14 11:26:01 +00:00
|
|
|
<MenubarSub
|
2022-12-08 11:04:25 +00:00
|
|
|
v-if="isItemVisible(processedItem) && isItemGroup(processedItem)"
|
|
|
|
:menuId="menuId"
|
|
|
|
role="menu"
|
|
|
|
class="p-submenu-list"
|
|
|
|
:focusedItemId="focusedItemId"
|
|
|
|
:items="processedItem.items"
|
2022-09-14 11:26:01 +00:00
|
|
|
:mobileActive="mobileActive"
|
2022-12-08 11:04:25 +00:00
|
|
|
:activeItemPath="activeItemPath"
|
2023-04-17 06:10:56 +00:00
|
|
|
:templates="templates"
|
2022-09-14 11:26:01 +00:00
|
|
|
:exact="exact"
|
2022-12-08 11:04:25 +00:00
|
|
|
:level="level + 1"
|
|
|
|
@item-click="$emit('item-click', $event)"
|
|
|
|
@item-mouseenter="$emit('item-mouseenter', $event)"
|
2022-09-14 11:26:01 +00:00
|
|
|
/>
|
2022-09-06 12:03:37 +00:00
|
|
|
</li>
|
2022-12-08 11:04:25 +00:00
|
|
|
<li v-if="isItemVisible(processedItem) && getItemProp(processedItem, 'separator')" :id="getItemId(processedItem)" :style="getItemProp(processedItem, 'style')" :class="getSeparatorItemClass(processedItem)" role="separator"></li>
|
2022-09-06 12:03:37 +00:00
|
|
|
</template>
|
|
|
|
</ul>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-04-18 12:53:43 +00:00
|
|
|
import AngleDownIcon from 'primevue/icons/angledown';
|
|
|
|
import AngleRightIcon from 'primevue/icons/angleright';
|
2022-09-06 12:03:37 +00:00
|
|
|
import Ripple from 'primevue/ripple';
|
2022-12-08 11:04:25 +00:00
|
|
|
import { ObjectUtils } from 'primevue/utils';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'MenubarSub',
|
2022-12-08 11:04:25 +00:00
|
|
|
emits: ['item-mouseenter', 'item-click'],
|
2022-09-06 12:03:37 +00:00
|
|
|
props: {
|
2022-12-08 11:04:25 +00:00
|
|
|
items: {
|
2022-09-06 12:03:37 +00:00
|
|
|
type: Array,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
root: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
popup: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
mobileActive: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
2023-04-17 06:10:56 +00:00
|
|
|
templates: {
|
2023-04-05 11:56:52 +00:00
|
|
|
type: Object,
|
2022-09-06 12:03:37 +00:00
|
|
|
default: null
|
|
|
|
},
|
|
|
|
exact: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
level: {
|
|
|
|
type: Number,
|
|
|
|
default: 0
|
|
|
|
},
|
|
|
|
menuId: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
focusedItemId: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
activeItemPath: {
|
|
|
|
type: Object,
|
|
|
|
default: null
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
list: null,
|
2022-09-06 12:03:37 +00:00
|
|
|
methods: {
|
2022-12-08 11:04:25 +00:00
|
|
|
getItemId(processedItem) {
|
|
|
|
return `${this.menuId}_${processedItem.key}`;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
getItemKey(processedItem) {
|
|
|
|
return this.getItemId(processedItem);
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2023-01-05 15:12:19 +00:00
|
|
|
getItemProp(processedItem, name, params) {
|
|
|
|
return processedItem && processedItem.item ? ObjectUtils.getItemValue(processedItem.item[name], params) : undefined;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
getItemLabel(processedItem) {
|
|
|
|
return this.getItemProp(processedItem, 'label');
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
isItemActive(processedItem) {
|
|
|
|
return this.activeItemPath.some((path) => path.key === processedItem.key);
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
isItemVisible(processedItem) {
|
|
|
|
return this.getItemProp(processedItem, 'visible') !== false;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
isItemDisabled(processedItem) {
|
|
|
|
return this.getItemProp(processedItem, 'disabled');
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
isItemFocused(processedItem) {
|
|
|
|
return this.focusedItemId === this.getItemId(processedItem);
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
isItemGroup(processedItem) {
|
|
|
|
return ObjectUtils.isNotEmpty(processedItem.items);
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
onItemClick(event, processedItem) {
|
2023-01-05 15:12:19 +00:00
|
|
|
this.getItemProp(processedItem, 'command', { originalEvent: event, item: processedItem.item });
|
2022-12-08 11:04:25 +00:00
|
|
|
this.$emit('item-click', { originalEvent: event, processedItem, isFocus: true });
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
onItemMouseEnter(event, processedItem) {
|
|
|
|
this.$emit('item-mouseenter', { originalEvent: event, processedItem });
|
|
|
|
},
|
|
|
|
onItemActionClick(event, navigate) {
|
|
|
|
navigate && navigate(event);
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
getAriaSetSize() {
|
|
|
|
return this.items.filter((processedItem) => this.isItemVisible(processedItem) && !this.getItemProp(processedItem, 'separator')).length;
|
|
|
|
},
|
|
|
|
getAriaPosInset(index) {
|
|
|
|
return index - this.items.slice(0, index).filter((processedItem) => this.isItemVisible(processedItem) && this.getItemProp(processedItem, 'separator')).length + 1;
|
|
|
|
},
|
|
|
|
getItemClass(processedItem) {
|
2022-09-06 12:03:37 +00:00
|
|
|
return [
|
2022-09-14 11:26:01 +00:00
|
|
|
'p-menuitem',
|
2022-12-08 11:04:25 +00:00
|
|
|
this.getItemProp(processedItem, 'class'),
|
2022-09-14 11:26:01 +00:00
|
|
|
{
|
2022-12-08 11:04:25 +00:00
|
|
|
'p-menuitem-active p-highlight': this.isItemActive(processedItem),
|
|
|
|
'p-focus': this.isItemFocused(processedItem),
|
|
|
|
'p-disabled': this.isItemDisabled(processedItem)
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
];
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
getItemActionClass(processedItem, routerProps) {
|
2022-09-14 11:26:01 +00:00
|
|
|
return [
|
|
|
|
'p-menuitem-link',
|
|
|
|
{
|
|
|
|
'router-link-active': routerProps && routerProps.isActive,
|
|
|
|
'router-link-active-exact': this.exact && routerProps && routerProps.isExactActive
|
|
|
|
}
|
|
|
|
];
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
getItemIconClass(processedItem) {
|
|
|
|
return ['p-menuitem-icon', this.getItemProp(processedItem, 'icon')];
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
getSeparatorItemClass(processedItem) {
|
|
|
|
return ['p-menuitem-separator', this.getItemProp(processedItem, 'class')];
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
containerClass() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return { 'p-submenu-list': !this.root, 'p-menubar-root-list': this.root };
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
2023-04-05 11:56:52 +00:00
|
|
|
components: {
|
|
|
|
AngleRightIcon: AngleRightIcon,
|
|
|
|
AngleDownIcon: AngleDownIcon
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
directives: {
|
2022-09-14 11:26:01 +00:00
|
|
|
ripple: Ripple
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
</script>
|