Skip to content

confirm-dialog

Dialog for action confirmation like delete resource action

Usage

Simple usage

Composition Api

vue

<script setup>

const confirmDialog = ref(null)

async function confirm() {
  confirm = await confirmDialog.value.confirm()
  if(!confirm) { return }
}

</script>

<template>
  <!-- simple usage -->
  <WeConfirmDialog
    ref="confirmDialog"  
  />
  <!-- simple usage deletion dialog -->
  <WeConfirmDialog
    ref="confirmDialog"
    type="delete"
  />

  <!-- title and text -->
  <WeConfirmDialog
    ref="confirmDialog"  
    title="Title"
    text="Content"
  />

  <!-- custom default confirm and delete button (slot actions) -->

  <WeConfirmDialog ref="confirmDialog">
    <template #actions="{ resolve }">
      <v-btn @click="resolve(true)">
        Confirm btn custom
      </v-btn>
      <v-btn @click="resolve(false)">
        Cancel btn custom
      </v-btn>
    </template>
  </WeConfirmDialog>

  <!-- use full custom dialog (slot dialog) -->
  <we-confirm-dialog
    ref="confirmDialog"  
    type="confirm"
  >
    <template #dialog="{resolve}">
      <v-card>
        <v-card-title>
          Title
        </v-card-title>
        <v-card-text>
          Content
        </v-card-text>
        <template #cancel="{ resolve }">
          <v-btn @click="resolve(true)">
            Confirm
          </v-btn>
          <v-btn @click="resolve(false)"
          >
            Cancel
          </v-btn>
        </template>
      </v-card>
    </template>
  </we-confirm-dialog>
</template>
<script>

Legacy

vue


<template>
  <!-- simple usage -->
  <WeConfirmDialog
    ref="confirmDialog"  
  />
  <!-- simple usage deletion dialog -->
  <WeConfirmDialog
    ref="confirmDialog"
    type="delete"
  />

  <!-- title and text -->
  <WeConfirmDialog
    ref="confirmDialog"  
    title="Title"
    text="Content"
  />

  <!-- custom default confirm and delete button (slot actions) -->

  <WeConfirmDialog ref="confirmDialog">
    <template #actions="{ resolve }">
      <v-btn @click="resolve(true)">
        Confirm btn custom
      </v-btn>
      <v-btn @click="resolve(false)">
        Cancel btn custom
      </v-btn>
    </template>
  </WeConfirmDialog>

  <!-- use full custom dialog (slot dialog) -->
  <we-confirm-dialog
    ref="confirmDialog"  
    type="custom"
  >
    <template #dialog="{resolve}">
      <v-card>
        <v-card-title>
          Title
        </v-card-title>
        <v-card-text>
          Content
        </v-card-text>
        <v-btn @click="resolve(true)">
          Confirm
        </v-btn>
        <v-btn @click="resolve(false)"
        >
          Cancel
        </v-btn>
      </v-card>
    </template>
  </we-confirm-dialog>
</template>
<script>

export default {
  methods: {
    action() {
      const confirm = await this.$refs.confirmDialog.confirm()
      if(!confirm) { return }

      // execute action
    }
  }
};

</script>

TIP

You can use resolve() function on button when slots dialog/footer/buttons is used

Props

NameTypeDefaultDescription
typeString
confirm
Set defaults for title/text/icon/color.
Types: ['confirm', 'delete', 'custom']
titleString
undefined
Title of the dialog
textString
undefined
Content of the dialog
confirmButtonTextString
undefined
Confirm button text
cancelButtonTextString
undefined
Cancel button text
iconString
undefined
Confirm button icon
colorString
undefined
Confirm button color

Slots

NameDescription
contentDialog content slot
actionsDialog actions slot

WARNING

Compared with the previous version, this management has been simplified; the following slots are no longer used:

  • header
  • title
  • text
  • footer
  • buttons

Methods

NameDescription
confirm()Promise that return (if resolved) `true/false` based on the user input