index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 { onClickOutside } from '@vueuse/core'
  61. const target = ref(null)
  62. const isAnimate = ref(false)
  63. const isVisible = defineModel('isVisible', {
  64. type: Boolean,
  65. })
  66. const isRendered = ref(isAnimate.value)
  67. const props = withDefaults(
  68. defineProps<{
  69. closable?: boolean
  70. formMessage?: string
  71. formType?: number
  72. }>(),
  73. {
  74. closable: true,
  75. formType: 0,
  76. },
  77. )
  78. defineEmits(['isClosed'])
  79. watch(isVisible, (val) => {
  80. if (val === true) {
  81. isAnimate.value = true
  82. isRendered.value = true
  83. }
  84. else {
  85. isAnimate.value = false
  86. setTimeout(() => {
  87. isRendered.value = false
  88. }, 300)
  89. }
  90. })
  91. // watcher fix
  92. if (isVisible.value === true) {
  93. isAnimate.value = true
  94. isRendered.value = true
  95. }
  96. onClickOutside(target, () => {
  97. if (props.closable) isVisible.value = false
  98. })
  99. </script>
  100. <style scoped>
  101. @keyframes fadeInUp {
  102. 0% {
  103. opacity: 0;
  104. transform: scale(110%);
  105. }
  106. 100% {
  107. opacity: 1;
  108. transform: scale(100%);
  109. }
  110. }
  111. .fadeInUp {
  112. animation: fadeInUp 200ms ease-in-out;
  113. animation-fill-mode: forwards;
  114. }
  115. @keyframes fadeOutDown {
  116. 0% {
  117. opacity: 1;
  118. transform: scale(100%);
  119. }
  120. 100% {
  121. opacity: 0;
  122. transform: scale(110%);
  123. }
  124. }
  125. .fadeOutDown {
  126. animation: fadeOutDown 200ms ease-in-out;
  127. animation-fill-mode: forwards;
  128. }
  129. </style>