primevue-mirror/apps/showcase/doc/panelmenu/RouterDoc.vue

234 lines
8.2 KiB
Vue
Raw Permalink Normal View History

2023-08-30 13:33:42 +00:00
<template>
<DocSectionText v-bind="$attrs">
2023-11-08 08:33:18 +00:00
<p>Items with navigation are defined with templating to be able to use a router link component, an external link or programmatic navigation.</p>
2023-08-30 13:33:42 +00:00
</DocSectionText>
2024-05-20 12:14:38 +00:00
<div class="card flex justify-center">
<PanelMenu :model="items" class="w-full md:w-80">
2023-11-08 08:33:18 +00:00
<template #item="{ item }">
<router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
2024-05-20 12:14:38 +00:00
<a v-ripple class="flex items-center cursor-pointer text-surface-700 dark:text-surface-0 px-4 py-2" :href="href" @click="navigate">
2023-11-08 08:33:18 +00:00
<span :class="item.icon" />
2024-05-21 11:17:35 +00:00
<span class="ml-2">{{ item.label }}</span>
2023-11-08 08:33:18 +00:00
</a>
</router-link>
2024-05-20 12:14:38 +00:00
<a v-else v-ripple class="flex items-center cursor-pointer text-surface-700 dark:text-surface-0 px-4 py-2" :href="item.url" :target="item.target">
2023-11-08 08:33:18 +00:00
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
<span v-if="item.items" class="pi pi-angle-down text-primary ml-auto" />
</a>
</template>
</PanelMenu>
</div>
2024-01-30 08:16:35 +00:00
<DocSectionCode :code="code" hideStackBlitz />
2023-08-30 13:33:42 +00:00
</template>
2023-11-08 08:33:18 +00:00
<script>
export default {
data() {
return {
items: [
{
label: 'Router',
icon: 'pi pi-palette',
items: [
{
label: 'Styled',
icon: 'pi pi-eraser',
2024-05-07 19:25:46 +00:00
route: '/theming/styled'
2023-11-08 08:33:18 +00:00
},
{
label: 'Unstyled',
icon: 'pi pi-heart',
2024-05-02 10:42:38 +00:00
route: '/theming/unstyled'
2023-11-08 08:33:18 +00:00
}
]
},
{
label: 'Programmatic',
icon: 'pi pi-link',
command: () => {
2023-12-26 18:38:03 +00:00
this.$router.push('/introduction');
2023-11-08 08:33:18 +00:00
}
},
{
label: 'External',
icon: 'pi pi-home',
items: [
{
label: 'Vue.js',
icon: 'pi pi-star',
url: 'https://vuejs.org/'
},
{
label: 'Vite.js',
icon: 'pi pi-bookmark',
url: 'https://vuejs.org/'
}
]
}
],
code: {
basic: `
<PanelMenu :model="items">
<template #item="{ item }">
<router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
2024-05-20 12:14:38 +00:00
<a v-ripple class="flex items-center cursor-pointer text-surface-700 dark:text-surface-0 px-4 py-2" :href="href" @click="navigate">
2023-11-08 08:33:18 +00:00
<span :class="item.icon" />
2024-05-21 11:17:35 +00:00
<span class="ml-2">{{ item.label }}</span>
2023-11-08 08:33:18 +00:00
</a>
</router-link>
2024-05-20 12:14:38 +00:00
<a v-else v-ripple class="flex items-center cursor-pointer text-surface-700 dark:text-surface-0 px-4 py-2" :href="item.url" :target="item.target">
2023-11-08 08:33:18 +00:00
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
<span v-if="item.items" class="pi pi-angle-down text-primary ml-auto" />
</a>
</template>
</PanelMenu>
`,
options: `
<template>
2024-05-20 12:14:38 +00:00
<div class="card flex justify-center">
<PanelMenu :model="items" class="w-full md:w-80">
2023-11-08 08:33:18 +00:00
<template #item="{ item }">
<router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
2024-05-20 12:14:38 +00:00
<a v-ripple class="flex items-center cursor-pointer text-surface-700 dark:text-surface-0 px-4 py-2" :href="href" @click="navigate">
2023-11-08 08:33:18 +00:00
<span :class="item.icon" />
2024-05-21 11:17:35 +00:00
<span class="ml-2">{{ item.label }}</span>
2023-11-08 08:33:18 +00:00
</a>
</router-link>
2024-05-20 12:14:38 +00:00
<a v-else v-ripple class="flex items-center cursor-pointer text-surface-700 dark:text-surface-0 px-4 py-2" :href="item.url" :target="item.target">
2023-11-08 08:33:18 +00:00
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
<span v-if="item.items" class="pi pi-angle-down text-primary ml-auto" />
</a>
</template>
</PanelMenu>
</div>
</template>
<script>
export default {
data() {
return {
items: [
{
label: 'Router',
icon: 'pi pi-palette',
items: [
{
label: 'Styled',
icon: 'pi pi-eraser',
2024-05-07 19:25:46 +00:00
route: '/theming/styled'
2023-11-08 08:33:18 +00:00
},
{
label: 'Unstyled',
icon: 'pi pi-heart',
2024-05-02 10:42:38 +00:00
route: '/theming/unstyled'
2023-11-08 08:33:18 +00:00
}
]
},
{
label: 'Programmatic',
icon: 'pi pi-link',
command: () => {
2023-12-26 18:38:03 +00:00
this.$router.push('/introduction');
2023-11-08 08:33:18 +00:00
}
},
{
label: 'External',
icon: 'pi pi-home',
items: [
{
label: 'Vue.js',
icon: 'pi pi-star',
url: 'https://vuejs.org/'
},
{
label: 'Vite.js',
icon: 'pi pi-bookmark',
url: 'https://vuejs.org/'
}
]
}
]
};
}
};
<\/script>
`,
composition: `
<template>
2024-05-20 12:14:38 +00:00
<div class="card flex justify-center">
<PanelMenu :model="items" class="w-full md:w-80">
2023-11-08 08:33:18 +00:00
<template #item="{ item }">
<router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
2024-05-20 12:14:38 +00:00
<a v-ripple class="flex items-center cursor-pointer text-surface-700 dark:text-surface-0 px-4 py-2" :href="href" @click="navigate">
2023-11-08 08:33:18 +00:00
<span :class="item.icon" />
2024-05-21 11:17:35 +00:00
<span class="ml-2">{{ item.label }}</span>
2023-11-08 08:33:18 +00:00
</a>
</router-link>
2024-05-20 12:14:38 +00:00
<a v-else v-ripple class="flex items-center cursor-pointer text-surface-700 dark:text-surface-0 px-4 py-2" :href="item.url" :target="item.target">
2023-11-08 08:33:18 +00:00
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
<span v-if="item.items" class="pi pi-angle-down text-primary ml-auto" />
</a>
</template>
</PanelMenu>
</div>
</template>
<script setup>
import { ref } from "vue";
2024-02-13 10:43:23 +00:00
import { useRouter } from 'vue-router';
2023-11-08 08:33:18 +00:00
const router = useRouter();
const items = ref([
{
label: 'Router',
icon: 'pi pi-palette',
items: [
{
label: 'Styled',
icon: 'pi pi-eraser',
2024-05-07 19:25:46 +00:00
route: '/theming/styled'
2023-11-08 08:33:18 +00:00
},
{
label: 'Unstyled',
icon: 'pi pi-heart',
2024-05-02 10:42:38 +00:00
route: '/theming/unstyled'
2023-11-08 08:33:18 +00:00
}
]
},
{
label: 'Programmatic',
icon: 'pi pi-link',
command: () => {
2023-12-26 18:38:03 +00:00
router.push('/introduction');
2023-11-08 08:33:18 +00:00
}
},
{
label: 'External',
icon: 'pi pi-home',
items: [
{
label: 'Vue.js',
icon: 'pi pi-star',
url: 'https://vuejs.org/'
},
{
label: 'Vite.js',
icon: 'pi pi-bookmark',
url: 'https://vuejs.org/'
}
]
}
]);
<\/script>
`
}
};
}
};
</script>