primevue-mirror/doc/confirmpopup/TemplateDoc.vue

144 lines
5.0 KiB
Vue

<template>
<DocSectionText v-bind="$attrs">
<p>Templating allows customizing the message content.</p>
</DocSectionText>
<ConfirmPopup group="templating">
<template #message="slotProps">
<div class="flex flex-column align-items-center w-full gap-3 border-bottom-1 surface-border p-3 mb-3">
<i :class="slotProps.message.icon" class="text-6xl text-primary-500"></i>
<p>{{ slotProps.message.message }}</p>
</div>
</template>
</ConfirmPopup>
<div class="card flex justify-content-center">
<Button @click="showTemplate($event)" icon="pi pi-check" label="Confirm"></Button>
</div>
<DocSectionCode :code="code" />
</template>
<script>
export default {
data() {
return {
code: {
basic: `
<ConfirmPopup group="templating">
<template #message="slotProps">
<div class="flex flex-column align-items-center w-full gap-3 border-bottom-1 surface-border p-3 mb-3">
<i :class="slotProps.message.icon" class="text-6xl text-primary-500"></i>
<p>{{ slotProps.message.message }}</p>
</div>
</template>
</ConfirmPopup>
<Button @click="showTemplate($event)" icon="pi pi-check" label="Confirm"></Button>
`,
options: `
<template>
<Toast />
<ConfirmPopup group="templating">
<template #message="slotProps">
<div class="flex flex-column align-items-center w-full gap-3 border-bottom-1 surface-border p-3 mb-3">
<i :class="slotProps.message.icon" class="text-6xl text-primary-500"></i>
<p>{{ slotProps.message.message }}</p>
</div>
</template>
</ConfirmPopup>
<div class="card flex justify-content-center">
<Button @click="showTemplate($event)" icon="pi pi-check" label="Confirm"></Button>
</div>
</template>
<script>
export default {
methods: {
showTemplate(event) {
this.$confirm.require({
target: event.currentTarget,
group: 'templating',
message: 'Please confirm to proceed moving forward.',
icon: 'pi pi-exclamation-circle',
acceptIcon: 'pi pi-check',
rejectIcon: 'pi pi-times',
rejectClass: 'p-button-sm',
acceptClass: 'p-button-outlined p-button-sm',
accept: () => {
this.$toast.add({ severity: 'info', summary: 'Confirmed', detail: 'You have accepted', life: 3000 });
},
reject: () => {
this.$toast.add({ severity: 'error', summary: 'Rejected', detail: 'You have rejected', life: 3000 });
}
});
}
}
};
<\/script>
`,
composition: `
<template>
<Toast />
<ConfirmPopup group="templating">
<template #message="slotProps">
<div class="flex flex-column align-items-center w-full gap-3 border-bottom-1 surface-border p-3 mb-3">
<i :class="slotProps.message.icon" class="text-6xl text-primary-500"></i>
<p>{{ slotProps.message.message }}</p>
</div>
</template>
</ConfirmPopup>
<div class="card flex justify-content-center">
<Button @click="showTemplate($event)" icon="pi pi-check" label="Confirm"></Button>
</div>
</template>
<script setup>
import { useConfirm } from "primevue/useconfirm";
import { useToast } from "primevue/usetoast";
const confirm = useConfirm();
const toast = useToast();
const showTemplate = (event) => {
confirm.require({
target: event.currentTarget,
group: 'templating',
message: 'Please confirm to proceed moving forward.',
icon: 'pi pi-exclamation-circle',
acceptIcon: 'pi pi-check',
rejectIcon: 'pi pi-times',
rejectClass: 'p-button-sm',
acceptClass: 'p-button-outlined p-button-sm',
accept: () => {
toast.add({severity:'info', summary:'Confirmed', detail:'You have accepted', life: 3000});
},
reject: () => {
toast.add({severity:'error', summary:'Rejected', detail:'You have rejected', life: 3000});
}
});
}
<\/script>
`
}
};
},
methods: {
showTemplate(event) {
this.$confirm.require({
target: event.currentTarget,
group: 'templating',
message: 'Please confirm to proceed moving forward.',
icon: 'pi pi-exclamation-circle',
acceptIcon: 'pi pi-check',
rejectIcon: 'pi pi-times',
rejectClass: 'p-button-sm',
acceptClass: 'p-button-outlined p-button-sm',
accept: () => {
this.$toast.add({ severity: 'info', summary: 'Confirmed', detail: 'You have accepted', life: 3000 });
},
reject: () => {
this.$toast.add({ severity: 'error', summary: 'Rejected', detail: 'You have rejected', life: 3000 });
}
});
}
}
};
</script>