2022-12-08 11:04:25 +00:00
|
|
|
<template>
|
2023-05-30 06:56:47 +00:00
|
|
|
<ul :class="level === 0 ? getCXOptions('menu') : getCXOptions('submenu')" :tabindex="tabindex" v-bind="level === 0 ? ptm('menu') : ptm('submenu')">
|
|
|
|
<li v-if="submenu" :class="[getCXOptions('submenuHeader', { submenu }), getItemProp(submenu, 'class')]" :style="getItemProp(submenu, 'style')" role="presentation" v-bind="ptm('submenuHeader')">{{ getItemLabel(submenu) }}</li>
|
2022-12-08 11:04:25 +00:00
|
|
|
<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')"
|
2023-05-30 06:56:47 +00:00
|
|
|
:class="[getCXOptions('menuitem', { processedItem }), getItemProp(processedItem, 'class')]"
|
2022-12-08 11:04:25 +00:00
|
|
|
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)"
|
2023-04-27 14:16:09 +00:00
|
|
|
v-bind="getPTOptions(processedItem, 'menuitem')"
|
2023-05-30 06:56:47 +00:00
|
|
|
:data-p-highlight="isItemActive(processedItem)"
|
|
|
|
:data-p-focused="isItemFocused(processedItem)"
|
|
|
|
:data-p-disabled="isItemDisabled(processedItem)"
|
2022-12-08 11:04:25 +00:00
|
|
|
>
|
2023-05-30 06:56:47 +00:00
|
|
|
<div :class="getCXOptions('content')" @click="onItemClick($event, processedItem)" @mouseenter="onItemMouseEnter($event, processedItem)" v-bind="getPTOptions(processedItem, 'content')">
|
2023-04-17 06:14:45 +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>
|
2023-05-30 06:56:47 +00:00
|
|
|
<a v-ripple :href="href" :class="getCXOptions('action', { isActive, isExactActive })" tabindex="-1" aria-hidden="true" @click="onItemActionClick($event, navigate)" v-bind="getPTOptions(processedItem, 'action')">
|
|
|
|
<component v-if="templates.itemicon" :is="templates.itemicon" :item="processedItem.item" :class="[getCXOptions('icon'), getItemProp(processedItem, 'icon')]" />
|
|
|
|
<span v-else-if="getItemProp(processedItem, 'icon')" :class="[getCXOptions('icon'), getItemProp(processedItem, 'icon')]" v-bind="getPTOptions(processedItem, 'icon')" />
|
|
|
|
<span :class="getCXOptions('text')" v-bind="getPTOptions(processedItem, 'label')">{{ getItemLabel(processedItem) }}</span>
|
2022-12-08 11:04:25 +00:00
|
|
|
</a>
|
|
|
|
</router-link>
|
2023-05-30 06:56:47 +00:00
|
|
|
<a v-else v-ripple :href="getItemProp(processedItem, 'url')" :class="getCXOptions('action')" :target="getItemProp(processedItem, 'target')" tabindex="-1" aria-hidden="true" v-bind="getPTOptions(processedItem, 'action')">
|
|
|
|
<component v-if="templates.itemicon" :is="templates.itemicon" :item="processedItem.item" :class="[getCXOptions('icon'), getItemProp(processedItem, 'icon')]" />
|
|
|
|
<span v-else-if="getItemProp(processedItem, 'icon')" :class="[getCXOptions('icon'), getItemProp(processedItem, 'icon')]" v-bind="getPTOptions(processedItem, 'icon')" />
|
|
|
|
<span :class="getCXOptions('text')" v-bind="getPTOptions(processedItem, 'label')">{{ getItemLabel(processedItem) }}</span>
|
2023-04-18 10:50:13 +00:00
|
|
|
<template v-if="isItemGroup(processedItem)">
|
2023-05-30 06:56:47 +00:00
|
|
|
<component v-if="templates.submenuicon" :is="templates.submenuicon" :active="isItemActive(processedItem)" :class="getCXOptions('submenuIcon')" v-bind="getPTOptions(processedItem, 'submenuIcon')" />
|
|
|
|
<component v-else :is="horizontal ? 'AngleDownIcon' : 'AngleRightIcon'" :class="getCXOptions('submenuIcon')" v-bind="getPTOptions(processedItem, 'submenuIcon')" />
|
2023-04-18 10:50:13 +00:00
|
|
|
</template>
|
2022-12-08 11:04:25 +00:00
|
|
|
</a>
|
|
|
|
</template>
|
2023-04-17 06:14:45 +00:00
|
|
|
<component v-else :is="templates.item" :item="processedItem.item"></component>
|
2022-12-08 11:04:25 +00:00
|
|
|
</div>
|
2023-05-30 06:56:47 +00:00
|
|
|
<div v-if="isItemVisible(processedItem) && isItemGroup(processedItem)" :class="getCXOptions('panel')" v-bind="ptm('panel')">
|
|
|
|
<div :class="getCXOptions('grid')" v-bind="ptm('grid')">
|
|
|
|
<div v-for="col of processedItem.items" :key="getItemKey(col)" :class="getCXOptions('column', { processedItem })" v-bind="ptm('column')">
|
2022-12-08 11:04:25 +00:00
|
|
|
<MegaMenuSub
|
|
|
|
v-for="submenu of col"
|
|
|
|
:key="getSubListKey(submenu)"
|
|
|
|
:id="getSubListId(submenu)"
|
2023-05-30 06:56:47 +00:00
|
|
|
:style="getSXOptions('submenu', { processedItem })"
|
2022-12-08 11:04:25 +00:00
|
|
|
role="menu"
|
|
|
|
:menuId="menuId"
|
|
|
|
:focusedItemId="focusedItemId"
|
|
|
|
:submenu="submenu"
|
|
|
|
:items="submenu.items"
|
2023-04-17 06:14:45 +00:00
|
|
|
:templates="templates"
|
2022-12-08 11:04:25 +00:00
|
|
|
:exact="exact"
|
|
|
|
:level="level + 1"
|
2023-04-26 09:57:55 +00:00
|
|
|
:pt="pt"
|
2022-12-08 11:04:25 +00:00
|
|
|
@item-click="$emit('item-click', $event)"
|
|
|
|
@item-mouseenter="$emit('item-mouseenter', $event)"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</li>
|
2023-04-26 09:57:55 +00:00
|
|
|
<li
|
|
|
|
v-if="isItemVisible(processedItem) && getItemProp(processedItem, 'separator')"
|
|
|
|
:id="getItemId(processedItem)"
|
2023-05-30 06:56:47 +00:00
|
|
|
:class="[getCXOptions('separator'), getItemProp(processedItem, 'class')]"
|
2023-04-26 09:57:55 +00:00
|
|
|
:style="getItemProp(processedItem, 'style')"
|
|
|
|
role="separator"
|
|
|
|
v-bind="ptm('separator')"
|
|
|
|
></li>
|
2022-12-08 11:04:25 +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-12-08 11:04:25 +00:00
|
|
|
import Ripple from 'primevue/ripple';
|
|
|
|
import { ObjectUtils } from 'primevue/utils';
|
2023-05-30 06:56:47 +00:00
|
|
|
import BaseMegaMenu from './BaseMegaMenu.vue';
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'MegaMenuSub',
|
2023-05-30 06:56:47 +00:00
|
|
|
extends: BaseMegaMenu,
|
2022-12-08 11:04:25 +00:00
|
|
|
emits: ['item-click', 'item-mouseenter'],
|
|
|
|
props: {
|
|
|
|
menuId: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
focusedItemId: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
horizontal: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
submenu: {
|
|
|
|
type: Object,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
items: {
|
|
|
|
type: Array,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
level: {
|
|
|
|
type: Number,
|
|
|
|
default: 0
|
|
|
|
},
|
2023-04-17 06:14:45 +00:00
|
|
|
templates: {
|
2023-04-05 11:56:29 +00:00
|
|
|
type: Object,
|
2022-12-08 11:04:25 +00:00
|
|
|
default: null
|
|
|
|
},
|
|
|
|
activeItem: {
|
|
|
|
type: Object,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
exact: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
2023-05-30 06:56:47 +00:00
|
|
|
},
|
|
|
|
tabindex: {
|
|
|
|
type: Number,
|
|
|
|
default: 0
|
2022-12-08 11:04:25 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getSubListId(processedItem) {
|
|
|
|
return `${this.getItemId(processedItem)}_list`;
|
|
|
|
},
|
|
|
|
getSubListKey(processedItem) {
|
|
|
|
return this.getSubListId(processedItem);
|
|
|
|
},
|
|
|
|
getItemId(processedItem) {
|
|
|
|
return `${this.menuId}_${processedItem.key}`;
|
|
|
|
},
|
|
|
|
getItemKey(processedItem) {
|
|
|
|
return this.getItemId(processedItem);
|
|
|
|
},
|
2023-01-05 15:12:19 +00:00
|
|
|
getItemProp(processedItem, name, params) {
|
|
|
|
return processedItem && processedItem.item ? ObjectUtils.getItemValue(processedItem.item[name], params) : undefined;
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
getItemLabel(processedItem) {
|
|
|
|
return this.getItemProp(processedItem, 'label');
|
|
|
|
},
|
2023-04-27 14:16:09 +00:00
|
|
|
getPTOptions(processedItem, key) {
|
|
|
|
return this.ptm(key, {
|
2023-04-28 10:15:44 +00:00
|
|
|
context: {
|
2023-04-27 14:16:09 +00:00
|
|
|
active: this.isItemActive(processedItem),
|
|
|
|
focused: this.isItemFocused(processedItem)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2023-05-30 06:56:47 +00:00
|
|
|
getCXOptions(key, params) {
|
|
|
|
return this.cx(key, {
|
|
|
|
...params,
|
|
|
|
context: this
|
|
|
|
});
|
|
|
|
},
|
|
|
|
getSXOptions(key, params) {
|
|
|
|
return this.sx(key, true, {
|
|
|
|
...params,
|
|
|
|
context: this
|
|
|
|
});
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
isItemActive(processedItem) {
|
|
|
|
return ObjectUtils.isNotEmpty(this.activeItem) ? this.activeItem.key === processedItem.key : false;
|
|
|
|
},
|
|
|
|
isItemVisible(processedItem) {
|
|
|
|
return this.getItemProp(processedItem, 'visible') !== false;
|
|
|
|
},
|
|
|
|
isItemDisabled(processedItem) {
|
|
|
|
return this.getItemProp(processedItem, 'disabled');
|
|
|
|
},
|
|
|
|
isItemFocused(processedItem) {
|
|
|
|
return this.focusedItemId === this.getItemId(processedItem);
|
|
|
|
},
|
|
|
|
isItemGroup(processedItem) {
|
|
|
|
return ObjectUtils.isNotEmpty(processedItem.items);
|
|
|
|
},
|
|
|
|
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 });
|
|
|
|
},
|
|
|
|
onItemMouseEnter(event, processedItem) {
|
|
|
|
this.$emit('item-mouseenter', { originalEvent: event, processedItem });
|
|
|
|
},
|
|
|
|
onItemActionClick(event, navigate) {
|
|
|
|
navigate && navigate(event);
|
|
|
|
},
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
},
|
2023-04-05 11:56:29 +00:00
|
|
|
components: {
|
|
|
|
AngleRightIcon: AngleRightIcon,
|
|
|
|
AngleDownIcon: AngleDownIcon
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
directives: {
|
|
|
|
ripple: Ripple
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|