primevue-mirror/doc/metergroup/TemplatingDoc.vue

154 lines
5.9 KiB
Vue
Raw Normal View History

2024-01-11 13:46:09 +00:00
<template>
<DocSectionText v-bind="$attrs">
<p>
MeterGroup offers meter customization with the <i>meter</i> template that receives the meter instance from the value as a parameter and also <i>label</i> template receives value instance. In addition, the <i>start</i> and <i>end</i> slots
are available to define the start and end templating for MeterGroup respectively.
</p>
</DocSectionText>
<div class="card">
<MeterGroup :value="value" labelPosition="start">
<template #label="{ value }">
<div class="flex flex-column text-sm gap-2">
<template v-for="(val, i) of value" :key="i">
<span :style="{ color: val.color }" class="flex gap-2">
<i :class="val.icon" />
{{ val.label }} ({{ val.value }}%)</span
>
</template>
</div>
</template>
<template #start="{ totalPercent }">
2024-01-12 12:26:52 +00:00
<div class="flex justify-content-between mt-3 mb-2">
<span>Account </span>
2024-01-18 12:55:13 +00:00
<span :style="{ width: totalPercent + '%' }" class="absolute text-right">{{ totalPercent }}%</span>
2024-01-11 13:46:09 +00:00
<span>Savings: 1000$ </span>
</div>
</template>
<template #meter="slotProps">
2024-01-18 12:55:13 +00:00
<span :class="slotProps.class" :style="{ backgroundColor: slotProps.value.color, width: slotProps.size }" />
2024-01-11 13:46:09 +00:00
</template>
</MeterGroup>
</div>
<DocSectionCode :code="code" />
</template>
<script>
export default {
data() {
return {
value: [
{ color: '#239EF0', label: 'Mortgage', value: 25, icon: 'pi pi-home' },
{ color: '#FAA419', label: 'Loan', value: 15, icon: 'pi pi-money-bill' },
{ color: '#EE5879', label: 'Credit Card', value: 20, icon: 'pi pi-credit-card' }
],
code: {
basic: `
<MeterGroup :value="value" labelPosition="start">
<template #label="{ value }">
2024-01-18 12:55:13 +00:00
<div class="flex flex-column text-sm gap-2">
2024-01-11 13:46:09 +00:00
<template v-for="(val, i) of value" :key="i">
2024-01-18 12:55:13 +00:00
<span :style="{ color: val.color }" class="flex gap-2">
<i :class="val.icon" />
{{ val.label }} ({{ val.value }}%)</span
>
2024-01-11 13:46:09 +00:00
</template>
</div>
</template>
<template #start="{ totalPercent }">
2024-01-12 12:44:53 +00:00
<div class="flex justify-content-between mt-3 mb-2">
<span>Account </span>
2024-01-18 12:55:13 +00:00
<span :style="{ width: totalPercent + '%' }" class="absolute text-right">{{ totalPercent }}%</span>
2024-01-11 13:46:09 +00:00
<span>Savings: 1000$ </span>
</div>
</template>
<template #meter="slotProps">
2024-01-18 12:55:13 +00:00
<span :class="slotProps.class" :style="{ backgroundColor: slotProps.value.color, width: slotProps.size }" />
2024-01-11 13:46:09 +00:00
</template>
</MeterGroup>
`,
options: `
<template>
<div class="card">
<MeterGroup :value="value" labelPosition="start">
<template #label="{ value }">
2024-01-18 12:55:13 +00:00
<div class="flex flex-column text-sm gap-2">
2024-01-11 13:46:09 +00:00
<template v-for="(val, i) of value" :key="i">
2024-01-18 12:55:13 +00:00
<span :style="{ color: val.color }" class="flex gap-2">
<i :class="val.icon" />
{{ val.label }} ({{ val.value }}%)</span
>
2024-01-11 13:46:09 +00:00
</template>
</div>
</template>
<template #start="{ totalPercent }">
2024-01-12 12:44:53 +00:00
<div class="flex justify-content-between mt-3 mb-2">
<span>Account </span>
2024-01-18 12:55:13 +00:00
<span :style="{ width: totalPercent + '%' }" class="absolute text-right">{{ totalPercent }}%</span>
2024-01-11 13:46:09 +00:00
<span>Savings: 1000$ </span>
</div>
</template>
<template #meter="slotProps">
2024-01-18 12:55:13 +00:00
<span :class="slotProps.class" :style="{ backgroundColor: slotProps.value.color, width: slotProps.size }" />
2024-01-11 13:46:09 +00:00
</template>
</MeterGroup>
</div>
</template>
<script>
export default {
data() {
return {
value: [
{ color: '#239EF0', label: 'Mortgage', value: 25 },
{ color: '#FAA419', label: 'Loan', value: 15 },
{ color: '#EE5879', label: 'Credit Card', value: 20 }
]
};
}
};
<\/script>
`,
composition: `
<template>
<div class="card">
<MeterGroup :value="value" labelPosition="start">
<template #label="{ value }">
2024-01-18 12:55:13 +00:00
<div class="flex flex-column text-sm gap-2">
2024-01-11 13:46:09 +00:00
<template v-for="(val, i) of value" :key="i">
2024-01-18 12:55:13 +00:00
<span :style="{ color: val.color }" class="flex gap-2">
<i :class="val.icon" />
{{ val.label }} ({{ val.value }}%)</span
>
2024-01-11 13:46:09 +00:00
</template>
</div>
</template>
<template #start="{ totalPercent }">
2024-01-12 12:44:53 +00:00
<div class="flex justify-content-between mt-3 mb-2">
<span>Account </span>
2024-01-18 12:55:13 +00:00
<span :style="{ width: totalPercent + '%' }" class="absolute text-right">{{ totalPercent }}%</span>
2024-01-11 13:46:09 +00:00
<span>Savings: 1000$ </span>
</div>
</template>
<template #meter="slotProps">
2024-01-18 12:55:13 +00:00
<span :class="slotProps.class" :style="{ backgroundColor: slotProps.value.color, width: slotProps.size }" />
2024-01-11 13:46:09 +00:00
</template>
</MeterGroup>
</div>
</template>
<script setup>
import { ref } from "vue";
const value = ref([
{ color: '#239EF0', label: 'Mortgage', value: 25 },
{ color: '#FAA419', label: 'Loan', value: 15 },
{ color: '#EE5879', label: 'Credit Card', value: 20 }
]);
<\/script>
`
}
};
}
};
</script>