primevue-mirror/src/views/menu/MenuDoc.vue

360 lines
12 KiB
Vue
Raw Normal View History

2019-05-27 08:10:22 +00:00
<template>
<div class="content-section documentation">
<TabView>
<TabPanel header="Documentation">
2020-06-17 19:29:33 +00:00
<h5>Import</h5>
2021-02-03 10:10:30 +00:00
<pre v-code.script><code>
2019-05-27 08:10:22 +00:00
import Menu from 'primevue/menu';
2020-09-24 11:14:55 +00:00
</code></pre>
2019-05-27 08:10:22 +00:00
2020-06-17 19:29:33 +00:00
<h5>MenuModel</h5>
2019-12-03 07:31:21 +00:00
<p>Menu uses the common MenuModel API to define the items, visit <router-link to="/menumodel">MenuModel API</router-link> for details.</p>
2020-06-17 19:29:33 +00:00
<h5>Getting Started</h5>
2019-05-27 08:10:22 +00:00
<p>Menu requires a collection of menuitems as its model.</p>
2021-02-03 10:10:30 +00:00
<pre v-code><code>
2019-05-27 08:10:22 +00:00
&lt;Menu :model="items" /&gt;
2020-09-24 11:14:55 +00:00
</code></pre>
2021-02-03 10:10:30 +00:00
<pre v-code.script><code>
2019-05-27 08:10:22 +00:00
export default {
data() {
return {
items: [
{
label: 'Update',
icon: 'pi pi-refresh',
command: () => {
this.$toast.add({severity:'success', summary:'Updated', detail:'Data Updated', life: 3000});
}
},
{
label: 'Delete',
icon: 'pi pi-times',
command: () => {
this.$toast.add({ severity: 'warn', summary: 'Delete', detail: 'Data Deleted', life: 3000});
}
},
{
label: 'Vue Website',
icon: 'pi pi-external-link',
url: 'https://vuejs.org/'
2019-05-27 08:10:22 +00:00
},
{
label: 'Router',
icon: 'pi pi-upload',
to: '/fileupload'
}
2019-05-27 08:10:22 +00:00
]
}
}
}
2020-09-24 11:14:55 +00:00
</code></pre>
2019-05-27 08:10:22 +00:00
2020-06-17 19:29:33 +00:00
<h5>SubMenus</h5>
2019-05-27 08:10:22 +00:00
<p>Menu supports one level of nesting via subitems of an item.</p>
2021-02-03 10:10:30 +00:00
<pre v-code.script><code>
const items: [
2019-05-27 08:10:22 +00:00
{
label: 'Options',
items: [{label: 'New', icon: 'pi pi-fw pi-plus', command:() => {} },
2019-12-10 17:54:51 +00:00
{label: 'Delete', icon: 'pi pi-fw pi-trash', url: 'https://www.primetek.com.tr'}]
2019-10-01 13:00:26 +00:00
},
2019-05-27 08:10:22 +00:00
{
label: 'Account',
items: [{label: 'Options', icon: 'pi pi-fw pi-cog', to: '/options'},
{label: 'Sign Out', icon: 'pi pi-fw pi-power-off', to: '/logout'} ]
2019-05-27 08:10:22 +00:00
}
];
2020-09-24 11:14:55 +00:00
</code></pre>
2019-05-27 08:10:22 +00:00
2020-06-17 19:29:33 +00:00
<h5>Popup Mode</h5>
2019-05-27 08:10:22 +00:00
<p>Menu is inline by default whereas popup mode is supported by enabling popup property and calling toggle method with an event of the target.</p>
2021-02-03 10:10:30 +00:00
<pre v-code><code>
2019-05-27 08:10:22 +00:00
&lt;Button type="button" label="Toggle" @click="toggle" /&gt;
&lt;Menu ref="menu" :model="items" :popup="true" /&gt;
2020-09-24 11:14:55 +00:00
</code></pre>
2021-02-03 10:10:30 +00:00
<pre v-code.script><code>
toggle(event) {
this.$refs.menu.toggle(event);
}
2020-09-24 11:14:55 +00:00
</code></pre>
2019-10-01 13:00:26 +00:00
2020-06-17 19:29:33 +00:00
<h5>Properties</h5>
2020-01-13 09:04:50 +00:00
<p>Any property as style and class are passed to the main container element. Following are the additional properties to configure the component.</p>
2019-05-27 08:10:22 +00:00
<div class="doc-tablewrapper">
<table class="doc-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
2019-10-01 13:00:26 +00:00
<tbody>
2019-05-27 08:10:22 +00:00
<tr>
<td>model</td>
<td>array</td>
<td>null</td>
<td>An array of menuitems.</td>
</tr>
<tr>
<td>popup</td>
<td>boolean</td>
<td>false</td>
<td>Defines if menu would displayed as a popup.</td>
</tr>
<tr>
<td>appendTo</td>
<td>string</td>
2021-03-01 20:54:17 +00:00
<td>body</td>
<td>A valid query selector or an HTMLElement to specify where the overlay gets attached.</td>
2019-05-27 08:10:22 +00:00
</tr>
<tr>
<td>baseZIndex</td>
<td>number</td>
<td>0</td>
<td>Base zIndex value to use in layering.</td>
</tr>
<tr>
<td>autoZIndex</td>
<td>boolean</td>
<td>true</td>
<td>Whether to automatically manage layering.</td>
</tr>
</tbody>
</table>
</div>
2020-06-17 19:29:33 +00:00
<h5>Methods</h5>
2019-05-27 08:10:22 +00:00
<div class="doc-tablewrapper">
<table class="doc-table">
<thead>
<tr>
<th>Name</th>
<th>Parameters</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>toggle</td>
<td>event: Browser event</td>
2019-12-04 14:13:39 +00:00
<td>Toggles the visibility of the overlay.</td>
2019-05-27 08:10:22 +00:00
</tr>
<tr>
<td>show</td>
<td>event: Browser event <br />
target: Optional target if event.target would not be used</td>
<td>Shows the overlay.</td>
</tr>
<tr>
<td>hide</td>
<td>-</td>
<td>Hides the overlay.</td>
</tr>
</tbody>
</table>
</div>
2020-06-17 19:29:33 +00:00
<h5>Styling</h5>
2019-05-27 08:10:22 +00:00
<p>Following is the list of structural style classes, for theming classes visit <router-link to="/theming">theming</router-link> page.</p>
<div class="doc-tablewrapper">
<table class="doc-table">
<thead>
<tr>
<th>Name</th>
<th>Element</th>
</tr>
</thead>
<tbody>
<tr>
<td>p-menu</td>
<td>Container element.</td>
</tr>
<tr>
<td>p-menu-list</td>
<td>List element.</td>
</tr>
<tr>
<td>p-menuitem</td>
<td>Menuitem element.</td>
</tr>
<tr>
<td>p-menuitem-text</td>
<td>Label of a menuitem.</td>
</tr>
<tr>
<td>p-menuitem-icon</td>
<td>Icon of a menuitem.</td>
</tr>
2019-05-27 08:10:22 +00:00
</tbody>
</table>
</div>
2020-06-17 19:29:33 +00:00
<h5>Dependencies</h5>
2019-05-27 08:10:22 +00:00
<p>None.</p>
</TabPanel>
<TabPanel header="Source">
2021-01-22 14:52:32 +00:00
<div class="p-d-flex p-jc-between">
<a href="https://github.com/primefaces/primevue/tree/master/src/views/menu" class="btn-viewsource" target="_blank" rel="noopener noreferrer">
<span>View on GitHub</span>
</a>
2021-01-26 07:23:55 +00:00
<LiveEditor name="MenuDemo" :sources="sources" :toastService="true" :router="true" :components="['Button']"/>
2021-01-22 14:52:32 +00:00
</div>
2021-02-03 10:10:30 +00:00
<pre v-code><code><template v-pre>
2019-08-04 12:19:34 +00:00
&lt;h3&gt;Inline&lt;/h3&gt;
&lt;Menu :model="items" /&gt;
2019-05-27 08:10:22 +00:00
2019-08-04 12:19:34 +00:00
&lt;h3&gt;Overlay&lt;/h3&gt;
&lt;Button type="button" label="Toggle" @click="toggle" aria-haspopup="true" aria-controls="overlay_menu" /&gt;
&lt;Menu id="overlay_menu" ref="menu" :model="items" :popup="true" /&gt;
2019-05-27 08:10:22 +00:00
</template>
2020-09-24 11:14:55 +00:00
</code></pre>
2019-05-27 08:10:22 +00:00
2021-02-03 10:10:30 +00:00
<pre v-code.script><code>
2019-05-27 08:10:22 +00:00
export default {
data() {
return {
items: [
{
label: 'Options',
items: [{
2019-10-01 13:00:26 +00:00
label: 'Update',
icon: 'pi pi-refresh',
2019-05-27 08:10:22 +00:00
command: () => {
this.$toast.add({severity:'success', summary:'Updated', detail:'Data Updated', life: 3000});
}
},
{
2019-10-01 13:00:26 +00:00
label: 'Delete',
2019-05-27 08:10:22 +00:00
icon: 'pi pi-times',
command: () => {
this.$toast.add({ severity: 'warn', summary: 'Delete', detail: 'Data Deleted', life: 3000});
}
}
]},
{
label: 'Navigate',
items: [{
2019-10-01 13:00:26 +00:00
label: 'Vue Website',
2019-05-27 08:10:22 +00:00
icon: 'pi pi-external-link',
url: 'https://vuejs.org/'
2019-05-27 08:10:22 +00:00
},
2019-10-01 13:00:26 +00:00
{
label: 'Router',
2019-10-01 13:00:26 +00:00
icon: 'pi pi-upload',
to: '/fileupload'
2019-05-27 08:10:22 +00:00
}
]}
]
2019-10-01 13:00:26 +00:00
}
2019-05-27 08:10:22 +00:00
},
methods: {
toggle(event) {
this.$refs.menu.toggle(event);
},
save() {
this.$toast.add({severity: 'success', summary: 'Success', detail: 'Data Saved', life: 3000});
}
}
}
2020-09-24 11:14:55 +00:00
</code></pre>
2019-05-27 08:10:22 +00:00
</TabPanel>
</TabView>
</div>
2020-09-27 16:48:28 +00:00
</template>
2021-01-22 14:52:32 +00:00
<script>
import LiveEditor from '../liveeditor/LiveEditor';
export default {
data() {
return {
sources: {
'template': {
content: `<template>
<div class="layout-content">
2021-01-26 07:23:55 +00:00
<Toast />
2021-01-22 14:52:32 +00:00
<div class="content-section implementation">
<div class="card">
<h5>Inline</h5>
<Menu :model="items" />
<h5>Overlay</h5>
<Button type="button" label="Toggle" @click="toggle" aria-haspopup="true" aria-controls="overlay_menu"/>
<Menu id="overlay_menu" ref="menu" :model="items" :popup="true" />
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
items: [
{
label: 'Options',
items: [{
label: 'Update',
icon: 'pi pi-refresh',
command: () => {
this.$toast.add({severity:'success', summary:'Updated', detail:'Data Updated', life: 3000});
}
},
{
label: 'Delete',
icon: 'pi pi-times',
command: () => {
this.$toast.add({ severity: 'warn', summary: 'Delete', detail: 'Data Deleted', life: 3000});
}
}
]},
{
label: 'Navigate',
items: [{
label: 'Vue Website',
icon: 'pi pi-external-link',
url: 'https://vuejs.org/'
},
{
label: 'Router',
icon: 'pi pi-upload',
command: () => {
window.location.hash = "/fileupload"
}
}
]}
]
}
},
methods: {
toggle(event) {
this.$refs.menu.toggle(event);
},
save() {
this.$toast.add({severity: 'success', summary: 'Success', detail: 'Data Saved', life: 3000});
}
}
}`
}
}
}
},
components: {
LiveEditor
}
}
</script>