primevue-mirror/doc/menu/TemplateDoc.vue

196 lines
7.2 KiB
Vue
Raw Normal View History

2023-02-28 08:29:30 +00:00
<template>
<DocSectionText v-bind="$attrs">
<p>Two slots named "start" and "end" are provided to embed content before or after the menu. In additon Menu, offers item customization with the <i>item</i> template that receives the menuitem instance from the model as a parameter.</p>
</DocSectionText>
<div class="card flex justify-content-center">
<Menu :model="items">
<template #start>
<button @click="profileClick" class="w-full p-link flex align-items-center p-2 pl-3 text-color hover:surface-200 border-noround">
<Avatar image="https://primefaces.org/cdn/primevue/images/avatar/amyelsner.png" class="mr-2" shape="circle" />
<div class="flex flex-column align">
<span class="font-bold">Amy Elsner</span>
<span class="text-sm">Agent</span>
</div>
</button>
</template>
2023-08-29 12:50:04 +00:00
<template #item="{ item, label, props }">
<a class="flex" v-bind="props.action">
<span v-bind="props.icon" />
<span v-bind="props.label">{{ label }}</span>
<Badge v-if="item.badge" class="ml-auto" :value="item.badge" />
</a>
</template>
2023-02-28 08:29:30 +00:00
<template #end>
<button class="w-full p-link flex align-items-center p-2 pl-4 text-color hover:surface-200 border-noround">
<i class="pi pi-sign-out" />
<span class="ml-2">Log Out</span>
</button>
</template>
</Menu>
</div>
<DocSectionCode :code="code" />
</template>
<script>
export default {
data() {
return {
2023-08-29 12:50:04 +00:00
items: [
{ separator: true },
{
label: 'Profile',
icon: 'pi pi-fw pi-user'
},
{
label: 'Settings',
icon: 'pi pi-fw pi-cog',
badge: 2
},
{ separator: true }
],
2023-02-28 08:29:30 +00:00
code: {
2023-08-16 13:58:31 +00:00
basic: `<Menu :model="items">
2023-02-28 08:29:30 +00:00
<template #start>
<button @click="profileClick" class="w-full p-link flex align-items-center p-2 pl-3 text-color hover:surface-200 border-noround">
<Avatar image="https://primefaces.org/cdn/primevue/images/avatar/amyelsner.png" class="mr-2" shape="circle" />
<div class="flex flex-column align">
<span class="font-bold">Amy Elsner</span>
<span class="text-sm">Agent</span>
</div>
</button>
</template>
2023-08-29 12:50:04 +00:00
<template #item="{ item, label, props }">
<a class="flex" v-bind="props.action">
<span v-bind="props.icon" />
<span v-bind="props.label">{{ label }}</span>
<Badge v-if="item.badge" class="ml-auto" :value="item.badge" />
</a>
</template>
2023-02-28 08:29:30 +00:00
<template #end>
<button class="w-full p-link flex align-items-center p-2 pl-4 text-color hover:surface-200 border-noround">
<i class="pi pi-sign-out" />
<span class="ml-2">Log Out</span>
</button>
</template>
</Menu>`,
2023-08-16 13:58:31 +00:00
options: `<template>
2023-02-28 08:29:30 +00:00
<div class="card flex justify-content-center">
<Menu :model="items">
<template #start>
<button @click="profileClick" class="w-full p-link flex align-items-center p-2 pl-3 text-color hover:surface-200 border-noround">
<Avatar image="https://primefaces.org/cdn/primevue/images/avatar/amyelsner.png" class="mr-2" shape="circle" />
<div class="flex flex-column align">
<span class="font-bold">Amy Elsner</span>
<span class="text-sm">Agent</span>
</div>
</button>
</template>
2023-08-29 12:50:04 +00:00
<template #item="{ item, label, props }">
<a class="flex" v-bind="props.action">
<span v-bind="props.icon" />
<span v-bind="props.label">{{ label }}</span>
<Badge v-if="item.badge" class="ml-auto" :value="item.badge" />
</a>
</template>
2023-02-28 08:29:30 +00:00
<template #end>
<button class="w-full p-link flex align-items-center p-2 pl-4 text-color hover:surface-200 border-noround">
<i class="pi pi-sign-out" />
<span class="ml-2">Log Out</span>
</button>
</template>
</Menu>
<Toast />
</div>
</template>
<script>
export default {
data() {
return {
items: [
{ separator: true },
2023-08-29 12:50:04 +00:00
{
label: 'Profile',
icon: 'pi pi-fw pi-user'
},
{
label: 'Settings',
icon: 'pi pi-fw pi-cog',
badge: 2
},
2023-02-28 08:29:30 +00:00
{ separator: true }
]
};
},
methods: {
profileClick() {
this.toast.add({ severity: 'info', summary: 'Info', detail: 'Item Selected', life: 3000 });
}
}
};
<\/script>`,
2023-08-16 13:58:31 +00:00
composition: `<template>
2023-02-28 08:29:30 +00:00
<div class="card flex justify-content-center">
<Menu :model="items">
<template #start>
<button @click="profileClick" class="w-full p-link flex align-items-center p-2 pl-3 text-color hover:surface-200 border-noround">
<Avatar image="https://primefaces.org/cdn/primevue/images/avatar/amyelsner.png" class="mr-2" shape="circle" />
<div class="flex flex-column align">
<span class="font-bold">Amy Elsner</span>
<span class="text-sm">Agent</span>
</div>
</button>
</template>
2023-08-29 12:50:04 +00:00
<template #item="{ item, label, props }">
<a class="flex" v-bind="props.action">
<span v-bind="props.icon" />
<span v-bind="props.label">{{ label }}</span>
<Badge v-if="item.badge" class="ml-auto" :value="item.badge" />
</a>
</template>
2023-02-28 08:29:30 +00:00
<template #end>
<button class="w-full p-link flex align-items-center p-2 pl-4 text-color hover:surface-200 border-noround">
<i class="pi pi-sign-out" />
<span class="ml-2">Log Out</span>
</button>
</template>
</Menu>
<Toast />
</div>
</template>
<script setup>
import { ref } from "vue";
import { useToast } from "primevue/usetoast";
const items = ref([
{ separator: true },
2023-08-29 12:50:04 +00:00
{
label: 'Profile',
icon: 'pi pi-fw pi-user'
},
{
label: 'Settings',
icon: 'pi pi-fw pi-cog',
badge: 2
},
2023-02-28 08:29:30 +00:00
{ separator: true }
]);
const toast = useToast();
const profileClick = () => {
toast.add({ severity: 'info', summary: 'Info', detail: 'Item Selected', life: 3000 });
}
<\/script>`
}
};
},
methods: {
profileClick() {
this.toast.add({ severity: 'info', summary: 'Info', detail: 'Item Selected', life: 3000 });
}
}
};
</script>