v0.0.2
Demos (demo panel, opens in a new tab)

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

Basic usage: view
BLADE

State what will be deleted with title and description, and name the confirm button after the action with confirm-text ("Delete" rather than "Confirm").

blade
<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"
/>
PropValues
titleDefault: Are you sure? (in the app language)
descriptionDescription text
confirm-textDefault: Confirm
cancel-textDefault: Cancel

Listening for the confirmation

Listening for the confirmation: view
BLADE

When the slot is empty, the confirm button closes the window and emits {name}-confirmed; start the action by listening for it with .window.

blade
<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"
/>
PropValues
{name}-confirmedEvent emitted on confirmation

Your own confirm button

Your own confirm button: view
BLADE

A button you put in the slot replaces the default confirm button; close the window yourself with zb:modal.close or close().

blade
<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

BLADE

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.

blade
<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'); } --}}
PropValues
close-actionLivewire method called when the user closes the window

Opening with modal.trigger

Opening with modal.trigger: view
BLADE

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.

blade
<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?

PropTypeDefaultDescription
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—nullDescription text
confirm-text—ConfirmText of the default confirm button (when the slot is empty)
cancel-text—CancelText of the cancel button
close-action—nullLivewire 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

Events, hooks and details
  • It is built on zb:modal: opening, closing and focus behave the same way, and it opens by name with zb:modal.trigger, the zb:modal:open event or ZubazarUI.modal.open('name').
  • With your own button in the slot, confirm-text is not used and {name}-confirmed is not sent. The old event names open-modal and close-modal still work.

Events

EventdetailDescription
{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.
Zubazar UI · ZubazarDesigned for people.