Confirmation dialog
A narrow window that asks the user one last time before an action that cannot be undone, such as deleting.
zb:confirmation-dialog zubazar/ui · free (MIT)
Basic usage
State what will be deleted with title and description, and name the confirm button after the action with confirm-text ("Delete" rather than "Confirm").
<zb:modal.trigger name="catalog-product-delete"><zb:button variant="outline-danger">Delete the product</zb:button></zb:modal.trigger>
<zb:confirmation-dialog
name="catalog-product-delete"
title="Delete the product"
description="Are you sure you want to delete the 'Wireless headphones' product? This cannot be undone."
confirm-text="Delete"
/>
| Prop | Values |
|---|---|
title | Default: Are you sure? (in the app language) |
description | Description text |
confirm-text | Default: Confirm |
cancel-text | Default: Cancel |
Listening for the confirmation
When the slot is empty, the confirm button closes the window and emits {name}-confirmed; start the action by listening for it with .window.
<div x-data x-on:catalog-product-archive-confirmed.window="$dispatch('toast', { type: 'success', message: 'Product archived.' })">
<zb:modal.trigger name="catalog-product-archive"><zb:button variant="white">Archive</zb:button></zb:modal.trigger>
</div>
<zb:confirmation-dialog
name="catalog-product-archive"
title="Archive the product"
description="An archived product does not appear in the store; its sales records are kept."
confirm-text="Archive"
/>
| Prop | Values |
|---|---|
{name}-confirmed | Event emitted on confirmation |
Your own confirm button
A button you put in the slot replaces the default confirm button; close the window yourself with zb:modal.close or close().
<zb:modal.trigger name="catalog-customer-delete"><zb:button variant="outline-danger">Delete the customer</zb:button></zb:modal.trigger>
<zb:confirmation-dialog name="catalog-customer-delete" title="Delete the customer permanently" description="The customer's entire order history will be deleted as well.">
<zb:modal.close><zb:button variant="danger" x-on:click="$dispatch('toast', { type: 'success', message: 'Customer deleted.' })">Delete permanently</zb:button></zb:modal.close>
</zb:confirmation-dialog>
With Livewire
Give the confirm button a wire:click and send zb:modal:close from the server when the action finishes; use close-action to clear state on cancel.
<zb:confirmation-dialog name="delete-product" title="Delete the product" description="This cannot be undone." close-action="clearProductToDelete">
<zb:button variant="danger" wire:click="delete">Delete</zb:button>
</zb:confirmation-dialog>
{{-- In the component: public function delete(): void { … $this->dispatch('zb:modal:close', name: 'delete-product'); } --}}
| Prop | Values |
|---|---|
close-action | Livewire method called when the user closes the window |
Opening with modal.trigger
Open the dialog with zb:modal.trigger and wrap the confirm button in zb:modal.close; a click runs the action and closes the window.
<zb:modal.trigger name="delete-product">
<zb:button variant="danger">Delete the product</zb:button>
</zb:modal.trigger>
<zb:confirmation-dialog name="delete-product" title="Delete the product?" description="The product's 24 variants and stock records are removed as well. This cannot be undone.">
<zb:modal.close>
<zb:button variant="danger" x-on:click="$dispatch('toast', { type: 'success', message: 'Product deleted.' })">Delete</zb:button>
</zb:modal.close>
</zb:confirmation-dialog>
Props
The values the component takes. What are props and slots?
| Prop | Type | Default | Description |
|---|---|---|---|
name | — | — | Required. The name used in the zb:modal:open event and the ZubazarUI.modal.open('…') call; {name}-confirmed is emitted on confirmation |
title | — | Are you sure? | Window title (default in the app language) |
description | — | null | Description text |
confirm-text | — | Confirm | Text of the default confirm button (when the slot is empty) |
cancel-text | — | Cancel | Text of the cancel button |
close-action | — | null | Livewire method called when the user closes the window |
Slots: default: the button(s) that replace the confirm button. The window width is always sm.
Developer notes
- It is built on
zb:modal: opening, closing and focus behave the same way, and it opens by name withzb:modal.trigger, thezb:modal:openevent orZubazarUI.modal.open('name'). - With your own button in the slot,
confirm-textis not used and{name}-confirmedis not sent. The old event namesopen-modalandclose-modalstill work.
Events
| Event | detail | Description |
|---|---|---|
{name}-confirmed | — | With an empty slot, the confirm button closes the dialog and sends this event from the button; it bubbles to window. Not sent when you put your own button in the slot. |
zb:modal:opened · zb:modal:closed | { name } | Built on zb:modal, so it sends the modal events too. |