WlConfirmDialog

A confirmation dialog with accept/reject buttons. Set tone in useWlConfirm().confirm(); confirmDanger remains a danger alias. Install WlConfirmationService and one WlConfirmDialog at the application root.
Components / Feedback v0.2.0

Change props to see the result: the example and code use the same settings. “Reset” restores the initial values.

Settings

Configure the container in App.vue. Call the service here to see the result.

Example

Material was not deleted.

Focus: outside the example · pointer: outside the example

Explore the live example and copy its Vue SFC into your application. Settings on the left can be combined.

Code for your application

Vue SFC · current settings
<script setup lang="ts">
import { useWlConfirm, WlButton } from "legato-ui";
import { ref } from "vue";
const confirm = useWlConfirm();
const removed = ref(false);
</script>

<template>
  <div class="wl-stack" data-space="md">
    <!-- Mount WlConfirmDialog once in App.vue. -->
    <WlButton
      variant="primary"
      tone="danger"
      @click="confirm.confirm({
        tone: 'danger', header: 'Delete material?',
        message: 'Deletion cannot be undone.',
        acceptLabel: 'Delete', rejectLabel: 'Cancel',
        accept: () => removed = true
      })"
    >{{ "Delete material" }}</WlButton>
    <p class="wl-text-small" role="status">
      {{ removed ? "Material deleted." : "Material was not deleted." }}
    </p>
  </div>
</template>

Add one container in App.vue and configure motion and pt there. Each Vue application has its own service state.

Action and deletion confirmation

Confirm with tone, custom accept/reject labels, cancellation, local result and repeating the example. The legacy confirmDanger alias remains supported.

Choose an action.

Use confirm with tone: danger for a destructive action; the default is accent. confirmDanger remains a compatible alias. The application owns accept/reject handlers.

Vue SFC · additional example
<script setup lang="ts">
import { useWlConfirm, WlButton } from "legato-ui";
import { ref } from "vue";
// Install WlConfirmationService and mount one WlConfirmDialog in the root.
const confirm = useWlConfirm();
const removed = ref(false);
const result = ref("Choose an action.");
function share(): void {
  confirm.confirm({ header: "Share the plan?", message: "Only the local status changes in this example.", acceptLabel: "Share", rejectLabel: "Not now", accept: () => result.value = "The plan is marked as shared.", reject: () => result.value = "Publication cancelled." });
}
function remove(): void {
  confirm.confirm({ tone: "danger", header: "Delete draft?", message: "Save any data you need before deleting.", acceptLabel: "Delete draft", rejectLabel: "Keep", accept: () => {
    removed.value = true;
    result.value = "Draft deleted in the local example.";
  }, reject: () => result.value = "Draft kept." });
}
</script>

<template>
  <div class="wl-stack" data-space="lg">
    <div class="wl-inline" data-space="sm">
      <WlButton @click="share">{{ "Share plan" }}</WlButton>
      <WlButton
        variant="primary"
        tone="danger"
        :disabled="removed"
        @click="remove"
      >
        {{ "Delete with confirmation" }}
      </WlButton>
      <WlButton
        v-if="removed"
        variant="ghost"
        @click="removed = false; result = 'Draft restored to try again.'"
      >{{ "Repeat example" }}</WlButton>
    </div>
    <p class="wl-text-small" role="status">{{ result }}</p>
    <p class="wl-text-small wl-text-muted">{{ "Use confirm with tone: danger for a destructive action; the default is accent. confirmDanger remains a compatible alias. The application owns accept/reject handlers." }}</p>
  </div>
</template>

Connecting the service

Register WlConfirmationService with the Vue application and add one WlConfirmDialog to App.vue. Each application has its own service state. Import styles as described in the installation section.

main.ts · service and container
import { createApp } from "vue";
import { WlConfirmationService } from "legato-ui";
import App from "./App.vue";
const app = createApp(App);
app.use(WlConfirmationService);
app.mount("#app");

// One container in the root App.vue: WlConfirmDialog.
// import { WlConfirmDialog } from "legato-ui";
// <WlConfirmDialog />