|
| 1 | +<script setup lang="ts"> |
| 2 | +import BaseModal from '../BaseModal.vue' |
| 3 | +import AppButton from '../../Buttons/AppButton.vue' |
| 4 | +
|
| 5 | +import { computed } from 'vue' |
| 6 | +
|
| 7 | +const { |
| 8 | + title, |
| 9 | + description, |
| 10 | + type, |
| 11 | + confirmationText, |
| 12 | + abortText, |
| 13 | +} = defineProps<Props>() |
| 14 | +
|
| 15 | +const emit = defineEmits(['cancel', 'confirm']) |
| 16 | +
|
| 17 | +interface Props { |
| 18 | + title: string |
| 19 | + description: String |
| 20 | + type: String |
| 21 | + confirmationText: String |
| 22 | + abortText: String |
| 23 | +} |
| 24 | +
|
| 25 | +const buttonBackground = computed(() => { |
| 26 | + if (type === 'info') |
| 27 | + return 'bg-blue-600 hover:bg-blue-700 focus:ring-blue-500' |
| 28 | +
|
| 29 | + if (type === 'warning') |
| 30 | + return 'bg-yellow-600 hover:bg-yellow-700 focus:ring-yellow-500' |
| 31 | +
|
| 32 | + if (type === 'danger') |
| 33 | + return 'bg-red-600 hover:bg-red-700 focus:ring-red-500' |
| 34 | +
|
| 35 | + if (type === 'success') |
| 36 | + return 'bg-green-600 hover:bg-green-700 focus:ring-green-500' |
| 37 | +
|
| 38 | + return 'bg-white-600 hover:bg-gray-50 ' |
| 39 | +}) |
| 40 | +
|
| 41 | +function abortAction() { |
| 42 | + emit('cancel') |
| 43 | +} |
| 44 | +function confirmAction() { |
| 45 | + emit('confirm') |
| 46 | +} |
| 47 | +</script> |
| 48 | + |
| 49 | +<template> |
| 50 | + <BaseModal @close-modal="abortAction()"> |
| 51 | + <template #modal-body> |
| 52 | + <div class="absolute top-0 right-0 hidden pt-4 pr-4 sm:block"> |
| 53 | + <button |
| 54 | + type="button" |
| 55 | + class="text-gray-400 rounded-md dark:text-gray-200 dark-hover:text-gray-100 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-offset-2" |
| 56 | + @click="abortAction()" |
| 57 | + > |
| 58 | + <span class="sr-only">Close</span> |
| 59 | + <!-- Heroicon name: outline/x-mark --> |
| 60 | + <svg |
| 61 | + class="w-6 h-6" |
| 62 | + xmlns="http://www.w3.org/2000/svg" |
| 63 | + fill="none" |
| 64 | + viewBox="0 0 24 24" |
| 65 | + stroke-width="1.5" |
| 66 | + stroke="currentColor" |
| 67 | + aria-hidden="true" |
| 68 | + > |
| 69 | + <path |
| 70 | + stroke-linecap="round" |
| 71 | + stroke-linejoin="round" |
| 72 | + d="M6 18L18 6M6 6l12 12" |
| 73 | + /> |
| 74 | + </svg> |
| 75 | + </button> |
| 76 | + </div> |
| 77 | + |
| 78 | + <div class="sm:flex sm:items-start"> |
| 79 | + <div |
| 80 | + v-if="type === 'warning'" |
| 81 | + class="flex items-center justify-center flex-shrink-0 w-12 h-12 mx-auto bg-yellow-100 rounded-full sm:mx-0 sm:h-10 sm:w-10" |
| 82 | + > |
| 83 | + <!-- Heroicon name: outline/exclamation-triangle --> |
| 84 | + <svg |
| 85 | + class="w-6 h-6 text-yellow-600" |
| 86 | + xmlns="http://www.w3.org/2000/svg" |
| 87 | + fill="none" |
| 88 | + viewBox="0 0 24 24" |
| 89 | + stroke-width="1.5" |
| 90 | + stroke="currentColor" |
| 91 | + aria-hidden="true" |
| 92 | + > |
| 93 | + <path |
| 94 | + stroke-linecap="round" |
| 95 | + stroke-linejoin="round" |
| 96 | + d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z" |
| 97 | + /> |
| 98 | + </svg> |
| 99 | + </div> |
| 100 | + <div |
| 101 | + v-if="type === 'success'" |
| 102 | + class="flex items-center justify-center flex-shrink-0 w-12 h-12 mx-auto bg-green-100 rounded-full sm:mx-0 sm:h-10 sm:w-10" |
| 103 | + > |
| 104 | + <svg |
| 105 | + class="w-6 h-6 text-green-600" |
| 106 | + fill="none" |
| 107 | + stroke="currentColor" |
| 108 | + stroke-width="1.5" |
| 109 | + viewBox="0 0 24 24" |
| 110 | + xmlns="http://www.w3.org/2000/svg" |
| 111 | + aria-hidden="true" |
| 112 | + > |
| 113 | + <path |
| 114 | + stroke-linecap="round" |
| 115 | + stroke-linejoin="round" |
| 116 | + d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z" |
| 117 | + /> |
| 118 | + </svg> |
| 119 | + </div> |
| 120 | + <div |
| 121 | + v-if="type === 'error'" |
| 122 | + class="flex items-center justify-center flex-shrink-0 w-12 h-12 mx-auto bg-red-100 rounded-full sm:mx-0 sm:h-10 sm:w-10" |
| 123 | + > |
| 124 | + <svg |
| 125 | + class="w-6 h-6 text-red-600" |
| 126 | + fill="none" |
| 127 | + stroke="currentColor" |
| 128 | + stroke-width="1.5" |
| 129 | + viewBox="0 0 24 24" |
| 130 | + xmlns="http://www.w3.org/2000/svg" |
| 131 | + aria-hidden="true" |
| 132 | + > |
| 133 | + <path |
| 134 | + stroke-linecap="round" |
| 135 | + stroke-linejoin="round" |
| 136 | + d="M9.75 9.75l4.5 4.5m0-4.5l-4.5 4.5M21 12a9 9 0 11-18 0 9 9 0 0118 0z" |
| 137 | + /> |
| 138 | + </svg> |
| 139 | + </div> |
| 140 | + <div |
| 141 | + v-if="type === 'info'" |
| 142 | + class="flex items-center justify-center flex-shrink-0 w-12 h-12 mx-auto bg-blue-100 rounded-full sm:mx-0 sm:h-10 sm:w-10" |
| 143 | + > |
| 144 | + <svg |
| 145 | + class="w-6 h-6 text-blue-600" |
| 146 | + fill="none" |
| 147 | + stroke="currentColor" |
| 148 | + stroke-width="1.5" |
| 149 | + viewBox="0 0 24 24" |
| 150 | + xmlns="http://www.w3.org/2000/svg" |
| 151 | + aria-hidden="true" |
| 152 | + > |
| 153 | + <path |
| 154 | + stroke-linecap="round" |
| 155 | + stroke-linejoin="round" |
| 156 | + d="M11.25 11.25l.041-.02a.75.75 0 011.063.852l-.708 2.836a.75.75 0 001.063.853l.041-.021M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9-3.75h.008v.008H12V8.25z" |
| 157 | + /> |
| 158 | + </svg> |
| 159 | + </div> |
| 160 | + |
| 161 | + <div class="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left"> |
| 162 | + <h3 |
| 163 | + id="modal-title" |
| 164 | + class="text-lg font-medium leading-6 text-gray-900 dark:text-gray-100" |
| 165 | + > |
| 166 | + {{ title }} |
| 167 | + </h3> |
| 168 | + <div class="mt-2"> |
| 169 | + <p class="text-sm text-gray-500 dark:text-gray-400"> |
| 170 | + {{ description }} |
| 171 | + </p> |
| 172 | + </div> |
| 173 | + </div> |
| 174 | + </div> |
| 175 | + </template> |
| 176 | + |
| 177 | + <template #modal-actions> |
| 178 | + <AppButton |
| 179 | + :button-text="String(confirmationText)" |
| 180 | + loading-text="Confirming..." |
| 181 | + :passed-class="`primary-button ${buttonBackground}`" |
| 182 | + @click="confirmAction()" |
| 183 | + /> |
| 184 | + |
| 185 | + <button |
| 186 | + v-if="abortText" |
| 187 | + type="button" |
| 188 | + class="mr-4 secondary-button" |
| 189 | + @click="abortAction()" |
| 190 | + > |
| 191 | + {{ abortText }} |
| 192 | + </button> |
| 193 | + </template> |
| 194 | + </BaseModal> |
| 195 | +</template> |
0 commit comments