primevue-mirror/doc/steps/BasicDoc.vue

197 lines
6.4 KiB
Vue
Raw Normal View History

2023-02-28 08:29:30 +00:00
<template>
<DocSectionText v-bind="$attrs">
<p>Steps requires a collection of menuitems as its <i>model</i>.</p>
</DocSectionText>
<div class="card">
2023-08-31 14:02:09 +00:00
<Steps
:model="items"
aria-label="Form Steps"
:readonly="false"
:pt="{
menuitem: ({ context }) => ({
class: isActive(context.item) && 'p-highlight p-steps-current'
})
}"
>
2023-08-30 14:38:19 +00:00
<template #item="{ label, item, index, props }">
<router-link v-if="item.route" v-slot="routerProps" :to="item.route" custom>
<a :href="routerProps.href" v-bind="props.action" @click="($event) => routerProps.navigate($event)" @keydown.enter="($event) => routerProps.navigate($event)">
<span v-bind="props.step">{{ index + 1 }}</span>
<span v-bind="props.label">{{ label }}</span>
</a>
</router-link>
</template>
</Steps>
2023-02-28 08:29:30 +00:00
</div>
<DocSectionCode :code="code" />
</template>
<script>
export default {
data() {
return {
items: [
{
label: 'Personal',
route: '/steps/'
2023-02-28 08:29:30 +00:00
},
{
label: 'Seat',
2023-08-30 14:38:19 +00:00
route: '/steps/seat'
2023-02-28 08:29:30 +00:00
},
{
label: 'Payment',
2023-08-30 14:38:19 +00:00
route: '/steps/payment'
2023-02-28 08:29:30 +00:00
},
{
label: 'Confirmation',
2023-08-30 14:38:19 +00:00
route: '/steps/confirmation'
2023-02-28 08:29:30 +00:00
}
],
code: {
2023-09-22 12:54:14 +00:00
basic: `
<Steps :model="items" aria-label="Form Steps" :readonly="false"
2023-08-31 14:02:09 +00:00
:pt="{
menuitem: ({ context }) => ({
class: isActive(context.item) && 'p-highlight p-steps-current'
})
}">
2023-08-30 14:38:19 +00:00
<template #item="{ label, item, index, props }">
<router-link v-if="item.route" v-slot="routerProps" :to="item.route" custom>
<a :href="routerProps.href" v-bind="props.action" @click="($event) => routerProps.navigate($event)" @keydown.enter="($event) => routerProps.navigate($event)">
<span v-bind="props.step">{{ index + 1 }}</span>
<span v-bind="props.label">{{ label }}</span>
</a>
</router-link>
<span v-else v-bind="props.action">
<span v-bind="props.step">{{ index + 1 }}</span>
<span v-bind="props.label">{{ label }}</span>
</span>
</template>
</Steps>`,
2023-09-22 12:54:14 +00:00
options: `
<template>
2023-02-28 08:29:30 +00:00
<div>
<div class="card">
2023-08-31 14:02:09 +00:00
<Steps :model="items" aria-label="Form Steps" :readonly="false"
:pt="{
menuitem: ({ context }) => ({
class: isActive(context.item) && 'p-highlight p-steps-current'
})
}">
2023-08-30 14:38:19 +00:00
<template #item="{ label, item, index, props }">
<router-link v-if="item.route" v-slot="routerProps" :to="item.route" custom>
<a :href="routerProps.href" v-bind="props.action" @click="($event) => routerProps.navigate($event)" @keydown.enter="($event) => routerProps.navigate($event)">
<span v-bind="props.step">{{ index + 1 }}</span>
<span v-bind="props.label">{{ label }}</span>
</a>
</router-link>
<span v-else v-bind="props.action">
<span v-bind="props.step">{{ index + 1 }}</span>
<span v-bind="props.label">{{ label }}</span>
</span>
</template>
</Steps>
2023-02-28 08:29:30 +00:00
</div>
</div>
</template>
<script>
export default {
data() {
return {
items: [
{
label: 'Personal',
route: '/'
2023-02-28 08:29:30 +00:00
},
{
label: 'Seat',
route: '/seat'
2023-02-28 08:29:30 +00:00
},
{
label: 'Payment',
route: '/payment'
2023-02-28 08:29:30 +00:00
},
{
label: 'Confirmation',
route: '/confirmation'
2023-02-28 08:29:30 +00:00
}
]
}
2023-08-31 14:02:09 +00:00
},
methods: {
isActive(item) {
return item.route ? this.$router.resolve(item.route).path === this.$route.path : false;
}
2023-02-28 08:29:30 +00:00
}
}
<\/script>`,
2023-09-22 12:54:14 +00:00
composition: `
<template>
2023-02-28 08:29:30 +00:00
<div>
<div class="card">
2023-08-31 14:02:09 +00:00
<Steps :model="items" aria-label="Form Steps" :readonly="false"
:pt="{
menuitem: ({ context }) => ({
class: isActive(context.item) && 'p-highlight p-steps-current'
})
}">
2023-08-30 14:38:19 +00:00
<template #item="{ label, item, index, props }">
<router-link v-if="item.route" v-slot="routerProps" :to="item.route" custom>
<a :href="routerProps.href" v-bind="props.action" @click="($event) => routerProps.navigate($event)" @keydown.enter="($event) => routerProps.navigate($event)">
<span v-bind="props.step">{{ index + 1 }}</span>
<span v-bind="props.label">{{ label }}</span>
</a>
</router-link>
<span v-else v-bind="props.action">
<span v-bind="props.step">{{ index + 1 }}</span>
<span v-bind="props.label">{{ label }}</span>
</span>
</template>
</Steps>
2023-02-28 08:29:30 +00:00
</div>
</div>
</template>
<script setup>
import { ref } from "vue";
2023-08-31 14:02:09 +00:00
import { useRouter, useRoute } from "vue-router";
const router = useRouter();
const route = useRoute();
2023-02-28 08:29:30 +00:00
const items = ref([
{
label: 'Personal',
2023-08-30 14:38:19 +00:00
route: "/"
2023-02-28 08:29:30 +00:00
},
{
label: 'Seat',
2023-08-30 14:38:19 +00:00
route: "/seat",
2023-02-28 08:29:30 +00:00
},
{
label: 'Payment',
2023-08-30 14:38:19 +00:00
route: "/payment",
2023-02-28 08:29:30 +00:00
},
{
label: 'Confirmation',
2023-08-30 14:38:19 +00:00
route: "/confirmation",
2023-02-28 08:29:30 +00:00
}
]);
2023-08-31 14:02:09 +00:00
const isActive = (item) => {
return item.route ? router.resolve(item.route).path === route.path : false;
}
2023-02-28 08:29:30 +00:00
<\/script>`
}
};
2023-08-31 14:02:09 +00:00
},
methods: {
isActive(item) {
return item.route ? this.$router.resolve(item.route).path === this.$route.path : false;
}
2023-02-28 08:29:30 +00:00
}
};
</script>