index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <Teleport to="body">
  3. <div
  4. v-if="isRendered"
  5. class="fixed top-0 left-0 w-screen h-screen"
  6. style="z-index: 2147483647;"
  7. >
  8. <div class="relative w-full h-full">
  9. <div
  10. :class="isAnimate ? 'animate__fadeIn' : 'animate__fadeOut'"
  11. class="w-full h-full backdrop-blur-md animate__animated animate__duration"
  12. />
  13. <div
  14. class="absolute top-0 left-0 w-full p-1 h-full flex justify-center items-center"
  15. :class="isAnimate ? 'fadeInUp' : 'fadeOutDown'"
  16. >
  17. <div
  18. ref="target"
  19. :class="{
  20. 'p-5': formType !== 1,
  21. }"
  22. class="w-[440px] flex flex-col gap-3 rounded-lg bg-background-100 text-foreground shadow-xl"
  23. >
  24. <div
  25. v-if="formType === -1"
  26. class="w-full h-full"
  27. >
  28. <slot />
  29. <button
  30. class="mt-3 w-full border-[1px] font-semibold text-md border-primary hover:bg-primary hover:text-black rounded-xl flex gap-3 justify-center items-center duration-150"
  31. @click="isVisible = false"
  32. >
  33. Ок
  34. </button>
  35. </div>
  36. <form
  37. v-else-if="formType === 0"
  38. class="flex flex-col gap-5 justify-center items-center"
  39. @submit.prevent="[(isVisible = false), $emit('isClosed', null)]"
  40. >
  41. <p v-text="formMessage" />
  42. <button
  43. class="w-full border-[1px] font-semibold text-md border-primary hover:bg-primary hover:text-black rounded-xl flex gap-3 justify-center items-center duration-150"
  44. type="submit"
  45. >
  46. Ок
  47. </button>
  48. </form>
  49. <!-- <FormAuth
  50. @is-closed="isVisible = false"
  51. v-else-if="formType === 1"
  52. /> -->
  53. </div>
  54. </div>
  55. </div>
  56. </div>
  57. </Teleport>
  58. </template>
  59. <script setup lang="ts">
  60. import { ref, watch } from 'vue'
  61. import { onClickOutside } from '@vueuse/core'
  62. const target = ref(null)
  63. const isAnimate = ref(false)
  64. const isVisible = defineModel('isVisible', {
  65. type: Boolean,
  66. })
  67. const isRendered = ref(isAnimate.value)
  68. const props = withDefaults(
  69. defineProps<{
  70. closable?: boolean
  71. formMessage?: string
  72. formType?: number
  73. }>(),
  74. {
  75. closable: true,
  76. formType: 0,
  77. },
  78. )
  79. defineEmits(['isClosed'])
  80. watch(isVisible, (val) => {
  81. if (val === true) {
  82. isAnimate.value = true
  83. isRendered.value = true
  84. }
  85. else {
  86. isAnimate.value = false
  87. setTimeout(() => {
  88. isRendered.value = false
  89. }, 300)
  90. }
  91. })
  92. // watcher fix
  93. if (isVisible.value === true) {
  94. isAnimate.value = true
  95. isRendered.value = true
  96. }
  97. onClickOutside(target, () => {
  98. if (props.closable) isVisible.value = false
  99. })
  100. </script>
  101. <style scoped>
  102. @keyframes fadeInUp {
  103. 0% {
  104. opacity: 0;
  105. transform: scale(110%);
  106. }
  107. 100% {
  108. opacity: 1;
  109. transform: scale(100%);
  110. }
  111. }
  112. .fadeInUp {
  113. animation: fadeInUp 200ms ease-in-out;
  114. animation-fill-mode: forwards;
  115. }
  116. @keyframes fadeOutDown {
  117. 0% {
  118. opacity: 1;
  119. transform: scale(100%);
  120. }
  121. 100% {
  122. opacity: 0;
  123. transform: scale(110%);
  124. }
  125. }
  126. .fadeOutDown {
  127. animation: fadeOutDown 200ms ease-in-out;
  128. animation-fill-mode: forwards;
  129. }
  130. </style>