Confirm dialog

A question before an action: it runs the action, shows its progress and errors, and offers Retry. Each app gives its texts and the action.

Delete

The app gives the texts and the action. While it runs the dialog cannot be closed; if it fails, it shows the error and offers Retry.

<script setup>
import { ref } from 'vue';
import ConfirmDialog from '@aisgroup/design/blocks/ConfirmDialog.vue';
import { Button } from '@aisgroup/design/ui/button';

const open = ref(true);
const fail = ref(false);
const wait = () => new Promise((resolve, reject) => setTimeout(() => (fail.value ? reject(new Error('The server did not answer')) : resolve()), 1200));
const start = (failing) => { fail.value = failing; open.value = true; };
</script>

<template>
  <div class="flex gap-2">
    <Button variant="outline" @click="start(false)">Delete model</Button>
    <Button variant="outline" @click="start(true)">Delete model, failing</Button>
    <ConfirmDialog
      v-if="open"
      title="Delete model"
      confirm-label="Delete"
      loading-label="Deleting..."
      error-title="The model could not be deleted"
      :action="wait"
      @close="open = false"
      @done="open = false"
    >
      <p class="text-sm">m-inspection-03 and its results will be deleted. This cannot be undone.</p>
    </ConfirmDialog>
  </div>
</template>

Type to confirm

For what cannot be recovered: the action stays disabled until the text matches.

<script setup>
import { ref } from 'vue';
import ConfirmDialog from '@aisgroup/design/blocks/ConfirmDialog.vue';
import { Button } from '@aisgroup/design/ui/button';

const open = ref(true);
const wait = () => new Promise(resolve => setTimeout(resolve, 1200));
</script>

<template>
  <Button variant="outline" @click="open = true">Delete dataset</Button>
  <ConfirmDialog
    v-if="open"
    title="Delete dataset"
    confirm-label="Delete"
    loading-label="Deleting..."
    confirm-text="tapones-linea-3"
    confirm-prompt="To confirm deletion, please type the dataset ID:"
    confirm-placeholder="Type dataset ID"
    mismatch-text="The dataset ID does not match"
    :action="wait"
    @close="open = false"
    @done="open = false"
  />
</template>

Confirm

Not only for deleting: another variant, and the action focused so Enter confirms.

<script setup>
import { ref } from 'vue';
import ConfirmDialog from '@aisgroup/design/blocks/ConfirmDialog.vue';
import { Button } from '@aisgroup/design/ui/button';

const open = ref(true);
const wait = () => new Promise(resolve => setTimeout(resolve, 1200));
</script>

<template>
  <Button variant="outline" @click="open = true">Restart Node-RED</Button>
  <ConfirmDialog
    v-if="open"
    title="Restart Node-RED"
    confirm-label="Restart"
    loading-label="Restarting..."
    variant="default"
    focus-confirm
    :action="wait"
    @close="open = false"
    @done="open = false"
  >
    <p class="text-sm">The panels will stop for a few seconds.</p>
  </ConfirmDialog>
</template>

Progress

A long action: the progress goes in its slot, and with background the only button is Continue, which leaves it running. The app closes the dialog and shows the progress elsewhere.

<script setup>
import { computed, ref } from 'vue';
import ConfirmDialog from '@aisgroup/design/blocks/ConfirmDialog.vue';
import { Button } from '@aisgroup/design/ui/button';
import { Progress } from '@aisgroup/design/ui/progress';
import { Spinner } from '@aisgroup/design/ui/spinner';

const TOTAL = 40;
const open = ref(true);
const done = ref(0);
const percent = computed(() => (done.value * 100) / TOTAL);

const action = () => new Promise((resolve) => {
  done.value = 0;
  const timer = setInterval(() => {
    done.value += 1;
    if (done.value === TOTAL) {
      clearInterval(timer);
      resolve();
    }
  }, 150);
});
</script>

<template>
  <Button variant="outline" @click="open = true">Delete 40 images</Button>
  <ConfirmDialog
    v-if="open"
    title="Delete images"
    confirm-label="Delete"
    loading-label="Deleting..."
    background
    :action="action"
    @close="open = false"
    @done="open = false"
    @background="open = false"
  >
    <p class="text-sm">40 images will be deleted. This cannot be undone.</p>
    <template #progress>
      <div class="flex flex-col gap-2">
        <p class="flex items-center gap-2 text-sm"><Spinner class="size-4 shrink-0 text-primary" />Deleting...</p>
        <Progress :model-value="percent" class="h-2" aria-label="Deleting" />
        <p class="text-sm text-muted-foreground tabular-nums">{{ done }} / {{ TOTAL }} images</p>
      </div>
    </template>
  </ConfirmDialog>
</template>

Type to search the guide.