2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2023-05-30 11:06:57 +00:00
|
|
|
<ul :class="cx('submenu')" :tabindex="tabindex">
|
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)"
|
2024-04-30 13:03:20 +00:00
|
|
|
:class="[cx('item', { processedItem }), getItemProp(processedItem, 'class')]"
|
2022-12-08 11:04:25 +00:00
|
|
|
:style="getItemProp(processedItem, 'style')"
|
|
|
|
role="treeitem"
|
|
|
|
:aria-label="getItemLabel(processedItem)"
|
|
|
|
:aria-expanded="isItemGroup(processedItem) ? isItemActive(processedItem) : undefined"
|
|
|
|
:aria-level="level + 1"
|
|
|
|
:aria-setsize="getAriaSetSize()"
|
|
|
|
:aria-posinset="getAriaPosInset(index)"
|
2024-04-30 13:03:20 +00:00
|
|
|
v-bind="getPTOptions('item', processedItem, index)"
|
2023-05-30 08:25:54 +00:00
|
|
|
:data-p-focused="isItemFocused(processedItem)"
|
|
|
|
:data-p-disabled="isItemDisabled(processedItem)"
|
2022-12-08 11:04:25 +00:00
|
|
|
>
|
2024-04-30 13:03:20 +00:00
|
|
|
<div :class="cx('itemContent')" @click="onItemClick($event, processedItem)" @mousemove="onItemMouseMove($event, processedItem)" v-bind="getPTOptions('itemContent', processedItem, index)">
|
2023-04-17 06:30:28 +00:00
|
|
|
<template v-if="!templates.item">
|
2024-04-30 13:03:20 +00:00
|
|
|
<a v-ripple :href="getItemProp(processedItem, 'url')" :class="cx('itemLink')" :target="getItemProp(processedItem, 'target')" tabindex="-1" aria-hidden="true" v-bind="getPTOptions('itemLink', processedItem, index)">
|
2023-04-18 10:50:13 +00:00
|
|
|
<template v-if="isItemGroup(processedItem)">
|
2023-07-24 10:48:47 +00:00
|
|
|
<component v-if="templates.submenuicon" :is="templates.submenuicon" :class="cx('submenuIcon')" :active="isItemActive(processedItem)" v-bind="getPTOptions('submenuIcon', processedItem, index)" />
|
|
|
|
<component v-else :is="isItemActive(processedItem) ? 'ChevronDownIcon' : 'ChevronRightIcon'" :class="cx('submenuIcon')" v-bind="getPTOptions('submenuIcon', processedItem, index)" />
|
2023-04-18 10:50:13 +00:00
|
|
|
</template>
|
2024-04-30 13:03:20 +00:00
|
|
|
<component v-if="templates.itemicon" :is="templates.itemicon" :item="processedItem.item" :class="cx('itemIcon')" />
|
|
|
|
<span v-else-if="getItemProp(processedItem, 'icon')" :class="[cx('itemIcon'), getItemProp(processedItem, 'icon')]" v-bind="getPTOptions('itemIcon', processedItem, index)" />
|
2023-07-24 10:48:47 +00:00
|
|
|
<span :class="cx('label')" v-bind="getPTOptions('label', processedItem, index)">{{ getItemLabel(processedItem) }}</span>
|
2022-09-06 12:03:37 +00:00
|
|
|
</a>
|
2022-12-08 11:04:25 +00:00
|
|
|
</template>
|
2023-11-03 12:54:49 +00:00
|
|
|
<component
|
|
|
|
v-else
|
|
|
|
:is="templates.item"
|
|
|
|
:item="processedItem.item"
|
2023-11-08 13:10:03 +00:00
|
|
|
:root="false"
|
2023-11-09 08:42:17 +00:00
|
|
|
:active="isItemActive(processedItem)"
|
2023-11-03 12:54:49 +00:00
|
|
|
:hasSubmenu="isItemGroup(processedItem)"
|
|
|
|
:label="getItemLabel(processedItem)"
|
|
|
|
:props="getMenuItemProps(processedItem, index)"
|
|
|
|
></component>
|
2022-12-08 11:04:25 +00:00
|
|
|
</div>
|
2023-08-02 12:02:08 +00:00
|
|
|
<transition name="p-toggleable-content" v-bind="ptm('transition')">
|
2024-04-30 13:03:20 +00:00
|
|
|
<div v-show="isItemActive(processedItem)" :class="cx('contentContainer')" v-bind="ptm('contentContainer')">
|
2022-12-08 11:04:25 +00:00
|
|
|
<PanelMenuSub
|
|
|
|
v-if="isItemVisible(processedItem) && isItemGroup(processedItem)"
|
|
|
|
:id="getItemId(processedItem) + '_list'"
|
|
|
|
role="group"
|
|
|
|
:panelId="panelId"
|
|
|
|
:focusedItemId="focusedItemId"
|
|
|
|
:items="processedItem.items"
|
|
|
|
:level="level + 1"
|
2023-04-17 06:30:28 +00:00
|
|
|
:templates="templates"
|
2022-12-08 11:04:25 +00:00
|
|
|
:activeItemPath="activeItemPath"
|
|
|
|
@item-toggle="onItemToggle"
|
2024-02-15 15:57:40 +00:00
|
|
|
@item-mousemove="$emit('item-mousemove', $event)"
|
2023-04-26 09:58:36 +00:00
|
|
|
:pt="pt"
|
2023-08-30 07:27:49 +00:00
|
|
|
:unstyled="unstyled"
|
2023-05-30 08:25:54 +00:00
|
|
|
v-bind="ptm('submenu')"
|
2022-12-08 11:04:25 +00:00
|
|
|
/>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
</li>
|
2023-05-30 08:25:54 +00:00
|
|
|
<li
|
|
|
|
v-if="isItemVisible(processedItem) && getItemProp(processedItem, 'separator')"
|
|
|
|
:style="getItemProp(processedItem, 'style')"
|
2023-05-30 11:06:57 +00:00
|
|
|
:class="[cx('separator'), getItemProp(processedItem, 'class')]"
|
2023-05-30 08:25:54 +00:00
|
|
|
role="separator"
|
|
|
|
v-bind="ptm('separator')"
|
|
|
|
></li>
|
2022-09-06 12:03:37 +00:00
|
|
|
</template>
|
|
|
|
</ul>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-05-30 11:06:57 +00:00
|
|
|
import BaseComponent from 'primevue/basecomponent';
|
2023-04-18 12:53:43 +00:00
|
|
|
import ChevronDownIcon from 'primevue/icons/chevrondown';
|
|
|
|
import ChevronRightIcon from 'primevue/icons/chevronright';
|
2022-12-08 11:04:25 +00:00
|
|
|
import Ripple from 'primevue/ripple';
|
|
|
|
import { ObjectUtils } from 'primevue/utils';
|
2023-08-30 07:27:49 +00:00
|
|
|
import { mergeProps } from 'vue';
|
2022-12-08 11:04:25 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
export default {
|
|
|
|
name: 'PanelMenuSub',
|
2023-07-04 06:29:36 +00:00
|
|
|
hostName: 'PanelMenu',
|
2023-05-30 11:06:57 +00:00
|
|
|
extends: BaseComponent,
|
2024-02-15 15:57:40 +00:00
|
|
|
emits: ['item-toggle', 'item-mousemove'],
|
2022-09-06 12:03:37 +00:00
|
|
|
props: {
|
2022-12-08 11:04:25 +00:00
|
|
|
panelId: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
focusedItemId: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
items: {
|
|
|
|
type: Array,
|
2022-09-06 12:03:37 +00:00
|
|
|
default: null
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
level: {
|
|
|
|
type: Number,
|
|
|
|
default: 0
|
|
|
|
},
|
2023-04-17 06:30:28 +00:00
|
|
|
templates: {
|
2023-04-05 12:14:26 +00:00
|
|
|
type: Object,
|
2022-09-06 12:03:37 +00:00
|
|
|
default: null
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
activeItemPath: {
|
|
|
|
type: Object,
|
2022-09-06 12:03:37 +00:00
|
|
|
default: null
|
|
|
|
},
|
2023-05-30 08:25:54 +00:00
|
|
|
tabindex: {
|
|
|
|
type: Number,
|
|
|
|
default: -1
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2022-12-08 11:04:25 +00:00
|
|
|
getItemId(processedItem) {
|
|
|
|
return `${this.panelId}_${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-07-24 10:48:47 +00:00
|
|
|
getPTOptions(key, processedItem, index) {
|
2023-04-27 14:16:09 +00:00
|
|
|
return this.ptm(key, {
|
2023-04-28 10:15:44 +00:00
|
|
|
context: {
|
2023-07-25 09:11:38 +00:00
|
|
|
item: processedItem,
|
2023-07-24 10:48:47 +00:00
|
|
|
index,
|
2023-04-27 14:16:09 +00:00
|
|
|
active: this.isItemActive(processedItem),
|
2023-10-17 10:06:59 +00:00
|
|
|
focused: this.isItemFocused(processedItem),
|
|
|
|
disabled: this.isItemDisabled(processedItem)
|
2023-04-27 14:16:09 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
isItemActive(processedItem) {
|
|
|
|
return this.activeItemPath.some((path) => path.key === processedItem.key);
|
|
|
|
},
|
|
|
|
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-toggle', { processedItem, expanded: !this.isItemActive(processedItem) });
|
|
|
|
},
|
|
|
|
onItemToggle(event) {
|
|
|
|
this.$emit('item-toggle', event);
|
|
|
|
},
|
2024-02-15 15:57:40 +00:00
|
|
|
onItemMouseMove(event, processedItem) {
|
|
|
|
this.$emit('item-mousemove', { originalEvent: event, processedItem });
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
getAriaSetSize() {
|
|
|
|
return this.items.filter((processedItem) => this.isItemVisible(processedItem) && !this.getItemProp(processedItem, 'separator')).length;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
getAriaPosInset(index) {
|
|
|
|
return index - this.items.slice(0, index).filter((processedItem) => this.isItemVisible(processedItem) && this.getItemProp(processedItem, 'separator')).length + 1;
|
2023-08-30 07:27:49 +00:00
|
|
|
},
|
|
|
|
getMenuItemProps(processedItem, index) {
|
|
|
|
return {
|
|
|
|
action: mergeProps(
|
|
|
|
{
|
2024-04-30 13:03:20 +00:00
|
|
|
class: this.cx('itemLink'),
|
2023-08-30 07:27:49 +00:00
|
|
|
tabindex: -1,
|
|
|
|
'aria-hidden': true
|
|
|
|
},
|
2024-04-30 13:03:20 +00:00
|
|
|
this.getPTOptions('itemLink', processedItem, index)
|
2023-08-30 07:27:49 +00:00
|
|
|
),
|
|
|
|
icon: mergeProps(
|
|
|
|
{
|
2024-04-30 13:03:20 +00:00
|
|
|
class: [this.cx('itemIcon'), this.getItemProp(processedItem, 'icon')]
|
2023-08-30 07:27:49 +00:00
|
|
|
},
|
2024-04-30 13:03:20 +00:00
|
|
|
this.getPTOptions('itemIcon', processedItem, index)
|
2023-08-30 07:27:49 +00:00
|
|
|
),
|
|
|
|
label: mergeProps(
|
|
|
|
{
|
|
|
|
class: this.cx('label')
|
|
|
|
},
|
|
|
|
this.getPTOptions('label', processedItem, index)
|
|
|
|
),
|
|
|
|
submenuicon: mergeProps(
|
|
|
|
{
|
|
|
|
class: this.cx('submenuIcon')
|
|
|
|
},
|
|
|
|
this.getPTOptions('submenuicon', processedItem, index)
|
|
|
|
)
|
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
2023-04-05 12:14:26 +00:00
|
|
|
components: {
|
|
|
|
ChevronRightIcon: ChevronRightIcon,
|
|
|
|
ChevronDownIcon: ChevronDownIcon
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
directives: {
|
|
|
|
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>
|