primevue-mirror/apps/showcase/doc/picklist/TemplateDoc.vue

129 lines
4.9 KiB
Vue
Raw Normal View History

2024-04-02 08:38:38 +00:00
<template>
<DocSectionText v-bind="$attrs">
2024-05-30 11:10:35 +00:00
<p>For custom content support define an <i>option</i> template that gets the item instance as a parameter. In addition <i>sourceheader</i> and <i>targetheader</i> slots are provided for further customization.</p>
2024-04-02 08:38:38 +00:00
</DocSectionText>
<div class="card">
<PickList v-model="products" dataKey="id" breakpoint="1400px" scrollHeight="20rem">
2024-05-30 11:10:35 +00:00
<template #option="{ option, selected }">
2024-05-30 00:00:59 +00:00
<div class="flex flex-wrap p-1 items-center gap-4 w-full">
2024-05-30 11:10:35 +00:00
<img class="w-12 shrink-0 rounded" :src="'https://primefaces.org/cdn/primevue/images/product/' + option.image" :alt="option.name" />
<div class="flex-1 flex flex-col">
2024-05-30 11:10:35 +00:00
<span class="font-medium text-sm">{{ option.name }}</span>
<span :class="['text-sm', { 'text-surface-500 dark:text-surface-400': !selected, 'text-inherit': selected }]">{{ option.category }}</span>
2024-04-02 08:38:38 +00:00
</div>
2024-05-30 11:10:35 +00:00
<span class="font-bold">${{ option.price }}</span>
2024-04-02 08:38:38 +00:00
</div>
</template>
</PickList>
</div>
<DocSectionCode :code="code" v-bind="$attrs" :service="['ProductService']" />
</template>
<script>
import { ProductService } from '@/service/ProductService';
export default {
data() {
return {
products: null,
code: {
basic: `
<PickList v-model="products" dataKey="id" breakpoint="1400px" scrollHeight="20rem>
2024-05-30 11:10:35 +00:00
<template #option="{ option , selected }">
2024-05-30 00:00:59 +00:00
<div class="flex flex-wrap p-1 items-center gap-4 w-full">
2024-05-30 11:10:35 +00:00
<img class="w-12 shrink-0 rounded" :src="'https://primefaces.org/cdn/primevue/images/product/' + option.image" :alt="option.name" />
<div class="flex-1 flex flex-col">
2024-05-30 11:10:35 +00:00
<span class="font-medium text-sm">{{ option.name }}</span>
<span :class="['text-sm', { 'text-surface-500 dark:text-surface-400': !selected, 'text-inherit': selected }]">{{ option.category }}</span>
2024-04-02 08:38:38 +00:00
</div>
2024-05-30 11:10:35 +00:00
<span class="font-bold">\${{ option.price }}</span>
2024-04-02 08:38:38 +00:00
</div>
</template>
</PickList>
`,
options: `
<template>
<div class="card">
<PickList v-model="products" dataKey="id" breakpoint="1400px" scrollHeight="20rem>
2024-05-30 11:10:35 +00:00
<template #option="{ option , selected }">
2024-05-30 00:00:59 +00:00
<div class="flex flex-wrap p-1 items-center gap-4 w-full">
2024-05-30 11:10:35 +00:00
<img class="w-12 shrink-0 rounded" :src="'https://primefaces.org/cdn/primevue/images/product/' + option.image" :alt="option.name" />
<div class="flex-1 flex flex-col">
2024-05-30 11:10:35 +00:00
<span class="font-medium text-sm">{{ option.name }}</span>
<span :class="['text-sm', { 'text-surface-500 dark:text-surface-400': !selected, 'text-inherit': selected }]">{{ option.category }}</span>
2024-04-02 08:38:38 +00:00
</div>
2024-05-30 11:10:35 +00:00
<span class="font-bold">\${{ option.price }}</span>
2024-04-02 08:38:38 +00:00
</div>
</template>
</PickList>
</div>
</template>
<script>
import { ProductService } from '@/service/ProductService'
export default {
data() {
return {
products: null
}
},
mounted() {
ProductService.getProductsSmall().then((data) => (this.products = [data, []]));
}
};
<\/script>
`,
composition: `
<template>
<div class="card">
<PickList v-model="products" dataKey="id" breakpoint="1400px">
2024-05-30 11:10:35 +00:00
<template #option="{ option , selected }">
<div class="flex flex-wrap p-1 items-center gap-4 w-full">
2024-05-30 11:10:35 +00:00
<img class="w-12 shrink-0 rounded" :src="'https://primefaces.org/cdn/primevue/images/product/' + option.image" :alt="option.name" />
<div class="flex-1 flex flex-col">
2024-05-30 11:10:35 +00:00
<span class="font-medium text-sm">{{ option.name }}</span>
<span :class="['text-sm', { 'text-surface-500 dark:text-surface-400': !selected, 'text-inherit': selected }]">{{ option.category }}</span>
2024-04-02 08:38:38 +00:00
</div>
2024-05-30 11:10:35 +00:00
<span class="font-bold">\${{ option.price }}</span>
2024-04-02 08:38:38 +00:00
</div>
</template>
</PickList>
</div>
</template>
<script setup>
import { ref, onMounted } from 'vue';
import { ProductService } from '@/service/ProductService'
const products = ref(null);
onMounted(() => {
ProductService.getProductsSmall().then((data) => (products.value = [data, []]));
});
<\/script>
`,
data: `
/* ProductService */
{
id: '1000',
code: 'f230fh0g3',
name: 'Bamboo Watch',
description: 'Product Description',
image: '/bamboo-watch.jpg',
price: 65,
category: 'Accessories',
quantity: 24,
inventoryStatus: 'INSTOCK',
rating: 5
},
...
`
}
};
},
mounted() {
ProductService.getProductsSmall().then((data) => (this.products = [data, []]));
}
};
</script>