All files / src/components ConfirmModal.vue

100% Statements 26/26
100% Branches 9/9
100% Functions 6/6
100% Lines 21/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97    132x           3x 3x   3x                       3x 3x   3x                                     118x                   118x         118x         118x 24x 5x 2x     118x 24x 5x     118x           118x             1x       3x      
<template>
  <div
    v-if="isOpen"
    class="modal fade show d-block"
    tabindex="-1"
    style="background-color: rgba(0, 0, 0, 0.5)"
    @click.self="cancel"
  >
    <div class="modal-dialog modal-dialog-centered">
      <div class="modal-content">
        <div class="modal-header" :class="headerClass">
          <h5 class="modal-title">
            <font-awesome-icon :icon="icon" class="me-2" />
            {{ title }}
          </h5>
          <button
            type="button"
            class="btn-close"
            :class="{ 'btn-close-white': variant === 'danger' }"
            :aria-label="t('common.close')"
            @click="cancel"
          ></button>
        </div>
        <div class="modal-body">
          <p class="mb-0">{{ message }}</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" @click="cancel">
            <font-awesome-icon icon="fa-solid fa-xmark" class="me-2" />
            {{ t('common.cancel') }}
          </button>
          <button type="button" :class="confirmBtnClass" @click="confirm">
            <font-awesome-icon :icon="confirmIcon" class="me-2" />
            {{ confirmLabel ?? t('common.confirm') }}
          </button>
        </div>
      </div>
    </div>
  </div>
</template>
 
<script setup lang="ts">
import { computed } from 'vue'
import { useUILanguage } from '@/composables/useUILanguage'
 
const { t } = useUILanguage()
 
interface Props {
  isOpen: boolean
  title: string
  message: string
  confirmLabel?: string
  variant?: 'danger' | 'warning' | 'primary'
}
 
const props = withDefaults(defineProps<Props>(), {
  confirmLabel: undefined,
  variant: 'danger'
})
 
const emit = defineEmits<{
  confirm: []
  cancel: []
}>()
 
const icon = computed(() => {
  if (props.variant === 'danger') return 'fa-solid fa-triangle-exclamation'
  if (props.variant === 'warning') return 'fa-solid fa-exclamation-circle'
  return 'fa-solid fa-question-circle'
})
 
const confirmIcon = computed(() => {
  if (props.variant === 'danger') return 'fa-solid fa-trash'
  return 'fa-solid fa-check'
})
 
const headerClass = computed(() => ({
  'bg-danger text-white': props.variant === 'danger',
  'bg-warning': props.variant === 'warning',
  'bg-primary text-white': props.variant === 'primary'
}))
 
const confirmBtnClass = computed(() => ({
  'btn btn-danger': props.variant === 'danger',
  'btn btn-warning': props.variant === 'warning',
  'btn btn-primary': props.variant === 'primary'
}))
 
function confirm() {
  emit('confirm')
}
 
function cancel() {
  emit('cancel')
}
</script>